slint icon indicating copy to clipboard operation
slint copied to clipboard

Font conguration for embedded fonts for the software renderer on MCU

Open ogoffart opened this issue 10 months ago • 3 comments

When compiling with slint_build::EmbedResourcesKind::EmbedForSoftwareRenderer, we need a way to specify with font to embed, which glyph ranges, which sizes.

Currently there is some code that tries to auto-detect the sizes, and there is also the undocumented SLINT_FONT_SIZES env variable. But embedding all the fonts with all the glyphs with all size variant is taking way too much flash and is not practical.

ogoffart avatar Mar 27 '24 07:03 ogoffart

Some options: (We can combine several approach)

  1. Have a config file somewhere (see https://github.com/slint-ui/slint/issues/267 )
  2. Some more configuration in slint_build
  3. Add some syntax to the import "foo.ttf"; statement so we can specify sizes and ranges
  4. Improve the flexibility of environment variables, and document them.

ogoffart avatar Mar 27 '24 07:03 ogoffart

Would it be possible to extend Platform or add another Trait with a call like get_glyph(...) -> Option<...>? If a glyph is not found in the embedded font data, slint asks for the glyph.

MiSimon avatar Mar 27 '24 07:03 MiSimon

There is another issue for loading font at runtime: https://github.com/slint-ui/slint/issues/4250 But a fallback in the platform seems like a good idea as well.

ogoffart avatar Mar 27 '24 08:03 ogoffart

@ogoffart What about selecting different font weights? I have Montserrat and would like to use Medium, SemiBold or Bold (weights of 400, 500, 700) on embedded. Is this possible right now?

FoundationKen avatar Jul 09 '24 21:07 FoundationKen

Unfortunately that's also not possible right now.

Maybe implementing #4250 would not be too difficult. @FoundationKen would that be an option for your device and ram? You'd then call something like slint::load_truetype_font_from_bytes(include_bytes!("foo.ttf")) (or similar, maybe you have a file system you could use at run-time). That would have to be called early on, and you could call it a few times, I suppose, like with "MontserratRegular.ttf", "MontSerratBold.ttf", and afterwards you could select them via font-weight and font-family.

tronical avatar Jul 10 '24 11:07 tronical

We definitely have the space for the TTF fonts and we have a file system.

FoundationKen avatar Jul 10 '24 21:07 FoundationKen

@tronical This is working for me now! Did I miss the release note where this was fixed?

FoundationKen avatar Aug 29 '24 22:08 FoundationKen

I don't recall fixing this in particular, but I've recently had somebody ask for the same and it worked (in an MCU environment). I used import "./NotoSans-Regular.ttf" and import "./NotoSans-Bold.ttf" and then Text { font-family: "Noto Sans"; font-weight: 800; ... } worked as expected. Is this how you're using it, too?

tronical avatar Aug 30 '24 06:08 tronical

Yes, that is how I am using it (two separate font files).

FoundationKen avatar Aug 30 '24 14:08 FoundationKen