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.
This commit is contained in:
Dav999 2024-01-04 22:19:50 +01:00 committed by Misa Elizabeth Kai
parent 25bdf0866a
commit 3f8333400f
1 changed files with 1 additions and 1 deletions

View File

@ -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)
{