From 3f8333400ffa85d6fe868670c3ef8ecacd3bc1c2 Mon Sep 17 00:00:00 2001 From: Dav999 Date: Thu, 4 Jan 2024 22:19:50 +0100 Subject: [PATCH] Base text box padding/centering on font width instead of codepoints Stuff like centertext="1" and padtowidth="264" in cutscene translations looked wrong in RTL mode, both with Arabic and English text. For Arabic text, I could easily fix the problem by not counting the number of codepoints (and assuming they all have the same glyph width), but by instead taking the width of the string as reported for the font, and dividing it by the glyph width. This leaves English text still looking weird in RTL mode. But this shouldn't be a problem either: the Arabic translations will probably be in Arabic (where the problem doesn't happen), and I can get English text to show up fine by wrapping it in U+2066 LEFT-TO-RIGHT ISOLATE and U+2069 POP DIRECTIONAL ISOLATE. So it looks like an inherent quirk of bidi, that translators familiar with bidi can easily grasp and fix. This is main-game only functionality, so it shouldn't break existing custom levels. We should just make sure textboxes in other languages aren't broken, but from my testing, it's completely fine - in fact, it should've improved if it was broken. --- desktop_version/src/Textbox.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/desktop_version/src/Textbox.cpp b/desktop_version/src/Textbox.cpp index a538f35f..3d6d1abf 100644 --- a/desktop_version/src/Textbox.cpp +++ b/desktop_version/src/Textbox.cpp @@ -165,7 +165,7 @@ void textboxclass::padtowidth(size_t new_w) size_t chars_w = SDL_max(w-16, new_w) / glyph_w; for (size_t iter = 0; iter < lines.size(); iter++) { - size_t n_glyphs = UTF8_total_codepoints(lines[iter].c_str()); + size_t n_glyphs = font::len(print_flags, lines[iter].c_str()) / glyph_w; signed int padding_needed = chars_w - n_glyphs; if (padding_needed < 0) {