From 8ff7a7722919b4addb0e7b8b5aeef1f2670c64f6 Mon Sep 17 00:00:00 2001 From: cwl769 Date: Sun, 4 Aug 2024 20:50:11 +0800 Subject: [PATCH 1/2] Fixing convert from UTF-8 to Unicode --- src/canvas/font.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/canvas/font.cpp b/src/canvas/font.cpp index c547d25..bb59e8f 100644 --- a/src/canvas/font.cpp +++ b/src/canvas/font.cpp @@ -331,19 +331,24 @@ uint16_t NanoFont::unicode16FromUtf8(uint8_t ch) { #ifdef CONFIG_SSD1306_UNICODE_ENABLE static uint16_t unicode = 0; - ch &= 0x00FF; - if ( !unicode ) + static uint8_t rest = 0; + if(ch & 0x80) { - if ( ch >= 0xc0 ) + if(ch & 0x40) { - unicode = ch; + uint8_t mask = 0x1f; + rest = 1; + while( ((~mask) & ch) == ((~mask) & 0xff) ) mask >>= 1, ++rest; + unicode = ch & mask; return SSD1306_MORE_CHARS_REQUIRED; } - return ch; + else + { + unicode = (unicode << 6) | (ch & 0x3f); + return (--rest) ? SSD1306_MORE_CHARS_REQUIRED : unicode; + } } - uint16_t code = ((unicode & 0x1f) << 6) | (ch & 0x3f); - unicode = 0; - return code; + return ch; #else return ch; #endif From 079c79da423fd38374f4554d094b7f2441ac9fec Mon Sep 17 00:00:00 2001 From: cwl769 Date: Mon, 19 Aug 2024 18:20:51 +0800 Subject: [PATCH 2/2] Fixing convert from UTF-8 to Unicode --- src/canvas/font.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/canvas/font.cpp b/src/canvas/font.cpp index bb59e8f..71e4b97 100644 --- a/src/canvas/font.cpp +++ b/src/canvas/font.cpp @@ -330,10 +330,10 @@ lcduint_t NanoFont::getTextSize(const char *text, lcduint_t *height) uint16_t NanoFont::unicode16FromUtf8(uint8_t ch) { #ifdef CONFIG_SSD1306_UNICODE_ENABLE - static uint16_t unicode = 0; - static uint8_t rest = 0; if(ch & 0x80) { + static uint16_t unicode = 0; + static uint8_t rest = 0; if(ch & 0x40) { uint8_t mask = 0x1f;