20 glyph_t glyph = { .encoding = -1, .bytes = (int[...]){}, .width = 0 };
22 while (!File::end(f)) {
25 string[*] tokens = String::split(l, " ");
31 glyph.encoding = atoi(tokens[1]);
34 glyph.width = atoi(tokens[1]);
37 glyph.height = atoi(tokens[2]);
42 while (!File::end(f)) {
46 glyph.bytes[dim(glyph.bytes)] = atoi(l, 16);
54 font_t read_font(file f) {
55 font_t font = { .glyphs = {}, .default_char = -1 };
58 while (in_head && !File::end(f)) {
59 string l = File::fgets(f);
61 string[*] tokens = String::split(l, " ");
64 font.default_char = atoi(tokens[1]);
67 font.ascent = atoi(tokens[1]);
74 while (!File::end(f)) {
75 glyph_t glyph = read_glyph(f);
76 if (glyph.encoding == -1)
78 font.glyphs[dim(font.glyphs)] = glyph;
88 for (int i = 0; i < 8; i++)
89 dest |= ((x >> (7 - i)) & 1) << i;
93 void print_font(font_t font) {
94 int width = font.glyphs[0].width;
95 int height = font.glyphs[0].height;
96 int[256] pos = { -1 ... };
100 for (int i = 1; i < dim(font.glyphs); i++) {
101 if (font.glyphs[i].width != width ||
102 font.glyphs[i].height != height)
104 File::fprintf(stderr, "font not constant size, glyph %d is %dx%d\n",
105 font.glyphs[i].encoding, font.glyphs[i].width, font.glyphs[i].height);
111 if (font.default_char == -1)
112 font.default_char = font.glyphs[0].encoding;
114 /* build byte array */
115 for (int i = 0; i < dim(font.glyphs); i++) {
116 pos[font.glyphs[i].encoding] = dim(bytes);
117 for (int b = 0; b < dim(font.glyphs[i].bytes); b++)
118 bytes[dim(bytes)] = font.glyphs[i].bytes[b];
121 /* Fill in default glyph */
122 for (int i = 0; i < dim(pos); i++)
124 pos[i] = pos[font.default_char];
126 printf("static const uint8_t glyph_bytes[%d] = {", dim(bytes));
127 for (int b = 0; b < dim(bytes); b++) {
130 printf("0x%02x, ", flip_byte(bytes[b]));
134 printf("static const uint16_t glyph_pos[%d] = {", dim(pos));
135 for (int i = 0; i < dim(pos); i++) {
138 printf("%4d, ", pos[i]);
142 printf("#define GLYPH_WIDTH %d\n", width);
143 printf("#define GLYPH_HEIGHT %d\n", height);
144 printf("#define GLYPH_ASCENT %d\n", font.ascent);
147 twixt (file f = File::open(argv[1], "r"); File::close(f)) {
148 font_t font = read_font(f);