Dynamically doubling font size

Description

I am trying to reduce the memory usage for storing fonts. Most of my fonts are small pixel fonts, so it should be relatively easy to double the size in all dimensions at runtime, not arbitrary scaling.

Does anyone have ideas on the best way to attempt this?

What MCU/Processor/Board and compiler are you using?

Imxrt1052

What do you want to achieve?

Runtime doubling of font sizes.

What have you tried so far?

Not much, seeing if there are recommendations on where to start.

Code to reproduce

N/A

Screenshots

N/A

I too wanted to do this but ended up having to create a massive 2MB font file to include 0-9 and a colon as i wanted size 160 at 4bpp.

Ideally i would have scaled the font up but…

If anyone has any ideas or if this could be implemented i would definitely be happy to know!

Thanks
Alex

My hope is that there would be a way to simply multiply all of the dimensions by a scale factor during render, which for a pixelated font should be fine. I am not looking for vector based calculation to give smooth scaling.

You can create a font on the fly.

Take a look at my github. I have code for runtime serialization that may be useful as a starting point.

The font items have font in the name. I have not fully tested this section yet, but like I said it should give you an idea

Otherwise you could create a new font render engine with an option for pixel size. 1 being default. Then you could render the fonts based on that value. For bonus points you could add antialiasing. Honestly that sounds like a fun project :smirk:

The more I think about this, the more I like it. If you could balance speed and size, dynamic sizing with antialiasing would be fantastic. You could define a 12 or 14 point font and dynamically size it for substantial savings in memory

(cc @puzrin, author of the font converter)

IMO bitmaps transform in runtime is not related to convertor.

Oh no, I wasnt thinking it was something for the font converter

@elgerg i’d suggest you try latest dev version with compression. It should be very effective on big sizes. Also, 3bpp should be enougth.

I have started to look at adding a multiplier to lv_draw_letter in lv_draw_basic.c.

1 Like

Do you where i should put a request in for:

https://littlevgl.com/ttf-font-to-c-array

To allow for 3bpp?

Thanks
Alex

3bpp is not supported in v6.0. It will be supported in v6.1 and then the online converter will be updated too. Until that you can use the latest version of the converter offline.

Note that, it’s not that simple. The larger letters imply larger labels too. Probably it’d be a cleaner approach to change the callbacks of the font:

Are there any in-progress branches or PRs with this feature? I’d like to help too.

I kinda gave up, as I transitioned to the latest lvgl version and abandoned a lot of my customizations.

I would love if this feature could be revisited!

Lvgl now has functions to transform (scale and/or rotate) images. I’ve tried to apply them on glyphs but it gave quite bad quality for letters. I think it’d be reasonable to add a dedicated algorithm which scale 8 bit fonts in 0.5 … 2 range. Above 2 things gets trickier because some pixels will be skipped.

Could you contribute with algorithm like this? If so I’d integrate it to lvgl.
It’s prototype could look like:

void scale_bitmap(uint8_t * in, uint8_t out, lv_coord_t w, lv_coord_t h, uint16_t zoom);

(zoom: 256: normal, 128, half, 512 double)

What do you think?
If you are interested, please open an issue for it on GitHub.

My use case may not be typical, but my fonts are pixel fonts, with no antialiasing… so scaling up by whole number factors should always look perfect.

In some cases, scaling down may be possible, but my plan is to have a pixel based font in the smallest possible size to save memory space, and then scale up during runtime to the needed size.

For example this is the type of font:

Sorry for the late replay.

In LittlevGL I’d like to integrate a more general solution but of course locally you can add this improvement. All you need to do is to modify lv_font_get_bitmap_fmt_txt and lv_font_get_glyph_dsc_fmt_txt to returned the upscaled bitmap and coordinates.

By the way, I’ve just come across the Hqx algorithm which designed for 1 bit images. It might be useful.

@kisvegabor
About font scaling, is there any latest progress?
I am using the lvgl MicroPython version, primarily for Chinese fonts. I need to dynamically display different texts and sizes, which requires loading a large font library with various sizes. However, this results in significant program space usage. Is there a way to dynamically scale within a single font to support different font sizes?

Of course, I understand that scaling to different sizes may lead to less clear fonts, and we are willing to keep it within a reasonable range.

Could you please let me know if there are plans to support this feature, or if we need to modify functions such as lv_font_get_bitmap_fmt_txt and lv_font_get_glyph_dsc_fmt_txt ourselves?