Don't truncate the lines on chinese chars
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -79,3 +79,14 @@ inline std::string TEXT_AT_INDEX(const char * val, uint8_t idx)
|
||||
return std::string(start, min<uint8_t>(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;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user