lvgl: Arabic display error

Perform all steps below and tick them with [x]

  • Check the related part of the Documentation
  • Update lvgl to the latest version
  • Reproduce the issue in a Simulator

Describe the bug

I meet some problem when doing Arabic Input. I have set LV_USE_BIDI==1 and LV_USE_ARABIC_PERSIAN_CHARS==1.

Probelm1: I found that if I use the lv_textarea_add_text interface to add a string, an error will occur, and the actual string does not meet expectations.But if only a single character is added, the result is as expected. According to the code, I found that because the lv_label_ins_text interface performs BIDI processing on the input string when LV_USE_BIDI==1, resulting in subsequent character deformation errors. Excuse me, why is BIDI processing required when LV_USE_BIDI==1 in the lv_label_ins_text interface?

code:

#if LV_USE_BIDI
    char * bidi_buf = lv_mem_buf_get(ins_len + 1);
    LV_ASSERT_MALLOC(bidi_buf);
    if(bidi_buf == NULL) return;

    _lv_bidi_process(txt, bidi_buf, lv_obj_get_style_base_dir(obj, LV_PART_MAIN));
    _lv_txt_ins(label->text, pos, bidi_buf);

    lv_mem_buf_release(bidi_buf);
#else
    _lv_txt_ins(label->text, pos, txt);
#endif

if delete bidi process,the result is correct

Problem2: If using lv_textarea_set_align to set LV_TEXT_ALIGN_RIGHT,the cursor will not move.

To Reproduce

static const char * const default_kb_map_ar[] =
{
    "del", "جثف", "ص", "ث", "ق", "ف", "غ", "ع", "ه","خ", "ح","ج", "\n",
    "ش", "س", "ي", "ب", "ل", "ا", "ت", "ن", "م", "ك", "ط",  "\n",
    "ذ", "ء", "ؤ", "ر", "ى", "ة", "و", "ز", "ظ", "د", "ز", "ظ", "د","\n",
	"1", "2", "3", "4", "5", "q", "w", "e", "r", "!", ":", "?", "(","\n",
};

static const lv_btnmatrix_ctrl_t default_kb_ctrl_ar_map[] = {
    5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
    4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
};


static void keyboard_event_cb(lv_event_t *e){
    lv_obj_t * obj = lv_event_get_target(e);

    lv_keyboard_t * keyboard = (lv_keyboard_t *)obj;
    uint16_t btn_id   = lv_btnmatrix_get_selected_btn(obj);
    if(btn_id == LV_BTNMATRIX_BTN_NONE) return;

    const char * txt = lv_btnmatrix_get_btn_text(obj, lv_btnmatrix_get_selected_btn(obj));
    if(txt == NULL) return;
    
    if(txt=="del"){lv_textarea_del_char(keyboard->ta);}
    else{
       lv_textarea_add_text(keyboard->ta, txt);
    }
}

LV_FONT_DECLARE(testfont);
void lv_arabic_input_test(void){
    static lv_style_t style;
    lv_style_init(&style);
    lv_style_set_text_font(&style,&testfont);

       lv_obj_t *textarea = lv_textarea_create(lv_scr_act());

    lv_obj_t *keyboard = lv_keyboard_create(lv_scr_act());
    lv_obj_add_style(keyboard, &style, 0);
    lv_keyboard_set_mode(keyboard, LV_KEYBOARD_MODE_TEXT_LOWER);
    lv_keyboard_set_map(keyboard, LV_KEYBOARD_MODE_TEXT_LOWER, (const char **)default_kb_map_ar, default_kb_ctrl_ar_map);
    lv_obj_remove_event_cb(keyboard, lv_keyboard_def_event_cb);
    lv_obj_add_event_cb(keyboard, keyboard_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
    lv_keyboard_set_textarea(keyboard, textarea);
    lv_obj_add_style(textarea, &style, 0);
}

Expected behavior

Screenshots or video

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (16 by maintainers)

Commits related to this issue

Most upvoted comments

I have send a PR.