diff options
| author | Jeff Epler <jepler@unpythonic.net> | 2019-12-19 16:26:01 -0600 |
|---|---|---|
| committer | Jeff Epler <jepler@unpythonic.net> | 2019-12-19 16:26:01 -0600 |
| commit | a93475707e18c110afdff23ac965e2e0c393fa40 (patch) | |
| tree | 1b41701cfbf80c5d6f449f722247acb3441fc1af | |
| parent | a3559f14e729cadb1f59d31d3011eb46f9eaaf4c (diff) | |
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.
| -rw-r--r-- | tools/gen_display_resources.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/tools/gen_display_resources.py b/tools/gen_display_resources.py index 781b5e69b..c08daf477 100644 --- a/tools/gen_display_resources.py +++ b/tools/gen_display_resources.py @@ -48,18 +48,19 @@ for c in sample_characters: all_characters += c if args.extra_characters: all_characters.extend(args.extra_characters) +all_characters = "".join(sorted(set(all_characters))) filtered_characters = all_characters # Try to pre-load all of the glyphs. Misses will still be slow later. -f.load_glyphs(set(all_characters)) +f.load_glyphs(set(ord(c) for c in all_characters)) # Get each glyph. -for c in all_characters: - g = f.get_glyph(ord(c)) - if not g: +for c in set(all_characters): + if ord(c) not in f._glyphs: print("Font missing character:", c, ord(c)) filtered_characters = filtered_characters.replace(c, "") continue + g = f.get_glyph(ord(c)) if g["shift"][1] != 0: raise RuntimeError("y shift") |
