Skip to content

Commit a934757

Browse files
committed
gen_display_resources: speed it up
It was intended that the `f.load_glyphs` line was fast and did most of the work. However, it actually didn't, because it's necessary to pass in a code point by number, not by string. Additionally, a little light layer violation is needed to make the check for missing characters fast. This used to be less important, as no fonts had missing characters. However, it would take an appreciable length of time on the Korean translation when failing to find hundreds of different code points. Testing performed: built build-circuitplayground_express_displayio/autogen_display_resources.c with ko translation before and after change. verified the file content was identical. Time went from about 7s on my machine to way under 1 second.
1 parent a3559f1 commit a934757

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tools/gen_display_resources.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,19 @@ def _load_row(self, y, row):
4848
all_characters += c
4949
if args.extra_characters:
5050
all_characters.extend(args.extra_characters)
51+
all_characters = "".join(sorted(set(all_characters)))
5152
filtered_characters = all_characters
5253

5354
# Try to pre-load all of the glyphs. Misses will still be slow later.
54-
f.load_glyphs(set(all_characters))
55+
f.load_glyphs(set(ord(c) for c in all_characters))
5556

5657
# Get each glyph.
57-
for c in all_characters:
58-
g = f.get_glyph(ord(c))
59-
if not g:
58+
for c in set(all_characters):
59+
if ord(c) not in f._glyphs:
6060
print("Font missing character:", c, ord(c))
6161
filtered_characters = filtered_characters.replace(c, "")
6262
continue
63+
g = f.get_glyph(ord(c))
6364
if g["shift"][1] != 0:
6465
raise RuntimeError("y shift")
6566

0 commit comments

Comments
 (0)