[PATCH 2/2] WINGs: avoid splitting UTF-8 characters when wrapping

Skip to first unread message

david.m...@gmail.com

unread,
Apr 4, 2026, 2:34:58 PM (2 days ago) Apr 4
to Window Maker Development
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 */
--
2.43.0
0002-WINGs-avoid-splitting-UTF-8-characters-when-wrapping.patch
Reply all
Reply to author
Forward
0 new messages