version 2.8
bdf_import.hh
1 // Function for importing .BDF fonts as data files.
2 
3 #pragma once
4 #include "datafile.hh"
5 
6 namespace mcufont
7 {
8 
9 std::unique_ptr<DataFile> LoadBDF(std::istream &file);
10 
11 }
12 
13 #ifdef CXXTEST_RUNNING
14 #include <cxxtest/TestSuite.h>
15 
16 using namespace mcufont;
17 
18 class BDFTests: public CxxTest::TestSuite
19 {
20 public:
21  void testLoadBDF()
22  {
23  std::istringstream s(testfile);
24  std::unique_ptr<DataFile> f = LoadBDF(s);
25 
26  TS_ASSERT_EQUALS(f->GetFontInfo().name, "-Misc-Fixed-Medium-R-Normal--14-130-75-75-C-70-ISO8859-15");
27  TS_ASSERT_EQUALS(f->GetFontInfo().max_width, 6);
28  TS_ASSERT_EQUALS(f->GetFontInfo().max_height, 11);
29  TS_ASSERT_EQUALS(f->GetGlyphCount(), 1);
30  TS_ASSERT_EQUALS(f->GetGlyphEntry(0).chars.size(), 2);
31  }
32 
33 private:
34  static constexpr const char *testfile =
35  "STARTFONT 2.1\n"
36  "FONT -Misc-Fixed-Medium-R-Normal--14-130-75-75-C-70-ISO8859-15\n"
37  "FONTBOUNDINGBOX 7 14 0 -2\n"
38  "STARTCHAR defaultchar\n"
39  "ENCODING 0\n"
40  "DWIDTH 7 0\n"
41  "BBX 7 14 0 -2\n"
42  "BITMAP\n"
43  "00\n"
44  "B4\n"
45  "84\n"
46  "00\n"
47  "84\n"
48  "84\n"
49  "00\n"
50  "84\n"
51  "84\n"
52  "00\n"
53  "84\n"
54  "B4\n"
55  "00\n"
56  "00\n"
57  "ENDCHAR\n"
58  "STARTCHAR copychar\n"
59  "ENCODING 2\n"
60  "DWIDTH 7 0\n"
61  "BBX 7 14 0 -2\n"
62  "BITMAP\n"
63  "00\n"
64  "B4\n"
65  "84\n"
66  "00\n"
67  "84\n"
68  "84\n"
69  "00\n"
70  "84\n"
71  "84\n"
72  "00\n"
73  "84\n"
74  "B4\n"
75  "00\n"
76  "00\n"
77  "ENDCHAR\n";
78 
79 };
80 #endif