LVGL use custom font(e.g. freetype), some letters are not fully displayed(e.g. j,g)

What MCU/Processor/Board and compiler are you using?

arm

What do you experience?

I use freetype instead of default font, but I fount that some letters are not fully displayed(e.g. j,g).

Maybe font’s base_line has problem. For example, Only I set label’s height to 35, and use 32 size font, it displays normally.

This means that the height of the label must be larger than the font size.

And I can’t set textarea text height, so it can’t display normally.

What do you expect?

None

Code to reproduce

    lv_obj_t* textArea = lv_textarea_create(lv_src_act(), NULL);
  
    lv_obj_set_style_local_radius(textArea, LV_TEXTAREA_PART_BG, LV_STATE_DEFAULT, 8);
    lv_obj_set_style_local_pad_bottom(textArea, LV_TEXTAREA_PART_BG, LV_STATE_DEFAULT, 26);
    lv_obj_set_style_local_pad_top(textArea, LV_TEXTAREA_PART_BG, LV_STATE_DEFAULT, 26);
    lv_obj_set_style_local_pad_left(textArea, LV_TEXTAREA_PART_BG, LV_STATE_DEFAULT, 8);
    lv_obj_set_style_local_pad_right(textArea, LV_TEXTAREA_PART_BG, LV_STATE_DEFAULT, 8);
   
    lv_obj_set_style_local_text_color(textArea, LV_TEXTAREA_PART_BG, LV_STATE_DEFAULT, lv_color_make(0xE4, 0xE4, 0xE4));
    lv_obj_set_style_local_text_font(textArea, LV_TEXTAREA_PART_BG, LV_STATE_DEFAULT, FontProvider::GetInstance().GetFont(28)/*custom font*/);

    lv_obj_set_height(textArea, 80/*pad + font size*/);

Screenshot and/or video

font size is 32? top and bottom pads are 26px? So set the height to 84.

Please check my sample code again, font size is 28.

From sample code there is no data related to font. I can see only custom function called with argument of 28 number, which tells nothing about font size.

By the way, font structure has member called line_height or use function lv_font_get_line_height which will return it. Try to use it instead of raw undefined numbers. For example, internal font lv_font_montserrat_18 as name says, shall have the size 18px, but in fact the real (required) height of the font is 21 pixels.

1 Like

I think @BesitzeRuf is right.

See how lv_lib_freetype calculates line_height.