diff --git a/src/widgets/span/lv_span.c b/src/widgets/span/lv_span.c index f9d4c311ef..5221bed80e 100644 --- a/src/widgets/span/lv_span.c +++ b/src/widgets/span/lv_span.c @@ -915,7 +915,7 @@ static bool lv_text_get_snippet(const char * txt, const lv_font_t * font, uint32_t ofs = lv_text_get_next_line(txt, LV_TEXT_LEN_MAX, font, use_width, &attributes); *end_ofs = ofs; - if(txt[ofs] == '\0' && *use_width < attributes.max_width && !(ofs && (txt[ofs - 1] == '\n' || txt[ofs - 1] == '\r'))) { + if(txt[ofs] == '\0' && *use_width <= attributes.max_width && !(ofs && (txt[ofs - 1] == '\n' || txt[ofs - 1] == '\r'))) { return false; } else { @@ -1320,16 +1320,17 @@ static void lv_draw_span(lv_obj_t * obj, lv_layer_t * layer) #endif bool need_draw_ellipsis = false; - uint32_t dot_width = 0; - + int32_t dot_width = 0; /* deal overflow */ if(ellipsis_valid) { - uint32_t dot_letter_w = lv_font_get_glyph_width(pinfo->font, '.', '.'); + int32_t dot_letter_w = lv_font_get_glyph_width(pinfo->font, '.', '.'); dot_width = dot_letter_w * 3; label_draw_dsc.flag = LV_TEXT_FLAG_BREAK_ALL; + int32_t text_width = coords.x2 - a.x1; uint32_t next_ofs; - need_draw_ellipsis = lv_text_get_snippet(pinfo->txt, pinfo->font, pinfo->letter_space, coords.x2 - a.x1 - dot_width, + text_width = text_width > dot_width ? text_width - dot_width : text_width; + need_draw_ellipsis = lv_text_get_snippet(pinfo->txt, pinfo->font, pinfo->letter_space, text_width, label_draw_dsc.flag, &pinfo->txt_w, &next_ofs); a.x2 = a.x1 + pinfo->txt_w; label_draw_dsc.text_length = next_ofs; @@ -1366,6 +1367,7 @@ static void lv_draw_span(lv_obj_t * obj, lv_layer_t * layer) if(need_draw_ellipsis) { label_draw_dsc.text = "..."; + label_draw_dsc.text_length = LV_TEXT_LEN_MAX; #if LV_USE_BIDI if(label_draw_dsc.bidi_dir == LV_BASE_DIR_RTL) { diff --git a/tests/ref_imgs/widgets/span_15.png b/tests/ref_imgs/widgets/span_15.png new file mode 100644 index 0000000000..508bb33d7e Binary files /dev/null and b/tests/ref_imgs/widgets/span_15.png differ diff --git a/tests/ref_imgs_vg_lite/widgets/span_15.png b/tests/ref_imgs_vg_lite/widgets/span_15.png new file mode 100644 index 0000000000..6863e436b5 Binary files /dev/null and b/tests/ref_imgs_vg_lite/widgets/span_15.png differ diff --git a/tests/src/test_cases/widgets/test_span.c b/tests/src/test_cases/widgets/test_span.c index 01b0ec91e8..f50ed73f35 100644 --- a/tests/src/test_cases/widgets/test_span.c +++ b/tests/src/test_cases/widgets/test_span.c @@ -586,4 +586,21 @@ void test_spangroup_set_line_space(void) lv_freetype_font_delete(font); } +void test_spangroup_less_letter_overflow(void) +{ + active_screen = lv_screen_active(); + spangroup = lv_spangroup_create(active_screen); + + lv_obj_set_style_outline_width(spangroup, 1, 0); + + lv_obj_set_width(spangroup, 25); + lv_obj_set_height(spangroup, 20); + + lv_span_t * span = lv_spangroup_new_span(spangroup); + lv_span_set_text_static(span, "less"); + lv_spangroup_set_overflow(spangroup, LV_SPAN_OVERFLOW_ELLIPSIS); + + TEST_ASSERT_EQUAL_SCREENSHOT("widgets/span_15.png"); +} + #endif