Skip to content

[LVGL] FreeType bold font generation is incorrect: generated code uses BITMAP mode so LV_FREETYPE_FONT_STYLE_BOLD does not take effect in version 9.5 #996

Description

@song7641

Hi, and thanks for adding FreeType font generation support for LVGL 9.2.2, 9.3.0, 9.4.0, and 9.5 in issue #866.

I found a problem related to FreeType bold fonts when using LVGL 9.5.

When a font is set to bold in EEZ Studio, the generated code does not actually produce a bold font at runtime.

Environment
EEZ Studio: 0.27.1
LVGL: 9.5
FreeType: enabled
Example font: SourceHanSansCN-Normal.otf
Problem description
The generated code currently looks like this:

ui_font_xxx = lv_freetype_font_create(
"SourceHanSansCN-Normal.otf",
LV_FREETYPE_FONT_RENDER_MODE_BITMAP,
14,
LV_FREETYPE_FONT_STYLE_NORMAL
);
There are two problems here:

It uses LV_FREETYPE_FONT_RENDER_MODE_BITMAP
The style argument is generated as LV_FREETYPE_FONT_STYLE_NORMAL
However, in LVGL 9.5, software bold does not take effect in LV_FREETYPE_FONT_RENDER_MODE_BITMAP mode.

As a result, even if bold is selected in EEZ Studio, the rendered font is still not bold at runtime.

Expected behavior
If the user selects bold for a FreeType font in EEZ Studio, the generated code should use:

LV_FREETYPE_FONT_RENDER_MODE_OUTLINE
LV_FREETYPE_FONT_STYLE_BOLD
For example:

ui_font_xxx = lv_freetype_font_create(
"SourceHanSansCN-Normal.otf",
LV_FREETYPE_FONT_RENDER_MODE_OUTLINE,
14,
LV_FREETYPE_FONT_STYLE_BOLD
);
Root cause analysis
I checked the LVGL 9.5 implementation and found that the bold effect is handled in the outline path.

In lvgl/src/libs/freetype/lv_freetype_outline.c, inside freetype_glyph_outline_create_cb(), there is the following code:

outline = outline_create(dsc->context,
dsc->cache_node->face,
node->glyph_index,
dsc->cache_node->ref_size,
dsc->style & LV_FREETYPE_FONT_STYLE_BOLD ? 1 : 0);
This means the bold effect depends on:

using the OUTLINE render path
passing LV_FREETYPE_FONT_STYLE_BOLD in the style
If EEZ Studio generates BITMAP mode, this bold path is not used, so the bold effect is not visible.

Suggested fix
For LVGL 9.x FreeType font generation, when the user selects bold, EEZ Studio should generate:

LV_FREETYPE_FONT_RENDER_MODE_OUTLINE
LV_FREETYPE_FONT_STYLE_BOLD
instead of continuing to generate BITMAP mode.

If helpful, it may also be worth documenting or clarifying in the UI that:

BITMAP mode does not support this kind of software bold effect
OUTLINE mode is required if bold should be produced through LVGL FreeType
Additional note
It also looks like the embolden strength is related to this expression:

dsc->style & LV_FREETYPE_FONT_STYLE_BOLD ? 1 : 0
Since the value passed here is currently 1, the final bold strength may also depend on the LVGL-side implementation.

Thanks.

Metadata

Metadata

Assignees

Type

Fields

No fields configured for Bug.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions