Font Manager

Report on GitHub

Load fonts at runtime and configure fallback chains, including image-based fonts.

Font manager with a FreeType source

Register a TTF path with the font manager and render a label with it.

lv_font_manager_create(8) builds a manager with an 8-slot recycling cache. lv_font_manager_add_src_static maps the name "Lato-Regular" to Lato-Regular.ttf through lv_freetype_font_class. lv_font_manager_create_font then resolves that name at size 24 with LV_FREETYPE_FONT_RENDER_MODE_BITMAP, LV_FREETYPE_FONT_STYLE_NORMAL, and LV_FONT_KERNING_NONE. The returned font is applied as the text font of a centered label reading "Hello Font Manager!".

Font fallback across multiple sources

Combine a TinyTTF, a FreeType emoji font, and built-in Montserrat into one fallback chain.

Up to three sources are registered with lv_font_manager_add_src_static: Montserrat 14 and 32 through lv_builtin_font_class, NotoColorEmoji-32.subset.ttf through lv_freetype_font_class, and Ubuntu-Medium.ttf through lv_tiny_ttf_font_class. lv_font_manager_create_font asks for the comma-joined chain "Ubuntu-Medium,NotoColorEmoji,Montserrat" at size 32, producing a font that falls through each source. A centered label uses it to render ASCII text, an emoji, and LV_SYMBOL_OK.

Custom image font class

Register a user-defined imgfont class that only matches a size range.

The file defines an lv_font_class_t whose create_cb returns a font from lv_imgfont_create only when the requested size falls between match_size_min and match_size_max (70 to 80). That class is registered as "Emoji" alongside a FreeType "Lato-Regular" source. lv_font_manager_create_font builds the chain "Lato-Regular,Emoji" at size 75, and a centered label renders "Quiet\uF617~" with the emoji glyph coming from the image source.

How is this guide?

Last updated on

On this page