aboutsummaryrefslogtreecommitdiffstats
path: root/tools/mcufontencoder/src/bdf_import.hh
blob: d94103e55294bd12febb38883728b079aa394324 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Function for importing .BDF fonts as data files.

#pragma once
#include "datafile.hh"

namespace mcufont
{

std::unique_ptr<DataFile> LoadBDF(std::istream &file);

}

#ifdef CXXTEST_RUNNING
#include <cxxtest/TestSuite.h>

using namespace mcufont;

class BDFTests: public CxxTest::TestSuite
{
public:
    void testLoadBDF()
    {
        std::istringstream s(testfile);
        std::unique_ptr<DataFile> f = LoadBDF(s);
        
        TS_ASSERT_EQUALS(f->GetFontInfo().name, "-Misc-Fixed-Medium-R-Normal--14-130-75-75-C-70-ISO8859-15");
        TS_ASSERT_EQUALS(f->GetFontInfo().max_width, 6);
        TS_ASSERT_EQUALS(f->GetFontInfo().max_height, 11);
        TS_ASSERT_EQUALS(f->GetGlyphCount(), 1);
        TS_ASSERT_EQUALS(f->GetGlyphEntry(0).chars.size(), 2);
    }
    
private:
    static constexpr const char *testfile = 
        "STARTFONT 2.1\n"
        "FONT -Misc-Fixed-Medium-R-Normal--14-130-75-75-C-70-ISO8859-15\n"
        "FONTBOUNDINGBOX 7 14 0 -2\n"
        "STARTCHAR defaultchar\n"
        "ENCODING 0\n"
        "DWIDTH 7 0\n"
        "BBX 7 14 0 -2\n"
        "BITMAP\n"
        "00\n"
        "B4\n"
        "84\n"
        "00\n"
        "84\n"
        "84\n"
        "00\n"
        "84\n"
        "84\n"
        "00\n"
        "84\n"
        "B4\n"
        "00\n"
        "00\n"
        "ENDCHAR\n"
        "STARTCHAR copychar\n"
        "ENCODING 2\n"
        "DWIDTH 7 0\n"
        "BBX 7 14 0 -2\n"
        "BITMAP\n"
        "00\n"
        "B4\n"
        "84\n"
        "00\n"
        "84\n"
        "84\n"
        "00\n"
        "84\n"
        "84\n"
        "00\n"
        "84\n"
        "B4\n"
        "00\n"
        "00\n"
        "ENDCHAR\n";

};
#endif