summaryrefslogtreecommitdiff
path: root/include/lib/pixelfont/ttf-to-font.py
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2021-11-29 22:44:30 +0100
committerDaniel Friesel <derf@finalrewind.org>2021-11-29 22:44:30 +0100
commitd4369b7abee295c95179028fd966272530055b03 (patch)
treec4d20ab8a7295539d6436b5b58e638e841588cf0 /include/lib/pixelfont/ttf-to-font.py
parente54cf737b446355b5863a7f31fe4d5d89d037ea4 (diff)
fix terminus16; add framebuffer support for multi-byte font heights
Diffstat (limited to 'include/lib/pixelfont/ttf-to-font.py')
-rwxr-xr-xinclude/lib/pixelfont/ttf-to-font.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/include/lib/pixelfont/ttf-to-font.py b/include/lib/pixelfont/ttf-to-font.py
index 50297e5..38460fe 100755
--- a/include/lib/pixelfont/ttf-to-font.py
+++ b/include/lib/pixelfont/ttf-to-font.py
@@ -4,6 +4,14 @@ import PIL
import PIL.ImageDraw
import PIL.ImageFont
+def invert(x):
+ ret = 0
+ for i in range(8):
+ if x & (0x80 >> i):
+ ret |= 0x01 << i
+ return ret
+
+
if __name__ == "__main__":
font = PIL.ImageFont.truetype(
"/usr/share/fonts/truetype/terminus/TerminusTTF-4.46.0.ttf", size=14
@@ -18,19 +26,21 @@ if __name__ == "__main__":
if bbox is None:
print(
- "glyph_line_t GLYPH_ATTR chr_032[] = {0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; // <spac>"
+ "glyph_line_t GLYPH_ATTR chr16_032[] = {0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; // <spac>"
)
continue
left, upper, right, lower = bbox
fontimg = fontimg.crop((left, 0, right, 15))
- fontimg = fontimg.transpose(PIL.Image.ROTATE_270)
+ fontimg = fontimg.transpose(PIL.Image.ROTATE_270).transpose(PIL.Image.FLIP_LEFT_RIGHT)
fontbytes = fontimg.tobytes()
glyph_len = len(fontbytes)
- glyph_data = "{" + ",".join(map(lambda x: f"0x{x:02x}", fontbytes)) + "}"
+ glyph_data = "{" + f"0x{glyph_len:02x}," + ",".join(map(lambda x: f"0x{invert(x):02x}", fontbytes)) + "}"
+
+ assert glyph_len % 2 == 0
print(
- f"glyph_line_t GLYPH_ATTR chr_{char:03d}[] = {glyph_data}; // {chr(char)}"
+ f"glyph_line_t GLYPH_ATTR chr16_{char:03d}[] = {glyph_data}; // {chr(char)}"
)