Use LV_FREETYPE_USE_LVGL_PORT to enable loading fonts from embedded resources

What do you want to achieve?

I’d like to have freetype load fonts from different locations depending on what’s being requested. In my case, I’ve an embedded latin font that includes what I need for the majority of languages, but in the case of Japanese, Korean and Simplified Chinese, I’d like to pull the file from disk.

What have you tried so far?

I’ve got freetype working fine, and I’m able to load arbitrary fonts from locations that I specify on disk. From the docs:

If you want FreeType to use LVGL’s memory allocation and file system interface, you can enable :c:macro:LV_FREETYPE_USE_LVGL_PORT in lv_conf.h, convenient for unified management. If you do this, you will need to exclude the configured FreeType library’s ftsystem.c file from being compiled, since LVGL’s lv_ftsystem.c has custom versions of the functions defined therein.

This seems logical, but I see errors related to FT_ERR_PREFIX as soon as I enable LV_FREETYPE_USE_LVGL_PORT. I suspect I am missing something, but I’m not sure whether this is a bug. Is anyone else doing similar with some success?

Code to reproduce

Just define LV_USE_FREETYPE and LV_FREETYPE_USE_LVGL_PORT as 1.

Environment

  • iMX8MP:
  • LVGL version: See 9.4

Just to follow up, I have got this working. The compilation issues were down to not defining:

FT2_BUILD_LIBRARY
FT_CONFIG_MODULES_H
FT_CONFIG_OPTIONS_H

… as described here:

https://docs.lvgl.io/9.3/details/libs/freetype.html

LVGL provides ftmodule and ftoption headers for the purpose of configuring freetype. I found a slight contradiction in that the ftoption.h requires libpng as it ships, so I had to disable FT_CONFIG_OPTION_USE_PNG and enable some modules that aren’t enabled by default to support some of the fonts I am using. I guess the correct thing to do is to copy these and adjust as required.

On the driver side, I ended up removing the default implementations from freetype (as alluded to by the documentation) and included the lv_ftsystem.c in the freetype build. The freetype docs talk about manually registering drivers by calling FT_Add_Module, but it doesn’t look like LVGL uses this method, so I’m assuming I’ve done the correct thing?