GithubHelp home page GithubHelp logo

Comments (7)

tannewt avatar tannewt commented on June 9, 2024

It's parsing the file the first time it needs a glyph (to save memory.) Use font.load_glyphs to preload the glyphs you need all in one pass of the file. Source is here: https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font/blob/master/adafruit_bitmap_font/glyph_cache.py#L53

from adafruit_circuitpython_display_text.

eirinnm avatar eirinnm commented on June 9, 2024

This doesn't work like I expect it to.


font_large = bitmap_font.load_font('/fonts/Arial-BoldMT-90.bdf')
font_large.load_glyphs('0123456789.-') 
lbl = label.Label(font=font_large, text="0.00", x=20, y=200, max_glyphs=5)

My problem: updating the lbl.text with new values takes a signficant amount of time the first time, but then the glyphs are cached and it runs fast. I want to pre-cache the glyphs. load_glyphs() doesn't work like I expect it to. What am I doing wrong?

from adafruit_circuitpython_display_text.

tannewt avatar tannewt commented on June 9, 2024

I'd expect that to work. To debug, I'd add a print of characters here: https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font/blob/master/adafruit_bitmap_font/bdf.py#L100

from adafruit_circuitpython_display_text.

eirinnm avatar eirinnm commented on June 9, 2024

I should have mentioned in my previous comment that font_large.load_glyphs('0123456789.-') takes a noticeable amount of time, which suggests it is doing something. It just doesn't speed up the label text updating.

from adafruit_circuitpython_display_text.

tannewt avatar tannewt commented on June 9, 2024

What new values cause the slow update? Can you time a subsequent update of a known label with time.monotonic()? It'd be slow if the text accidentally included a new character.

from adafruit_circuitpython_display_text.

eirinnm avatar eirinnm commented on June 9, 2024

Here's my test code for timing. It omits the label construction.

font_large = bitmap_font.load_font('/fonts/Arial-BoldMT-90.bdf')
info_target_speed_left.font = font_large
info_target_speed_left.text = "0.00" 

starttime = time.monotonic()
font_large.load_glyphs('0123456789.-')
print(time.monotonic() - starttime)

starttime = time.monotonic()
info_target_speed_left.text = "1.23" 
print(time.monotonic() - starttime)

starttime = time.monotonic()
info_target_speed_left.text = "4.56"
print(time.monotonic() - starttime)

starttime = time.monotonic()
info_target_speed_left.text = "1.23"
print(time.monotonic() - starttime)

Output:

1.55908 //cache
1.125 //changing to 1.23
1.36401 //changing to 4.56
0.00390625 //changing to 1.23

Now if I comment out the cache line:

0.0
1.36914
1.36475
0.00341797

So yeah it seems that load_glyphs takes time but doesn't actually cache. Yet label caching does work because the last line is faster than the others.

from adafruit_circuitpython_display_text.

tannewt avatar tannewt commented on June 9, 2024

Good find @zouden. load_glyphs didn't handle strings correctly. I've add support for them here: adafruit/Adafruit_CircuitPython_Bitmap_Font#15 This will screw up alternate encodings but I think that is ok. Everyone should use UTF-8 now.

from adafruit_circuitpython_display_text.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.