Loading fonts can be one of the slow phases of a Magtag type project, and run time decreases battery lifetime. Therefore, it's warranted to write less idiomatic Python here if it improves runtime significantly. This change assumes that the lines within a character come in a specific order. While the document ostensibly defining the BDF file format https://www.adobe.com/content/dam/acom/en/devnet/font/pdfs/5005.BDF_Spec.pdf does not say that the order is defined, I inspected the source of the Linux program "bdftopcf" which has been used for decades to convert textual bdf font files into binary pcf files, and it too assumes that the lines come in a defined order. I doubt that bdf files that do not work with the linux bdftopcf program are less scarce than unicorns. I timed loading the characters "Adafruit CircuitPython" from the font "GothamBlack-50.bdf" on a PyBadge in CircuitPython 6.0.0: ```python font = load_font("/GothamBlack-50.bdf") font.load_glyphs("Adafruit CircuitPython") ``` The time decreased from 919ms to 530ms (-42%). Just reading all the lines in the font file takes 380ms. However, only the first 38% of the file (or so) needs to be read, so the I/O time is about 140ms. |
||
|---|---|---|
| .. | ||
| __init__.py | ||
| bdf.py | ||
| bitmap_font.py | ||
| glyph_cache.py | ||
| pcf.py | ||
| ttf.py | ||