Skip to content

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

Closed
@kmatch98

Description

@kmatch98

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions