Hi there
I use lvgl simulator codeblocks/windows and i neet to change my lvgl font
to LV_FONT_DEJAVU_16_PERSIAN_HEBREW but i cant drive it
lvgl version: V7.9.0-dev

i use this codes:

    static lv_style_t style;

    lv_style_set_radius(&style, LV_STATE_DEFAULT, 5);
    lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER);
    lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER);
    lv_style_set_border_width(&style, LV_STATE_DEFAULT, 2);
    lv_style_set_border_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE);

    lv_style_set_pad_top(&style, LV_STATE_DEFAULT, 10);
    lv_style_set_pad_bottom(&style, LV_STATE_DEFAULT, 10);
    lv_style_set_pad_left(&style, LV_STATE_DEFAULT, 10);
    lv_style_set_pad_right(&style, LV_STATE_DEFAULT, 10);

    lv_style_set_text_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE);
    lv_style_set_text_letter_space(&style, LV_STATE_DEFAULT, 5);
    lv_style_set_text_line_space(&style, LV_STATE_DEFAULT, 20);
    lv_style_set_text_decor(&style, LV_STATE_DEFAULT, LV_TEXT_DECOR_UNDERLINE);

    //change font
    lv_style_set_text_font(&style, LV_STATE_DEFAULT, LV_FONT_DEJAVU_16_PERSIAN_HEBREW);///////////////

    /*Create an object with the new style*/
    lv_obj_t * obj = lv_label_create(lv_scr_act(), NULL);
    lv_obj_add_style(obj, LV_LABEL_PART_MAIN, &style);
    lv_label_set_text(obj, "Text of\n" "|   سلام علیکم |\n"
                            "a label");
    lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0);

it show’s nothing
i just need to show some text on a lable to start lvgl.
can anyone help me, please?

You don’t have any problem in displaying English font, do you?

Check these in lv_conf.h:


#define LV_USE_BIDI     1
/* Set the default direction. Supported values:
 * `LV_BIDI_DIR_LTR` Left-to-Right
 * `LV_BIDI_DIR_RTL` Right-to-Left
 * `LV_BIDI_DIR_AUTO` detect texts base direction */

1 Like

Thank you,
i just downloaded codeblocks project files from this link:
but it seem’s too old and it has not "#define LV_USE_ARABIC_PERSIAN_CHARS 1
" in its lv_conf.h

anyway, i use
with VS2017, also i downloaded
which all are last version and simulation is fantastic.

i choosed lv_ex_get_started_2
i noticed :
#define LV_USE_BIDI 1
is seted.

and just added font change function, but it crashed!!

void lv_ex_get_started_2(void)
    static lv_style_t style_btn;
    static lv_style_t style_btn_red;

    /*Create a simple button style*/

	//change font          change font ////////////////////////////////////////////
	lv_style_set_text_font(&style_btn, LV_STATE_DEFAULT, LV_FONT_DEJAVU_16_PERSIAN_HEBREW);///////////////

	lv_style_set_radius(&style_btn, LV_STATE_DEFAULT, 10);
    lv_style_set_bg_opa(&style_btn, LV_STATE_DEFAULT, LV_OPA_COVER);
    lv_style_set_bg_color(&style_btn, LV_STATE_DEFAULT, LV_COLOR_SILVER);
    lv_style_set_bg_grad_color(&style_btn, LV_STATE_DEFAULT, LV_COLOR_GRAY);
    lv_style_set_bg_grad_dir(&style_btn, LV_STATE_DEFAULT, LV_GRAD_DIR_VER);

    /*Swap the colors in pressed state*/
    lv_style_set_bg_color(&style_btn, LV_STATE_PRESSED, LV_COLOR_GRAY);
    lv_style_set_bg_grad_color(&style_btn, LV_STATE_PRESSED, LV_COLOR_SILVER);

    /*Add a border*/
    lv_style_set_border_color(&style_btn, LV_STATE_DEFAULT, LV_COLOR_WHITE);
    lv_style_set_border_opa(&style_btn, LV_STATE_DEFAULT, LV_OPA_70);
    lv_style_set_border_width(&style_btn, LV_STATE_DEFAULT, 2);

    /*Different border color in focused state*/
    lv_style_set_border_color(&style_btn, LV_STATE_FOCUSED, LV_COLOR_BLUE);
    lv_style_set_border_color(&style_btn, LV_STATE_FOCUSED | LV_STATE_PRESSED, LV_COLOR_NAVY);

    /*Set the text style*/
    lv_style_set_text_color(&style_btn, LV_STATE_DEFAULT, LV_COLOR_WHITE);

    /*Make the button smaller when pressed*/
    lv_style_set_transform_height(&style_btn, LV_STATE_PRESSED, -5);
    lv_style_set_transform_width(&style_btn, LV_STATE_PRESSED, -10);
    /*Add a transition to the size change*/
    static lv_anim_path_t path;
    lv_anim_path_set_cb(&path, lv_anim_path_overshoot);

    lv_style_set_transition_prop_1(&style_btn, LV_STATE_DEFAULT, LV_STYLE_TRANSFORM_HEIGHT);
    lv_style_set_transition_prop_2(&style_btn, LV_STATE_DEFAULT, LV_STYLE_TRANSFORM_WIDTH);
    lv_style_set_transition_time(&style_btn, LV_STATE_DEFAULT, 300);
    lv_style_set_transition_path(&style_btn, LV_STATE_DEFAULT, &path);

    /*Create a red style. Change only some colors.*/
    lv_style_set_bg_color(&style_btn_red, LV_STATE_DEFAULT, LV_COLOR_RED);
    lv_style_set_bg_grad_color(&style_btn_red, LV_STATE_DEFAULT, LV_COLOR_MAROON);
    lv_style_set_bg_color(&style_btn_red, LV_STATE_PRESSED, LV_COLOR_MAROON);
    lv_style_set_bg_grad_color(&style_btn_red, LV_STATE_PRESSED, LV_COLOR_RED);
    lv_style_set_text_color(&style_btn_red, LV_STATE_DEFAULT, LV_COLOR_WHITE);
    /*Create buttons and use the new styles*/
    lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL);     /*Add a button the current screen*/
    lv_obj_set_pos(btn, 10, 10);                            /*Set its position*/
    lv_obj_set_size(btn, 120, 50);                          /*Set its size*/
    lv_obj_reset_style_list(btn, LV_BTN_PART_MAIN);         /*Remove the styles coming from the theme*/
    lv_obj_add_style(btn, LV_BTN_PART_MAIN, &style_btn);

    lv_obj_t * label = lv_label_create(btn, NULL);          /*Add a label to the button*/
    lv_label_set_text(label, "Button");                     /*Set the labels text*/

    /*Create a new button*/
    lv_obj_t * btn2 = lv_btn_create(lv_scr_act(), btn);
    lv_obj_set_pos(btn2, 10, 80);
    lv_obj_set_size(btn2, 120, 50);                             /*Set its size*/
    lv_obj_reset_style_list(btn2, LV_BTN_PART_MAIN);         /*Remove the styles coming from the theme*/
    lv_obj_add_style(btn2, LV_BTN_PART_MAIN, &style_btn);
    lv_obj_add_style(btn2, LV_BTN_PART_MAIN, &style_btn_red);   /*Add the red style on top of the current */
    lv_obj_set_style_local_radius(btn2, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); /*Add a local style*/

    label = lv_label_create(btn2, NULL);          /*Add a label to the button*/
    lv_label_set_text(label, "Button 2");                     /*Set the labels text*/

There is one addition setting missing in lv_conf.h:


And you should inspect your compiler warning messages:
My gcc tells me:

../src/lv_conf.h:380:42: warning: passing argument 3 of 'lv_style_set_text_font' makes pointer from integer without a cast [-Wint-conversion]


  lv_style_set_text_font (&style_btn, LV_STATE_DEFAULT, LV_FONT_DEJAVU_16_PERSIAN_HEBREW);

is wrong!

It should be:

  lv_style_set_text_font (&style_btn, LV_STATE_DEFAULT, &lv_font_dejavu_16_persian_hebrew);


thank you.

lv_style_set_text_font(&style_btn_red, LV_STATE_DEFAULT, &lv_font_dejavu_16_persian_hebrew);

i change my code and without any error it compiles/builds and run but it not show any arabic character.

i use windows10, VS2017, lvgl7.9.0-dev for simulating

visual studio saved my text in unicode format.
and in run mode just show ??? for arabic characters,
i used “lv_ex_get_started_2.c” sample and just add some codes:

	//change font
	lv_style_set_text_font(&style_btn, LV_STATE_DEFAULT, &lv_font_dejavu_16_persian_hebrew);///////////////
	lv_obj_reset_style_list(label, LV_BTN_PART_MAIN);         /*Remove the styles coming from the theme*/
	lv_obj_add_style(label, LV_BTN_PART_MAIN, &style_btn); //set new style which contains new FONT

	lv_label_set_text(label, "Button 2   سلام");                     /*Set the labels text*/

is there any thing wrong ?


Hmm, could be a file encoding problem!?
I’m not sure whether VS needs a UTF8 encoding with BOM.
If you have notepad++ you can easily check the file encoding and you can convert it to UTF8 with BOM and try.
I did use it with real hardware and it works.

1 Like

Thank you so much. wow , VS encoded the file as UTF-8-BOM but lvgl needs UTF-8 so in Notepad++ i changed and BOM, just done.

UTF-8 notepad vs-run2 okok