Skip to content

Speed up glyph loading when glyphs are not pre-loaded #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kmatch98 opened this issue Aug 16, 2020 · 0 comments
Closed

Speed up glyph loading when glyphs are not pre-loaded #84

kmatch98 opened this issue Aug 16, 2020 · 0 comments

Comments

@kmatch98
Copy link
Contributor

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).

https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font/blob/784322cac41f3ae33385675e9977dd3957f6cecb/adafruit_bitmap_font/bdf.py#L100-L104

for code_point in remaining:
            if code_point in self._glyphs and self._glyphs[code_point]:
                remaining.remove(code_point)
        if not remaining:
            return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant