From d4369b7abee295c95179028fd966272530055b03 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 29 Nov 2021 22:44:30 +0100 Subject: fix terminus16; add framebuffer support for multi-byte font heights --- include/lib/pixelfont/ttf-to-font.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'include/lib/pixelfont/ttf-to-font.py') 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}; // " + "glyph_line_t GLYPH_ATTR chr16_032[] = {0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; // " ) 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)}" ) -- cgit v1.2.3