From 48dc44ea8f45d3f8758bda19d233c9d40f2d0ded Mon Sep 17 00:00:00 2001 From: HarukiToreda <116696711+HarukiToreda@users.noreply.github.com> Date: Sat, 10 May 2025 17:29:18 -0400 Subject: [PATCH] Fix for degree sign type characters on text message screen --- src/graphics/Screen.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 858736d35..f4bfb8eba 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -1170,10 +1170,17 @@ void drawStringWithEmotes(OLEDDisplay* display, int x, int y, const std::string& } if (!matched) { - char c[2] = {line[i], '\0'}; - display->drawString(cursorX, fontY, c); - cursorX += display->getStringWidth(c); - ++i; + uint8_t c = static_cast(line[i]); + int charLen = 1; + + if ((c & 0xE0) == 0xC0) charLen = 2; // 2-byte UTF-8 + else if ((c & 0xF0) == 0xE0) charLen = 3; // 3-byte UTF-8 + else if ((c & 0xF8) == 0xF0) charLen = 4; // 4-byte UTF-8 + + std::string utf8char = line.substr(i, charLen); + display->drawString(cursorX, fontY, utf8char.c_str()); + cursorX += display->getStringWidth(utf8char.c_str()); + i += charLen; } } }