feat(txt): any Chinese character should be allowed to break line (#4127)

Signed-off-by: Xuxingliang <xuxingliang@xiaomi.com>
This commit is contained in:
Neo Xu 2023-04-13 01:25:14 +08:00 committed by GitHub
parent d6cc2ff76f
commit b770b6c74b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 5 deletions

View File

@ -226,6 +226,12 @@ static uint32_t lv_txt_get_next_word(const char * txt, const lv_font_t * font,
word_len--;
break;
}
else if(_lv_txt_is_a_word(letter_next) || _lv_txt_is_a_word(letter)) {
/*Found a word for single letter, usually true for CJK*/
*word_w_ptr = cur_w;
i = i_next;
break;
}
/*Update the output width*/
if(word_w_ptr != NULL && break_index == NO_BREAK_FOUND) *word_w_ptr = cur_w;

View File

@ -167,11 +167,6 @@ static inline bool _lv_txt_is_break_char(uint32_t letter)
uint8_t i;
bool ret = false;
/* each chinese character can be break */
if(letter >= 0x4E00 && letter <= 0x9FA5) {
return true;
}
/*Compare the letter to TXT_BREAK_CHARS*/
for(i = 0; LV_TXT_BREAK_CHARS[i] != '\0'; i++) {
if(letter == (uint32_t)LV_TXT_BREAK_CHARS[i]) {
@ -183,6 +178,35 @@ static inline bool _lv_txt_is_break_char(uint32_t letter)
return ret;
}
/**
* Test if char is break char or not (a text can broken here or not)
* @param letter a letter
* @return false: 'letter' is not break char
*/
static inline bool _lv_txt_is_a_word(uint32_t letter)
{
/*Cheap check on invalid letter*/
if(letter == 0) return false;
/*Chinese characters*/
if(letter >= 0x4E00 && letter <= 0x9FA5) {
return true;
}
/*Fullwidth ASCII variants*/
if(letter >= 0xFF01 && letter <= 0xFF5E) {
return true;
}
/*CJK symbols and punctuation*/
if(letter >= 0x3000 && letter <= 0x303F) {
return true;
}
return false;
}
/***************************************************************
* GLOBAL FUNCTION POINTERS FOR CHARACTER ENCODING INTERFACE
***************************************************************/