How to add Arabic letters to keyboard

Description

I want to add an Arabic keyboard to my program but when I try to implement the code it shows empty buttons

What LVGL version are you using?

8

What do you want to achieve?

Arabic keyboard

What have you tried so far?

I’ve tried to set the keyboard mode to “LV_KEYBOARD_MODE_TEXT_ARABIC”,
added a map and then used “lv_keyboard_set_map” but still it shows the same result

Code to reproduce

//kb is defined as a global variable "static lv_obj_t * kb"
 lv_coord_t kb_height = LV_MATH_MIN(LV_VER_RES / 2, LV_DPI * 4 / 3);
            lv_obj_set_height(tv, LV_VER_RES - kb_height);
            kb = lv_keyboard_create(lv_scr_act(), NULL);
            lv_obj_set_height(kb, kb_height);
            lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_TEXT_ARABIC);
            lv_obj_align(kb, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
            lv_obj_set_event_cb(kb, kb_event_cb);

Screenshot and/or video

Which font are you using? It may not include the necessary characters.

Thank you for your response @embeddedt
I didn’t use anyone in particular, I though it would show a default font, was I wrong?

How can I add a font to a keyboard?

The default font doesn’t include many international characters to keep the size small. There is another font included but disabled by default which includes the needed Arabic characters. You can enable it in lv_conf.h. Be sure to change LV_FONT_DEFAULT as well.

Hello @embeddedt

sorry for the late response, I tried to enable the font by changing 0 to 1:

#define LV_FONT_MONTSERRAT_12_SUBPX 1
#define LV_FONT_MONTSERRAT_28_COMPRESSED 1
#define LV_FONT_DEJAVU_16_PERSIAN_HEBREW 1
#define LV_FONT_SIMSUN_16_CJK 1

sorry but I didn’t find the default font as you mentioned, is it in lv_conf.h as well? or it’s in the widget example?

It’s slightly further down in the same file.

@embeddedt
Sorry I’m new to LVGL .

I defined it as such:
#define LV_FONT_DEFAULT &LV_FONT_DEJAVU_16_PERSIAN_HEBREW
but still it didn’t show the Arabic letters, was the way I defined it wrong?

I think that should have given you a warning/error, and/or crashed the application, as LV_FONT_DEJAVU_16_PERSIAN_HEBREW is just a config option that can only be 0 or 1.

The correct way to define it is like this, similarly to how Montserrat was selected:

#define LV_FONT_DEFAULT &lv_font_dejavu_16_persian_hebrew

@embeddedt

I defined it as you said but still it gives me empty buttons, is there something I need to adjust in my project as well or when creating the keyboard?

Keyboard function:
lv_coord_t kb_height = LV_MATH_MIN(LV_VER_RES / 2, LV_DPI * 4 / 3);
kb = lv_keyboard_create(lv_scr_act(), NULL);
lv_obj_set_height(kb, kb_height);
lv_obj_align(kb, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
lv_keyboard_set_cursor_manage(kb, true);
lv_obj_set_event_cb(kb, kb_event_cb);
lv_keyboard_set_textarea(kb, ta);