bidi fixes + add missing prefix to lv_encoded_get_char_id

This commit is contained in:
Gabor Kiss-Vamosi
2019-11-06 05:19:06 +01:00
parent 5d5a8b4894
commit 5441cf9998
4 changed files with 17 additions and 20 deletions
+1 -1
View File
@@ -220,7 +220,7 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, const lv_st
letter_w = lv_font_get_glyph_width(font, letter, letter_next);
if(sel_start != 0xFFFF && sel_end != 0xFFFF) {
int char_ind = lv_encoded_get_char_id(bidi_txt, i);
int char_ind = lv_txt_encoded_get_char_id(bidi_txt, i);
/*Do not draw the rectangle on the character at `sel_start`.*/
if(char_ind > sel_start && char_ind <= sel_end) {
lv_area_t sel_coords;
+2 -2
View File
@@ -56,7 +56,7 @@ uint32_t (*lv_txt_encoded_conv_wc)(uint32_t) = lv_txt_utf8_con
uint32_t (*lv_txt_encoded_next)(const char *, uint32_t *) = lv_txt_utf8_next;
uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *) = lv_txt_utf8_prev;
uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t) = lv_txt_utf8_get_byte_id;
uint32_t (*lv_encoded_get_char_id)(const char *, uint32_t) = lv_txt_utf8_get_char_id;
uint32_t (*lv_txt_encoded_get_char_id)(const char *, uint32_t) = lv_txt_utf8_get_char_id;
uint32_t (*lv_txt_get_encoded_length)(const char *) = lv_txt_utf8_get_length;
#elif LV_TXT_ENC == LV_TXT_ENC_ASCII
uint8_t (*lv_txt_encoded_size)(const char *) = lv_txt_iso8859_1_size;
@@ -65,7 +65,7 @@ uint32_t (*lv_txt_encoded_conv_wc)(uint32_t) = lv_txt_iso8859_
uint32_t (*lv_txt_encoded_next)(const char *, uint32_t *) = lv_txt_iso8859_1_next;
uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *) = lv_txt_iso8859_1_prev;
uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t) = lv_txt_iso8859_1_get_byte_id;
uint32_t (*lv_encoded_get_char_id)(const char *, uint32_t) = lv_txt_iso8859_1_get_char_id;
uint32_t (*lv_txt_encoded_get_char_id)(const char *, uint32_t) = lv_txt_iso8859_1_get_char_id;
uint32_t (*lv_txt_get_encoded_length)(const char *) = lv_txt_iso8859_1_get_length;
#endif
+1 -1
View File
@@ -188,7 +188,7 @@ extern uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t);
* @param byte_id byte index
* @return character index of the letter at 'byte_id'th position
*/
extern uint32_t (*lv_encoded_get_char_id)(const char *, uint32_t);
extern uint32_t (*lv_txt_encoded_get_char_id)(const char *, uint32_t);
/**
* Get the number of characters (and NOT bytes) in a string.
+13 -16
View File
@@ -578,7 +578,7 @@ uint16_t lv_label_get_anim_speed(const lv_obj_t * label)
* index (different in UTF-8)
* @param pos store the result here (E.g. index = 0 gives 0;0 coordinates)
*/
void lv_label_get_letter_pos(const lv_obj_t * label, uint16_t index, lv_point_t * pos)
void lv_label_get_letter_pos(const lv_obj_t * label, uint16_t char_id, lv_point_t * pos)
{
LV_ASSERT_OBJ(label, LV_OBJX_NAME);
LV_ASSERT_NULL(pos);
@@ -593,8 +593,6 @@ void lv_label_get_letter_pos(const lv_obj_t * label, uint16_t index, lv_point_t
uint8_t letter_height = lv_font_get_line_height(font);
lv_coord_t y = 0;
lv_txt_flag_t flag = LV_TXT_FLAG_NONE;
uint16_t visual_pos;
char *bidi_txt;
if(ext->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR;
if(ext->expand != 0) flag |= LV_TXT_FLAG_EXPAND;
@@ -608,12 +606,12 @@ void lv_label_get_letter_pos(const lv_obj_t * label, uint16_t index, lv_point_t
max_w = LV_COORD_MAX;
}
index = lv_txt_encoded_get_byte_id(txt, index);
uint16_t byte_id = lv_txt_encoded_get_byte_id(txt, char_id);
/*Search the line of the index letter */;
while(txt[new_line_start] != '\0') {
new_line_start += lv_txt_get_next_line(&txt[line_start], font, style->text.letter_space, max_w, flag);
if(index < new_line_start || txt[new_line_start] == '\0')
if(byte_id < new_line_start || txt[new_line_start] == '\0')
break; /*The line of 'index' letter begins at 'line_start'*/
y += letter_height + style->text.line_space;
@@ -621,30 +619,29 @@ void lv_label_get_letter_pos(const lv_obj_t * label, uint16_t index, lv_point_t
}
/*If the last character is line break then go to the next line*/
if(index > 0) {
if((txt[index - 1] == '\n' || txt[index - 1] == '\r') && txt[index] == '\0') {
if(byte_id > 0) {
if((txt[byte_id - 1] == '\n' || txt[byte_id - 1] == '\r') && txt[byte_id] == '\0') {
y += letter_height + style->text.line_space;
line_start = index;
line_start = byte_id;
}
}
char *bidi_txt;
#if LV_USE_BIDI
/*Handle Bidi*/
visual_pos = lv_bidi_get_visual_pos(&txt[line_start], &bidi_txt, new_line_start - line_start, lv_obj_get_base_dir(label), index - line_start);
uint16_t line_char_id = lv_txt_encoded_get_char_id(&txt[line_start], byte_id - line_start);
printf("vp:%d, ", visual_pos);
visual_pos = lv_txt_encoded_get_byte_id(bidi_txt, visual_pos);
printf("vpb:%d, ", visual_pos);
uint16_t visual_char_pos = lv_bidi_get_visual_pos(&txt[line_start], &bidi_txt, new_line_start - line_start, lv_obj_get_base_dir(label), line_char_id);
uint16_t visual_byte_pos = lv_txt_encoded_get_byte_id(bidi_txt, visual_char_pos);
#else
visual_pos = index - line_start;
bidi_txt = &txt[line_start];
#endif
/*Calculate the x coordinate*/
lv_coord_t x = lv_txt_get_width(bidi_txt, visual_pos, font, style->text.letter_space, flag);
lv_coord_t x = lv_txt_get_width(bidi_txt, visual_byte_pos, font, style->text.letter_space, flag);
if(index != line_start) x += style->text.letter_space;
if(char_id != line_start) x += style->text.letter_space;
if(align == LV_LABEL_ALIGN_CENTER) {
lv_coord_t line_w;
@@ -764,7 +761,7 @@ uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos)
#if LV_USE_BIDI
/*Handle Bidi*/
logical_pos = lv_bidi_get_logical_pos(&txt[line_start], NULL, new_line_start - line_start, lv_obj_get_base_dir(label), lv_encoded_get_char_id(bidi_txt, i));
logical_pos = lv_bidi_get_logical_pos(&txt[line_start], NULL, new_line_start - line_start, lv_obj_get_base_dir(label), lv_txt_encoded_get_char_id(bidi_txt, i));
#else
logical_pos = lv_encoded_get_char_id(bidi_txt, i);
#endif