From a91c85d92ef34e6e957c161d5dd0f002e670d1fd Mon Sep 17 00:00:00 2001 From: Dav999-v Date: Thu, 23 Feb 2023 04:52:56 +0100 Subject: [PATCH] Fix UTF-8 handling in next_wrap Finally this FIXME can be removed! --- desktop_version/src/Font.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/desktop_version/src/Font.cpp b/desktop_version/src/Font.cpp index 3ed8f19a..5f3e4712 100644 --- a/desktop_version/src/Font.cpp +++ b/desktop_version/src/Font.cpp @@ -789,14 +789,10 @@ static bool next_wrap( while (true) { - /* FIXME: This only checks one byte, not multiple! */ - if ((str[idx] & 0xC0) == 0x80) - { - /* Skip continuation byte. */ - goto next; - } + uint8_t codepoint_nbytes; + uint32_t codepoint = UTF8_peek_next(&str[idx], &codepoint_nbytes); - switch (str[idx]) + switch (codepoint) { case ' ': if (loc::get_langmeta()->autowordwrap) @@ -813,7 +809,7 @@ static bool next_wrap( return true; } - linewidth += get_advance(f, str[idx]); + linewidth += get_advance(f, codepoint); if (linewidth > maxwidth) { @@ -831,10 +827,9 @@ static bool next_wrap( return true; } -next: - idx += 1; - *start += 1; - *len += 1; + idx += codepoint_nbytes; + *start += codepoint_nbytes; + *len += codepoint_nbytes; } }