How to use lvgl's lv_font_load to load a font file in bin format and display it on the screen;

Description

I use the lv_font_load function that comes with v7.4 to load the bin file, then create a label, bind the font to the style, set the text of the label, and finally display blank. I also tried the official lv_test_font_loader method, importing the fnt font File. The result remains the same.

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

arm

What LVGL version are you using?

V7.4

What do you want to achieve?

Import the bin file and display the font correctly

What have you tried so far?

Try to use API functions to import bin files and fnt font files by yourself.

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

  lv_font_t * myFont1;
    // myFont1 = lv_font_load("gui_app/font/font-PHT-cn-20.bin");
    myFont1 = lv_font_load("gui_app/font/font_1.fnt");
    // compare_fonts(&myFont, font - PHT - cn - 20.bin);
    lv_obj_t * label = lv_label_create(lv_scr_act(), NULL);
    lv_style_init(&style1);
    lv_style_set_text_font(&style1, LV_STATE_DEFAULT, myFont1);
    lv_obj_add_style(label, LV_LABEL_PART_MAIN, &style1);
    lv_label_set_text(label, "hello\n");

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

Please check if myFont1 is null or not after call of lv_font_load ().

As far as I know, reading from external filesystem (SD-card) needs a drive letter.
So your path should look like

lv_font_load ("S:/gui_app/font/font_1.fnt");

Thank you very much for your reply.My bin file is directly placed in the local directory of the development board and not in the filesystem (SD-card).I just tried it. After executing lv_font_load(), myFont1 is empty.

Without any drive letter, lv_font_load will fail:
Take a look into lv_font_load -> lv_fs_open -> if no drive letter, return null

Okay, thank you very much, it seems that the API provided by lvgl does not support reading local bin files directly.

You need to hook up your filesystem to LVGL in order for it to be used. https://docs.lvgl.io/latest/en/html/overview/file-system.html

If your development environment uses standard POSIX file functions (open, read, etc.) you can probably use the lv_fs_pc implementation in this repo.

Thanks for your reply, I will try it.

image
After I use the bin font file, I successfully read it, but this problem occurs, can you answer it? Thank you very much.
memcmp result is -1