From 96fa932a8a6981b27b7a730116d375badf452abf Mon Sep 17 00:00:00 2001 From: Dav999 Date: Fri, 5 Jan 2024 02:48:45 +0100 Subject: [PATCH] Don't pass newline characters to bidi algorithm If you copy-paste a newline character where it's not interpreted, such as in a level title, the print function wouldn't treat it any special. font::print_wrap() would, but that's not used here. However, now that bidi is involved, the newline is passed straight to SheenBidi which interprets it as a new line (which would need a new SBLine to be created, or maybe even a new SBParagraph if there's two). All while we're still treating it as a single line. This means the text would just stop being displayed after the first newline. This is now fixed by treating all newlines as spaces. --- desktop_version/src/FontBidi.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/desktop_version/src/FontBidi.cpp b/desktop_version/src/FontBidi.cpp index 582bc032..5c4d948d 100644 --- a/desktop_version/src/FontBidi.cpp +++ b/desktop_version/src/FontBidi.cpp @@ -324,9 +324,16 @@ const char* bidi_transform(const bool rtl, const char* text) int n_codepoints = 0; const char* text_ptr = text; - while ((utf32_in[n_codepoints] = UTF8_next(&text_ptr))) + uint32_t codepoint; + while ((codepoint = UTF8_next(&text_ptr))) { - n_codepoints++; + if (codepoint == '\r' || codepoint == '\n') + { + // Don't treat newlines in font::print differently in bidi + codepoint = ' '; + } + + utf32_in[n_codepoints++] = codepoint; if (n_codepoints >= 1023) {