summaryrefslogtreecommitdiff
path: root/tools/gen_display_resources.py
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2019-01-24 17:25:08 -0800
committerScott Shawcroft <scott@tannewt.org>2019-01-31 11:42:13 -0800
commit590e0291989c8df150b9b8aff960049903b56ac2 (patch)
tree65622a83faa0e1519a1ec75dbce5a20b846d3c69 /tools/gen_display_resources.py
parentfb0970ec6e2fee42d748718557c35fe84a4d0ce5 (diff)
Begin font parsing and packing for terminal
Diffstat (limited to 'tools/gen_display_resources.py')
-rw-r--r--tools/gen_display_resources.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/tools/gen_display_resources.py b/tools/gen_display_resources.py
new file mode 100644
index 000000000..3bcdc9952
--- /dev/null
+++ b/tools/gen_display_resources.py
@@ -0,0 +1,68 @@
+import argparse
+
+import os
+import sys
+
+sys.path.append("bitmap_font")
+
+from adafruit_bitmap_font import bitmap_font
+
+parser = argparse.ArgumentParser(description='Generate USB descriptors.')
+parser.add_argument('--font', type=str,
+ help='manufacturer of the device', required=True)
+parser.add_argument('--output_c_file', type=argparse.FileType('w'), required=True)
+
+args = parser.parse_args()
+
+args.font
+
+c_file = args.output_c_file
+
+c_file.write("""\
+
+#include "supervisor/shared/display.h"
+
+""")
+
+class BitmapStub:
+ def __init__(self, width, height, color_depth):
+ self.width = width
+ self.rows = [b''] * height
+
+ def _load_row(self, y, row):
+ self.rows[y] = bytes(row)
+
+f = bitmap_font.load_font(args.font, BitmapStub)
+f.load_glyphs(range(0x20, 0x7f))
+
+print(f.get_bounding_box())
+real_bb = [0, 0]
+
+visible_ascii = bytes(range(0x20, 0x7f)).decode("utf-8")
+all_characters = visible_ascii
+for c in all_characters:
+ g = f.get_glyph(ord(c))
+ x, y, dx, dy = g["bounds"]
+ print(c, g["bounds"], g["shift"])
+ if g["shift"][1] != 0:
+ raise RuntimeError("y shift")
+ real_bb[0] = max(max(real_bb[0], x - dx), g["shift"][0])
+ real_bb[1] = max(real_bb[1], y - dy)
+
+real_bb[1] += 1
+print(real_bb)
+
+tile_x, tile_y = real_bb
+
+for c in all_characters:
+ g = f.get_glyph(ord(c))
+ #print(c, g["bounds"], g["shift"])
+ for row in g["bitmap"].rows:
+ for i in range(g["bounds"][0]):
+ byte = i // 8
+ bit = i % 8
+ # if row[byte] & (1 << (7-bit)) != 0:
+ # print("*",end="")
+ # else:
+ # print("_",end="")
+ #print()