The proper procedure to enable display of BIDI (Arabic) text

I am trying to display Arabic text on screen. I am using PC simulator. According to your instruction, I applied the following procedure:

convert font into binary format using lv_font_conv with this command: (size is ~12KB)

npx lv_font_conv --size 16 --format bin --bpp 4 --font c:/e-ws/simpo.ttf -r 0x20-0x7f -r 0x600-0x6ff  -r 0xfe00-0xfeff -o c:/e-ws/simpo_16.bin

I verified the imported fonts using –format dump switch.
Then, in my initialization routing, I added:

    lv_font_t * my_font; // <-- this is a global variable

    lv_port_fs_init();
    my_font = lv_font_load("c:/e-ws/simpo_16.bin");

And modified lv_config.h with:

#define LV_USE_BIDI     1
#define LV_USE_ARABIC_PERSIAN_CHARS 1

And finally, wrote a code to display the Arabic text:

    static lv_style_t style2;
    lv_style_init(&style2);

    lv_obj_t * label2 = lv_label_create(lv_scr_act(), NULL);
    lv_obj_add_style(label2, LV_OBJ_PART_MAIN, &style2);
    lv_style_set_text_font(&style2, LV_STATE_DEFAULT, my_font);
    lv_obj_set_style_local_text_color(label2, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
    lv_obj_set_width(label2, 128);
    lv_obj_align(label2, NULL, LV_ALIGN_CENTER, 0, 0);
    lv_label_set_text(label2, "احمد");
    //lv_label_set_text(label2, "ahmad");

The English text is displayed correctly, but not the Arabic’s.

Did I miss any configuration or initialization step?
Thanks.

Hi,

Is it working if you NOT load the font but convert it to C array?

The Arabic text is simply not displayed?

With a built-in font can you use symbols? E.g.

 lv_label_set_text(label2, LV_SYMBOL_OK);

I verified that font was loaded into memory using debugger. It looks that lvgl does not use my_font when drawing the label.
When I use canvas I can see the Arabic text on screen.
Is the code above correct to set the font for a text/label?

Thanks.

It’s strange that it works with the canvas.

Please attach simpo.ttf and the converted bin file and will try it.

thanks for reply. here is the bin and ttf files.simpo.zip (94.0 KB)

I’ve tested it and it found a minor issue in your code in these lines:

    lv_obj_add_style(label2, LV_OBJ_PART_MAIN, &style2);
    lv_style_set_text_font(&style2, LV_STATE_DEFAULT, my_font);

You should set the properties of the style first and apply it after that. Else LVGL won’t know that the style is changed.

So try this:

    lv_style_set_text_font(&style2, LV_STATE_DEFAULT, my_font);
    lv_obj_add_style(label2, LV_OBJ_PART_MAIN, &style2);

If you modify the style while it is already used by widgets you need to call lv_obj_report_style_mod(&style)