1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

fix(textarea): fix accepted chars issue on big endian systems (#5479)

Co-authored-by: Jim Boström <jim.bostrom@indra.no>
Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>
This commit is contained in:
jimbom 2024-01-25 14:05:53 +01:00 committed by GitHub
parent e05e1f3c7a
commit 65af3d79d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -116,14 +116,25 @@ void lv_textarea_add_char(lv_obj_t * obj, uint32_t c)
const char * letter_buf = (char *)&u32_buf;
uint32_t c2 = c;
#if LV_BIG_ENDIAN_SYSTEM
if(c != 0) while(*letter_buf == 0) ++letter_buf;
/*The byte order may or may not need to be swapped here to get correct c_uni below,
since lv_textarea_add_text is ordering bytes correctly before calling lv_textarea_add_char.
Assume swapping is needed if MSB is zero. May not be foolproof. */
if((c != 0) && ((c & 0xff000000) == 0)) {
c2 = ((c >> 24) & 0xff) | /*move byte 3 to byte 0*/
((c << 8) & 0xff0000) | /*move byte 1 to byte 2*/
((c >> 8) & 0xff00) | /*move byte 2 to byte 1*/
((c << 24) & 0xff000000); /*byte 0 to byte 3*/
}
#endif
lv_result_t res = insert_handler(obj, letter_buf);
if(res != LV_RESULT_OK) return;
uint32_t c_uni = _lv_text_encoded_next((const char *)&c, NULL);
uint32_t c_uni = _lv_text_encoded_next((const char *)&c2, NULL);
if(char_is_accepted(obj, c_uni) == false) {
LV_LOG_INFO("Character is not accepted by the text area (too long text or not in the accepted list)");