Skip to content

Add lv_imgfont codepoint range filter (and fix macOS brew parser)#3

Merged
ThomasFarstrike merged 15 commits into
MicroPythonOS:mainfrom
bitcoin3us:fix/imgfont-set-range
May 31, 2026
Merged

Add lv_imgfont codepoint range filter (and fix macOS brew parser)#3
ThomasFarstrike merged 15 commits into
MicroPythonOS:mainfrom
bitcoin3us:fix/imgfont-set-range

Conversation

@bitcoin3us
Copy link
Copy Markdown

@bitcoin3us bitcoin3us commented May 30, 2026

Summary

Two small things; the imgfont one is the headline. macOS.py is a drive-by that was blocking the build entirely.

1. imgfont_set_range.patch — fast filter for composed-font glyph lookup

Adds an optional accept/exclude codepoint range to lv_imgfont so LVGL can reject codepoints in C before calling path_cb:

void lv_imgfont_set_range(font, cp_min, cp_max, excl_min, excl_max);

For MicroPython callers — where path_cb is a Python function — this turns the per-glyph cost from a C→Python round-trip into a pair of int compares. A typical text label using getFont(emoji=True) is overwhelmingly ASCII, so almost every glyph today crosses into Python just to bail out with None. With the filter set, only codepoints actually in the emoji map reach Python.

  • Backward-compatible: lv_imgfont_create initialises the range to "accept everything", so any existing caller behaves identically.
  • Safety guard: setter is a no-op on non-imgfont lv_font_t (fingerprint check on get_glyph_dsc) — safe to call defensively from MicroPython.
  • MicroPython auto-binder picks it up from the header — zero binding glue.
  • Patch applies cleanly to LVGL v9.4.0 (current pinned SHA).
  • Wired into build_mpos.sh over in Fast composed-font emoji rendering via lv_imgfont_set_range MicroPythonOS#148 using the same patch -p1 --forward < ../../*.patch pattern as the existing esp32_*.patch files in this repo.

2. builder/macOS.py brew-config parser

is_homebrew_arm() built a dict from brew config lines via line.split(':', 1), but output.split('\n') yields a trailing empty string with no :IndexError, build aborts before anything compiles. Filter to lines containing : before parsing. One-line fix.

Reproduced on Python 3.14 + recent Homebrew on macOS 26.

Test plan

  • macOS desktop build (build_mpos.sh macOS) — patch applies cleanly, lv.imgfont_set_range exposed in the binding, FontManager wiring works
  • ESP32-S3 firmware build (build_mpos.sh esp32s3) — patch applies cleanly, builds clean (no warnings on the patched files)
  • On-device verification (Waveshare ESP32-S3-Touch-LCD-2): lv.imgfont_set_range is callable, FontManager computes bounds dynamically from the loaded emoji map, scrolling the Lightning Piggy transactions list is noticeably smoother than the pre-patch build
  • Safety: setter called on lv.font_montserrat_14 no-ops without crashing, as designed

Companion PR

The MPOS-side wiring (FontManager invokes the new setter; build_mpos.sh applies the patch) lives in MicroPythonOS/MicroPythonOS#148 — depends on this one merging first so the submodule pointer resolves.

ThomasFarstrike and others added 15 commits May 18, 2026 12:39
Custom font source files for MicroPythonOS, including compressed
Montserrat variants, CJK fonts, and custom symbol definitions.
- Bump image cache size for 1280x720 PNG support
- Set color depth to 16
- Disable verbose trace logging for speed
- Enable assert style checks
- Enable sysmon and perf monitor
- Configure font sizes (enable small/medium, disable large)
- Enable compressed font support
- Set default font to Montserrat 12
- Enable GIF decode cache, file explorer, image header cache
- Various UI tweaks (calendar start Monday, etc.)
- macOS: remove -static LDFLAGS (fixes black window on macOS)
- unix: add LDFLAGS_EXTRA=-static for portable binary, fix binary path print
- SDL: add SDL_WINDOW_FULLSCREEN env var support, set arrow cursor
- gen/lvgl_api_gen_mpy.py, gen/python_api_gen_mpy.py: wrap LVGL
  callbacks in nlr_buf_t try/except to catch Python exceptions
  and disable failing callbacks instead of crashing
- task_handler.py: improve exception handling robustness
- display_driver_framework.py: reduce backlight PWM frequency
is_homebrew_arm() built a dict from `brew config` lines via
`line.split(':', 1)`, but output.split('\n') yields a trailing empty
string with no ':' — IndexError, build aborts before anything
compiles. Filter to lines containing ':' before parsing.

Reproduces with Python 3.14 + recent Homebrew on macOS 26.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Bakes an optional accept/exclude codepoint range into lv_imgfont so
LVGL can fast-reject non-emoji glyphs in C before invoking the
path_cb. For MicroPython callers — where path_cb is a Python
function — this is the difference between a C->Python round-trip
per glyph and a pair of int compares.

Effect on MPOS scrolling: a transactions list label is composed-font
with emoji=True, but typical content is mostly ASCII. Without the
filter every glyph (digits, letters, punctuation) crosses into
Python just to bail out. With it, only codepoints actually in the
emoji map reach Python, so plain-text scrolling stays in C
end-to-end.

  void lv_imgfont_set_range(font, cp_min, cp_max, excl_min, excl_max);

  - Cp outside [cp_min, cp_max] or inside [excl_min, excl_max]
    -> get_glyph_dsc returns false immediately (LVGL falls back
    to the next font in the chain at C speed).
  - cp_min=0 / cp_max=UINT32_MAX defaults preserve existing behaviour
    for any caller that doesn't call the setter.
  - Setter no-ops safely on non-imgfont lv_font_t (fingerprint check)
    so it's safe to call defensively from MicroPython.

Applied at build time to lvgl_micropython/lib/lvgl via build_mpos.sh,
matching the existing esp32_*.patch pattern in this repo. The
MicroPython auto-binder picks the new setter up from the header
declaration with no extra binding glue.

Patch applies cleanly to LVGL v9.4.0 (the current pinned lvgl SHA).

Verified end-to-end: macOS desktop build + ESP32-S3 device. On
device, FontManager.getFont(emoji=True) sets the range to the
actual min/max codepoint in the loaded emoji map; scrolling a
transactions list in Lightning Piggy is now noticeably smoother.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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

Successfully merging this pull request may close these issues.

2 participants