From 5523c12cfd01c859a01f26575a1dfff4c43eac8e Mon Sep 17 00:00:00 2001 From: Giuliano Zaro <3684609+GMagician@users.noreply.github.com> Date: Wed, 1 Nov 2023 01:02:11 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20Fix=20MarlinUI=20UTF-8=20chars?= =?UTF-8?q?=20(#26381)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/lcd/lcdprint.cpp | 18 +++++------------- Marlin/src/lcd/utf8.cpp | 8 +++++--- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/Marlin/src/lcd/lcdprint.cpp b/Marlin/src/lcd/lcdprint.cpp index 2b524e983f..c84a695c78 100644 --- a/Marlin/src/lcd/lcdprint.cpp +++ b/Marlin/src/lcd/lcdprint.cpp @@ -51,6 +51,7 @@ lcd_uint_t expand_u8str_P(char * const outstr, PGM_P const ptpl, const int8_t in int8_t n = maxlen; while (n > 0) { lchar_t wc; + uint8_t *psc = (uint8_t *)p; p = get_utf8_value_cb(p, read_byte_rom, wc); if (!wc) break; if (wc == '{' || wc == '~' || wc == '*') { @@ -88,20 +89,11 @@ lcd_uint_t expand_u8str_P(char * const outstr, PGM_P const ptpl, const int8_t in n -= utf8_strlen(o); o += strlen(o); } - else if (wc == '@') { - *o++ = AXIS_CHAR(ind); - *o = '\0'; - n--; - } - else if (wc > 255 && prop == 2) { - // Wide glyph support incomplete - *((uint16_t*)o) = wc; - o += 2; - *o = '\0'; - n--; - } else { - *o++ = wc; + if (wc == '@') + *o++ = AXIS_CHAR(ind); + else + while (psc != p) *o++ = read_byte_rom(psc++); *o = '\0'; n--; } diff --git a/Marlin/src/lcd/utf8.cpp b/Marlin/src/lcd/utf8.cpp index 6957fffc64..d9dd53e953 100644 --- a/Marlin/src/lcd/utf8.cpp +++ b/Marlin/src/lcd/utf8.cpp @@ -94,13 +94,15 @@ int pf_bsearch_r(void *userdata, size_t num_data, pf_bsearch_cb_comp_t cb_comp, return -1; } -/* Returns true if passed byte is first byte of UTF-8 char sequence */ +// Is the passed byte the first byte of a UTF-8 char sequence? static inline bool utf8_is_start_byte_of_char(const uint8_t b) { return 0x80 != (b & 0xC0); } -/* This function gets the character at the pstart position, interpreting UTF8 multibyte sequences - and returns the pointer to the next character */ +/** + * Get the character at pstart, interpreting UTF8 multibyte sequences. + * Return the pointer to the next character. + */ const uint8_t* get_utf8_value_cb(const uint8_t *pstart, read_byte_cb_t cb_read_byte, lchar_t &pval) { uint32_t val = 0; const uint8_t *p = pstart;