From 3abe7f7094eb963df181bfc2e0420b02390544b1 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Wed, 17 Mar 2021 11:43:35 +0100 Subject: [PATCH] Don't truncate the lines on chinese chars --- radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp | 2 ++ .../src/thirdparty/libopenui/src/libopenui_helpers.h | 11 +++++++++++ radio/src/thirdparty/libopenui/src/static.cpp | 5 ++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp index e3ef9ed3f..4db3e7ed7 100755 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp @@ -639,6 +639,7 @@ coord_t BitmapBuffer::drawSizedText(coord_t x, coord_t y, const char * s, uint8_ while (len--) { unsigned int c = uint8_t(*s); + // TRACE("c = %d %o 0x%X '%c'", c, c, c, c); if (!c) { break; @@ -647,6 +648,7 @@ coord_t BitmapBuffer::drawSizedText(coord_t x, coord_t y, const char * s, uint8_ // CJK char s++; c = uint8_t(*s) + ((c & 0x01u) << 8u) - 1; + // TRACE("CJK = %d", c); if (c >= 0x101) c -= 1; c += CJK_FIRST_LETTER_INDEX; diff --git a/radio/src/thirdparty/libopenui/src/libopenui_helpers.h b/radio/src/thirdparty/libopenui/src/libopenui_helpers.h index 5c5597be4..b91388966 100644 --- a/radio/src/thirdparty/libopenui/src/libopenui_helpers.h +++ b/radio/src/thirdparty/libopenui/src/libopenui_helpers.h @@ -79,3 +79,14 @@ inline std::string TEXT_AT_INDEX(const char * val, uint8_t idx) return std::string(start, min(val[0], (uint8_t)strlen(start))); } +inline const char * findNextLine(const char * stack) +{ + while (true) { + const char * pos = strchr(stack, '\n'); + if (!pos) + return nullptr; + if (pos == stack || *((uint8_t *)(pos - 1)) < 0xFE) + return pos; + stack = pos + 1; + } +} diff --git a/radio/src/thirdparty/libopenui/src/static.cpp b/radio/src/thirdparty/libopenui/src/static.cpp index 8d1ef9c40..4deb4e998 100755 --- a/radio/src/thirdparty/libopenui/src/static.cpp +++ b/radio/src/thirdparty/libopenui/src/static.cpp @@ -37,13 +37,13 @@ void StaticText::paint(BitmapBuffer * dc) coord_t y = (textFlags & VCENTERED) ? (rect.h - getFontHeight(textFlags)) / 2 : FIELD_PADDING_TOP; auto start = text.c_str(); - auto nextline = strchr(start, '\n'); + auto nextline = findNextLine(start); if (nextline) { auto current = start; do { dc->drawText(x, y, text.substr(current - start, nextline - current).c_str(), textFlags); current = nextline + 1; - nextline = strchr(current, '\n'); + nextline = findNextLine(current); y += getFontHeight(textFlags) + 2; } while (nextline); dc->drawText(x, y, current, textFlags); @@ -51,5 +51,4 @@ void StaticText::paint(BitmapBuffer * dc) else { dc->drawText(x, y, start, textFlags); } - }