Comments (7)
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.
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.
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.
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.
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.
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.
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)
- save_text=False throws error on init HOT 11
- Missing Type Annotations HOT 1
- Spaces are deleted when word-wrapping HOT 1
- Updates to text are inefficient for special case of same length and width text HOT 3
- bitmap_label losing direction HOT 6
- Suppress warnings in bitmap_label HOT 1
- Use `fontio.FontProtocol` for type annotations
- Label can take Tuple[int, int, int] for color HOT 1
- wrap_text_to_pixels() cannot handle Windows line endings HOT 1
- bitmap_label flicker HOT 1
- Unable to update scrolling_label text outside constructor HOT 2
- Exception with multiple consecutive newlines in bitmap label
- label.Label padding is wrong when using DWR or UPR HOT 5
- button simpletest throws error on PyPortal Titano HOT 1
- bitmap_label errors if no bitmaptools module present
- ValueError from negatives on first character
- Convert `.show()` to `.root_group =` for CircuitPython 9
- Program stops without any error when importing the library HOT 4
- bitmap label cuts off part of text HOT 3
- Add error handling for misspelled kwargs in adafruit_display_text.label HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from adafruit_circuitpython_display_text.