From 14fe7ee414c672530b36420182539abfd53c7839 Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Mon, 12 Oct 2020 20:01:03 -0300 Subject: [PATCH] Fix UTF8 handling for Color UI (#19708) --- Marlin/src/lcd/tft/tft_string.cpp | 11 +++++++++++ Marlin/src/lcd/tft/tft_string.h | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Marlin/src/lcd/tft/tft_string.cpp b/Marlin/src/lcd/tft/tft_string.cpp index 7e66c3d29..663ed97c3 100644 --- a/Marlin/src/lcd/tft/tft_string.cpp +++ b/Marlin/src/lcd/tft/tft_string.cpp @@ -116,6 +116,17 @@ void TFT_String::add(uint8_t *string, int8_t index, uint8_t *itemString) { eol(); } +void TFT_String::add(uint8_t *string) { + wchar_t wchar; + while (*string) { + string = get_utf8_value_cb(string, read_byte, &wchar); + if (wchar > 255) wchar |= 0x0080; + uint8_t ch = uint8_t(wchar & 0x00FF); + add_character(ch); + } + eol(); +} + void TFT_String::add_character(uint8_t character) { if (length < MAX_STRING_LENGTH) { data[length] = character; diff --git a/Marlin/src/lcd/tft/tft_string.h b/Marlin/src/lcd/tft/tft_string.h index d83d3af70..924d6de43 100644 --- a/Marlin/src/lcd/tft/tft_string.h +++ b/Marlin/src/lcd/tft/tft_string.h @@ -85,7 +85,7 @@ class TFT_String { static void set(); static void add(uint8_t character) { add_character(character); eol(); } - static void add(uint8_t *string) { while (*string) { add_character(*string++); } eol(); } + static void add(uint8_t *string); static void add(uint8_t *string, int8_t index, uint8_t *itemString = NULL); static void set(uint8_t *string) { set(); add(string); }; static void set(uint8_t *string, int8_t index, const char *itemString = NULL) { set(); add(string, index, (uint8_t *)itemString); };