I realized that the lvgl font converter not only produces const structures, but also modifiable ones. Specifically lv_font_fmt_txt_dsc_t and lv_font_t structures. Wanting to save some RAM, I went ahead and made them all const. Running the code like that led me to a segmentation fault, as in get_glyph_dsc_id some of the font_dsc fields are modified, due to a caching logic.
I’d like to suggest the following:
Hide this caching logic behind a compile switch (e.g. #if (LV_FONT_CACHE != 0))
Make lv_font_t and lv_font_fmt_txt_dsc_t structures const
If the font cache is enabled, add a cache pointer to lv_font_fmt_txt_dsc_t structure, that points to the separate non-const cache structure
I think if we added config options to disable font cache we needed to add a lot of other config options too where a few bytes could be saved.
It sounds good but doesn’t require any new config option. E.g. a non-const lv_font_fmt_txt_cache_t variable can be added to the font file automatically by the font converter.
This way both lv_font_t and lv_font_fmt_txt_dsc_t could be const. It saves 50-60 bytes / font so for 2-3 fonts it’s alrady a few hundred bytes.