Tk Source Code

Artifact [7316b627]
Login

Artifact 7316b627f2ab825af58c3f27f881658b640cdf921aa2afff5f23148453147c39:

Attachment "Patch1.txt" to ticket [adb63528] added by fvogel 2022-06-12 20:04:40.
Index: macosx/tkMacOSXFont.c
==================================================================
--- macosx/tkMacOSXFont.c
+++ macosx/tkMacOSXFont.c
@@ -908,10 +908,11 @@
     CTLineRef line;
     CGFloat offset = 0;
     CFIndex index;
     double width;
     int length, fit;
+    int trimmed = 0;

     if (rangeStart < 0 || rangeLength <= 0 ||
            rangeStart + rangeLength > numBytes ||
            (maxLength == 0 && !(flags & TK_AT_LEAST_ONE))) {
        *lengthPtr = 0;
@@ -970,10 +971,11 @@
        cs = (index <= len && (flags & TK_WHOLE_WORDS)) ?
                whitespaceCharacterSet : lineendingCharacterSet;
        while (index > start &&
                [cs characterIsMember:[string characterAtIndex:(index - 1)]]) {
            index--;
+            trimmed++;
        }

         /*
          * If there is no line breakpoint in the source string between its
          * start and the index position that fits in maxWidth, then
@@ -1030,11 +1032,11 @@
     }
     CFRelease(typesetter);
     [attributedString release];
     [string release];
     length = ceil(width - offset);
-    fit = (TkUtfAtIndex(source, index) - source) - rangeStart;
+    fit = (TkUtfAtIndex(source, index) - source) + trimmed - rangeStart;
 done:
 #ifdef TK_MAC_DEBUG_FONTS
     TkMacOSXDbgMsg("measure: source=\"%s\" range=\"%.*s\" maxLength=%d "
            "flags='%s%s%s%s' -> width=%d bytesFit=%d\n", source, rangeLength,
            source+rangeStart, maxLength,