Skip to content
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

MCU: Add support for font rendering from TrueType fonts loaded from memory #4250

Open
tronical opened this issue Jan 2, 2024 · 3 comments
Open
Labels
a:text Text rendering, fonts, Text input (mS,bF) enhancement New feature or request rfc Request for comments: proposals for changes

Comments

@tronical
Copy link
Member

tronical commented Jan 2, 2024

A few times in the past the desire has come up to be able to support a wider range of languages with Slint on MCUs, without pre-rendering a large amount of glyphs ahead of time or embedding an entire TrueType font in regular flash space (most recently in #4149 ).

We could add a feature among the following lines to address this:

  • Add a slint/sdcard-fonts feature that enables dependencies to embedded_sdmmc and fat32 (or similar crates)
  • When this feature is enabled, we also enable dependencies to fontdue or some other rasteriser, and ttf-parser.
  • Finally, at run-time we could look for the first .ttf file on an SD card (if inserted), read the cmap/hmtx/os2/etc. tables to cache basic font metrics, and then on a per-glyph basis cache glyph metrics and renderered glyphs on the heap on-demand.

On MCUs that are equipped with enough RAM, like an STM32H7 for example, this might be a reasonable solution to better support multiple languages.

In the same context, it might make sense to add the ability to load translations off of the same SD-Card - see also #3715

@tronical tronical added enhancement New feature or request rfc Request for comments: proposals for changes a:platform-mcu Microcontrollers (mO,bS) a:text Text rendering, fonts, Text input (mS,bF) labels Jan 2, 2024
@ogoffart
Copy link
Member

ogoffart commented Jan 2, 2024

We woudn't need the FS and SD card if we embedded directly the .ttf.

In the API, we could have something like so:

slint::load_font_from_ttf(include_bytes!("foo.ttf"));

And using this API, the dev would be free to use a sdcard driver themselves to load the font at runtime from a SDCard instead of using include_bytes.

@tronical
Copy link
Member Author

tronical commented Jan 2, 2024

We can add such an API, but that won’t make it possible for folks to use their own SD-Card setup, because those aren’t memory mapped. It would have to be something that abstracts away also the I/O.

That said, it’s indeed not enough to have the feature, we need indeed an API that abstracts away at least device access.

I also wonder how to make the ttf parser work on such a device hmm.

@zhangzqs
Copy link
Contributor

We woudn't need the FS and SD card if we embedded directly the .ttf.

In the API, we could have something like so:

slint::load_font_from_ttf(include_bytes!("foo.ttf"));

And using this API, the dev would be free to use a sdcard driver themselves to load the font at runtime from a SDCard instead of using include_bytes.

In this case, low-memory devices may not be able to load this ttf file. Perhaps we need to abstract some resource access interfaces so that we can randomly read any data source at will.

@tronical tronical changed the title MCU: Add support for font rendering from TrueType fonts loaded from an SD-Card MCU: Add support for font rendering from TrueType fonts loaded from an SD-Card or EEProm, etc. Jan 15, 2024
@tronical tronical changed the title MCU: Add support for font rendering from TrueType fonts loaded from an SD-Card or EEProm, etc. MCU: Add support for font rendering from TrueType fonts loaded from memory Jan 15, 2024
@tronical tronical removed the a:platform-mcu Microcontrollers (mO,bS) label Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:text Text rendering, fonts, Text input (mS,bF) enhancement New feature or request rfc Request for comments: proposals for changes
Projects
None yet
Development

No branches or pull requests

3 participants