[HOW TO] Use custom font in LVGL

Description

Hello, I need spacial characters used in translation to work with lvgl lib. I’ve used

Online font converter - TTF or WOFF fonts to C array | LVGL

to convert abhaya.ttf into lv_font_abhaya.c. If I understend the idea I need to copy that file into

\components\lvgl\src\font

and than add this line

CSRCS += lv_font_abhaya.c

at the bottom of .mk file right? After that I need to use

CONFIG_LV_FONT_CUSTOM

and set in sdkconfig

CONFIG_LV_FONT_CUSTOM_DECLARE “lv_font_abhaya”

Am I right at this point? bcs compiler gives me error

expected identifier or ‘(’ before string constant

What LVGL version are you using?

v8.1

Hi!
Please check this C example:
Fonts: https://github.com/sharandac/My-TTGO-Watch/tree/master/src/gui/font
Usage: https://github.com/sharandac/My-TTGO-Watch/blob/master/src/gui/mainbar/main_tile/main_tile.cpp#L69
Doc: Fonts — LVGL documentation

Other solution is loading fonts dynamically from device FS:
https://docs.lvgl.io/master/overview/font.html#load-a-font-at-run-time

1 Like