Tk Source Code

Attachment Details
Login
Overview

Artifact ID: 5520d14407248c1bd7addc03fe06d50f521b4426bbb41950ffccc5270213a261
Ticket: adb6352846319ff0ba4761bb46391c5ea284fd7c
Date: 2022-06-12 20:04:40
User: fvogel
Artifact Attached: 7316b627f2ab825af58c3f27f881658b640cdf921aa2afff5f23148453147c39
Filename:Patch1.txt
Description:
Content:
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,