3 # Parse a 14-segment font file
4 # and construct the bitmasks for each
5 # character. Output is in the same
19 # Note that there can only be tabs before the glyph image
20 # as spaces are significant in the image itself.
30 glyph read_glyph(file f) {
36 string l = File::fgets(f);
37 if (File::sscanf(l, "CHAR %d", &c) == 1)
41 string strip_tab(string x) {
43 while (i < String::length(x) && x[i] == '\t')
45 string n = String::substr(x, i, String::length(x) - i);
46 while (String::length(n) < 7)
51 string[7] lines = { [i] = strip_tab(File::fgets(f)) };
55 g.bits[0] = lines[0][1] == '-';
57 g.bits[1] = lines[1][0] == '|';
58 g.bits[2] = lines[1][1] == '\\';
59 g.bits[3] = lines[1][3] == '|';
60 g.bits[4] = lines[1][5] == '/';
61 g.bits[5] = lines[1][6] == '|';
63 g.bits[6] = lines[3][1] == '-';
64 g.bits[7] = lines[3][4] == '-';
66 g.bits[8] = lines[5][0] == '|';
67 g.bits[9] = lines[5][1] == '/';
68 g.bits[10] = lines[5][3] == '|';
69 g.bits[11] = lines[5][5] == '\\';
70 g.bits[12] = lines[5][6] == '|';
72 g.bits[13] = lines[6][1] == '-';
76 string[*] glyph_image(glyph g) {
77 int[7][7] chars = { { ' ' ... } ... };
80 for (int c = 1; c < 6; c++)
84 for (int r = 1; r < 3; r++)
87 for (int p = 1; p < 3; p++)
90 for (int p = 1; p < 3; p++)
93 for (int p = 1; p < 3; p++)
96 for (int p = 1; p < 3; p++)
100 for (int p = 1; p < 3; p++)
103 for (int p = 4; p < 6; p++)
107 for (int r = 4; r < 6; r++)
110 for (int p = 4; p < 6; p++)
113 for (int p = 4; p < 6; p++)
116 for (int p = 4; p < 6; p++)
119 for (int p = 4; p < 6; p++)
123 for (int c = 1; c < 6; c++)
126 return (string[7]) { [i] = String::new(chars[i]) };
130 int glyph_value(glyph g) {
133 for (int b = 0; b < 14; b++)
139 void write_glyph(file f, glyph g) {
140 File::fprintf (f, "CHAR %d '%s'\n", g.c, g.c == 127 ? "DEL" : String::new(g.c));
141 string[7] lines = glyph_image(g);
142 for (int i = 0; i < 7; i++)
143 File::fprintf (f, "\t%s\n", lines[i]);
148 glyph[*] read_font(file f) {
149 glyph[128 - 32] font = { [i] = read_glyph(f) };
151 Sort::qsort(&font, bool func (glyph a, glyph b) = (a.c > b.c));
157 twixt (file f = File::open("ao_lcd_font_bits.h", "r"); File::close(f)) {
163 twixt(file f = File::open("ao_lcd_font_bits.h.new", "w"); File::close(f)) {
164 for (int i = 0; i < dim(font); i++) {
165 File::fprintf (f, "\t[%d] = 0x%04x,\n", i, glyph_value(font[i]));
166 File::fprintf (f, "/*\n");
167 write_glyph(f, font[i]);
168 File::fprintf (f, "*/\n\n");