How to use FreeType in LVGL 8

How to use FreeType in LVGL 8? In the watch demo, I noticed that during font setup, the following function is used:

lv_ext_set_local_font(label_header, FONT_TITLE, LV_COLOR_WHITE);

This seems to be a custom or proprietary usage you’ve created. When I tried to compile FreeType, I encountered the following error:

D:\OpenSiFli\SDK\SiFli-SDK\v2.4.2\middleware\lvgl\lvsf/lv_freetype.h:66:5: error: conflicting types for 'lv_freetype_init'; have 'int(uint8_t, uint32_t)' {aka 'int(unsigned char, long unsigned int)'}
   66 | int lv_freetype_init(uint8_t max_faces, uint32_t max_cache_size);

I’m getting a type conflict error. Is there a configuration or setup conflict somewhere? :smiling_face_with_tear:

It seems like the SDK has modified freetype, but I have no idea how to use it.

lv_ext_set_local_font is a simple wrapper for lv_obj_set_style_text_font and lv_obj_set_style_text_color.

image

Refer to example\\multimedia\\lvgl\\watch\\src\\resource\\fonts\\SConscript. After converting the .ttf file to a .c file:

# for module compiling
import os
from building import *
import rtconfig

cwd = GetCurrentDir()
list = os.listdir(cwd)

CPPDEFINES = []

if GetDepend('FREETYPE_TINY_FONT_FULL'):
    font_name = 'tiny55_full'
elif GetDepend('FREETYPE_TINY_FONT_LITE'):
    font_name = 'tiny55_lite'
elif GetDepend('FREETYPE_HANSANS_FONT'):
    font_name = 'SourceHanSansCN-Normal'
elif GetDepend('FREETYPE_ARIAL_FONT'):
    font_name = 'arial'
else:
    font_name = 'DroidSansFallback'

CPPDEFINES += ["FREETYPE_FONT_NAME={}".format(font_name)]

objs = Glob('freetype/{}.ttf'.format(font_name))

objs = Env.FontFile(objs)

if GetOption('no_cc'):
    objs = []

objs = DefineGroup('resource', objs, depend = ['PKG_USING_LITTLEVGL2RTT'], CPPDEFINES = CPPDEFINES)  

Return ('objs')

The generated C file uses LVSF_FREETYPE_FONT_REGISTER to register the font, making it available for use in LVGL. The function lv_ext_set_local_font automatically selects the appropriate font based on the text size.

WeChat Work Screenshot_1759125380723

lv_ext_lable_set_fixed_font 这个API还可以指定字体名称,以便区分相同字号不同字体

Alright, I’ll give it a try these days and provide the results back to this post. Thanks for your reply.

Hello, may I ask if this issue has been resolved successfully? :grinning_face_with_smiling_eyes:

Has lvsf_get_font_from_size been compiled into a library? I’d like to see the source code.