|
| 1 | +import argparse |
| 2 | + |
| 3 | +import os |
| 4 | +import sys |
| 5 | + |
| 6 | +sys.path.append("bitmap_font") |
| 7 | + |
| 8 | +from adafruit_bitmap_font import bitmap_font |
| 9 | + |
| 10 | +parser = argparse.ArgumentParser(description='Generate USB descriptors.') |
| 11 | +parser.add_argument('--font', type=str, |
| 12 | + help='manufacturer of the device', required=True) |
| 13 | +parser.add_argument('--output_c_file', type=argparse.FileType('w'), required=True) |
| 14 | + |
| 15 | +args = parser.parse_args() |
| 16 | + |
| 17 | +args.font |
| 18 | + |
| 19 | +c_file = args.output_c_file |
| 20 | + |
| 21 | +c_file.write("""\ |
| 22 | +
|
| 23 | +#include "supervisor/shared/display.h" |
| 24 | +
|
| 25 | +""") |
| 26 | + |
| 27 | +class BitmapStub: |
| 28 | + def __init__(self, width, height, color_depth): |
| 29 | + self.width = width |
| 30 | + self.rows = [b''] * height |
| 31 | + |
| 32 | + def _load_row(self, y, row): |
| 33 | + self.rows[y] = bytes(row) |
| 34 | + |
| 35 | +f = bitmap_font.load_font(args.font, BitmapStub) |
| 36 | +f.load_glyphs(range(0x20, 0x7f)) |
| 37 | + |
| 38 | +print(f.get_bounding_box()) |
| 39 | +real_bb = [0, 0] |
| 40 | + |
| 41 | +visible_ascii = bytes(range(0x20, 0x7f)).decode("utf-8") |
| 42 | +all_characters = visible_ascii |
| 43 | +for c in all_characters: |
| 44 | + g = f.get_glyph(ord(c)) |
| 45 | + x, y, dx, dy = g["bounds"] |
| 46 | + print(c, g["bounds"], g["shift"]) |
| 47 | + if g["shift"][1] != 0: |
| 48 | + raise RuntimeError("y shift") |
| 49 | + real_bb[0] = max(max(real_bb[0], x - dx), g["shift"][0]) |
| 50 | + real_bb[1] = max(real_bb[1], y - dy) |
| 51 | + |
| 52 | +real_bb[1] += 1 |
| 53 | +print(real_bb) |
| 54 | + |
| 55 | +tile_x, tile_y = real_bb |
| 56 | + |
| 57 | +for c in all_characters: |
| 58 | + g = f.get_glyph(ord(c)) |
| 59 | + #print(c, g["bounds"], g["shift"]) |
| 60 | + for row in g["bitmap"].rows: |
| 61 | + for i in range(g["bounds"][0]): |
| 62 | + byte = i // 8 |
| 63 | + bit = i % 8 |
| 64 | + # if row[byte] & (1 << (7-bit)) != 0: |
| 65 | + # print("*",end="") |
| 66 | + # else: |
| 67 | + # print("_",end="") |
| 68 | + #print() |
0 commit comments