Description
When creating a text label: label
processes each character at a time with get_glyph
. If font glyphs are not preloaded, the adafruit_bitmap_font
library function get_glyph
calls the load_glyphs
command on each individual character.
The load_glyphs
function parses each line of the font file until the required glyph is found. So, if we process each character individually (like we do now), each new glyph that is encountered will require a new parsing of the font file.
I propose to perform the load_glyphs
command on the full text input string prior to entering the character loop. By performing load_glyphs
on the full input string will require a maximum of one time parsing through the font file.
When the glyphs are already loaded, this will add some time overhead due to checking if the glyphs are already present. But this checking adds only a small overhead (see snippet below from load_glyphs
).
for code_point in remaining:
if code_point in self._glyphs and self._glyphs[code_point]:
remaining.remove(code_point)
if not remaining:
return