test(span): add span testcase for Chinese line break (#6236)

This commit is contained in:
Benign X 2024-05-20 11:50:20 +08:00 committed by GitHub
parent dfe7bd5563
commit 64ebf19734
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 49 additions and 4 deletions

View File

@ -878,11 +878,10 @@ static void lv_draw_span(lv_obj_t * obj, lv_layer_t * layer)
}
uint32_t tmp_ofs = next_ofs;
uint32_t letter = lv_text_encoded_prev(&cur_txt[cur_txt_ofs], &tmp_ofs);
uint32_t letter_next = lv_text_encoded_next(&cur_txt[cur_txt_ofs + next_ofs], NULL);
if(!(letter == '\0' || letter == '\n' || letter == '\r' || lv_text_is_break_char(letter) ||
lv_text_is_a_word(letter))) {
tmp_ofs = 0;
letter = lv_text_encoded_next(&cur_txt[cur_txt_ofs + next_ofs], &tmp_ofs);
if(!(letter == '\0' || letter == '\n' || letter == '\r' || lv_text_is_break_char(letter))) {
lv_text_is_a_word(letter) || lv_text_is_a_word(letter_next))) {
if(!(letter_next == '\0' || letter_next == '\n' || letter_next == '\r' || lv_text_is_break_char(letter_next))) {
break;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

View File

@ -309,4 +309,50 @@ void test_spangroup_newlines(void)
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/span_06.png");
}
#if LV_USE_FREETYPE && __WORDSIZE == 64
void test_spangroup_chinese_break_line(void)
{
lv_font_t * font = lv_freetype_font_create("src/test_files/fonts/noto/NotoSansSC-Regular.ttf",
LV_FREETYPE_FONT_RENDER_MODE_BITMAP, 24, LV_FREETYPE_FONT_STYLE_NORMAL);
if(!font) {
LV_LOG_ERROR("freetype font create failed.");
TEST_FAIL();
}
active_screen = lv_screen_active();
spangroup = lv_spangroup_create(active_screen);
lv_obj_set_size(spangroup, LV_PCT(100), LV_PCT(100));
lv_spangroup_set_mode(spangroup, LV_SPAN_MODE_BREAK);
lv_obj_set_style_text_font(spangroup, font, 0);
lv_obj_set_style_border_width(spangroup, 2, 0);
lv_obj_set_width(spangroup, 250);
lv_span_t * span1 = lv_spangroup_new_span(spangroup);
lv_span_set_text(span1, "八百标兵奔北坡");
lv_span_t * span2 = lv_spangroup_new_span(spangroup);
lv_span_set_text(span2, "炮兵并排北边跑");
lv_style_set_text_color(&span2->style, lv_palette_main(LV_PALETTE_RED));
lv_span_t * span3 = lv_spangroup_new_span(spangroup);
lv_span_set_text(span3, "中英文测试。The quick brown fox jumps over a lazy dog. ");
lv_style_set_text_color(&span3->style, lv_palette_main(LV_PALETTE_BLUE));
lv_span_t * span4 = lv_spangroup_new_span(spangroup);
lv_span_set_text(span4, "abcdefghijklmn中英文测试");
lv_style_set_text_color(&span4->style, lv_palette_main(LV_PALETTE_GREEN));
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/span_07.png");
lv_freetype_font_delete(font);
}
#else
void test_spangroup_chinese_break_line(void)
{
}
#endif
#endif