From fa49b7c0032f83a40f52ddc4de6b6b9a4eb76533 Mon Sep 17 00:00:00 2001 From: David Maciejak Date: Sat, 4 Apr 2026 14:30:05 -0400 Subject: [PATCH] WINGs: avoid splitting UTF-8 characters when wrapping text This patch is to split UTF-8 word by characters and not bytes. Issue reported at https://github.com/window-maker/wmaker/issues/65 --- WINGs/wmisc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/WINGs/wmisc.c b/WINGs/wmisc.c index ba4c8a6a..e14ad176 100644 --- a/WINGs/wmisc.c +++ b/WINGs/wmisc.c @@ -122,11 +122,14 @@ static int fitText(const char *text, WMFont * font, int width, int wrap) word1 = word2; } - for (i = word1; i < word2; i++) { - w = WMWidthOfString(font, text, i); - if (w > width) { + /* Advance character by character (not byte by byte) */ + i = word1; + while (i < word2) { + int next_i = i + oneUTF8CharForward(text + i, word2 - i); + w = WMWidthOfString(font, text, next_i); + if (w > width) break; - } + i = next_i; } /* keep words complete if possible */