From e112662cca542c5a8dd957d115d465451a20ca79 Mon Sep 17 00:00:00 2001 From: fvogel Date: Sun, 7 Oct 2018 19:40:03 +0000 Subject: Re-integrate the tentative fixes for font-24.5 ([94cfd2f6] for macOS and [1235434d] for Linux) in the present bugfix branch. --- macosx/tkMacOSXFont.c | 4 ++++ unix/tkUnixRFont.c | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c index d92e6b4..301659e 100644 --- a/macosx/tkMacOSXFont.c +++ b/macosx/tkMacOSXFont.c @@ -863,6 +863,10 @@ TkpMeasureCharsInContext( } cs = (index <= len && (flags & TK_WHOLE_WORDS)) ? whitespaceCharacterSet : lineendingCharacterSet; + while ((index > start) && (index < len) && (flags & TK_WHOLE_WORDS) + && ![cs characterIsMember:[string characterAtIndex:index]]) { + index--; + } while (index > start && [cs characterIsMember:[string characterAtIndex:(index - 1)]]) { index--; diff --git a/unix/tkUnixRFont.c b/unix/tkUnixRFont.c index 8e0ce55..70aebfa 100644 --- a/unix/tkUnixRFont.c +++ b/unix/tkUnixRFont.c @@ -711,9 +711,19 @@ Tk_MeasureChars( (flags & TK_AT_LEAST_ONE && curByte == 0)) { curX = newX; curByte = newByte; - } else if (flags & TK_WHOLE_WORDS && termX != 0) { - curX = termX; - curByte = termByte; + } else if (flags & TK_WHOLE_WORDS) { + if ((flags & TK_AT_LEAST_ONE) && (termX == 0)) { + /* + * No space was seen before reaching the right + * of the allotted maxLength space, i.e. no word + * boundary. Return the string that fills the + * allotted space, without overfill. + * curX and curByte are already the right ones: + */ + } else { + curX = termX; + curByte = termByte; + } } break; } -- cgit v0.12 From ca239ce8308e98ef22024b83914e5c7e51cbdca8 Mon Sep 17 00:00:00 2001 From: fvogel Date: Sun, 7 Oct 2018 22:14:36 +0000 Subject: Fix [6437e8d00d] (font-24.5 test fails on macOS and Linux) without regression in canvText test. This is the fix for macOS. --- macosx/tkMacOSXFont.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c index 301659e..2c5316c 100644 --- a/macosx/tkMacOSXFont.c +++ b/macosx/tkMacOSXFont.c @@ -863,14 +863,14 @@ TkpMeasureCharsInContext( } cs = (index <= len && (flags & TK_WHOLE_WORDS)) ? whitespaceCharacterSet : lineendingCharacterSet; - while ((index > start) && (index < len) && (flags & TK_WHOLE_WORDS) - && ![cs characterIsMember:[string characterAtIndex:index]]) { - index--; - } while (index > start && [cs characterIsMember:[string characterAtIndex:(index - 1)]]) { index--; } + if ((index >= start) && (index < len) && (flags & TK_WHOLE_WORDS) && !(flags & TK_AT_LEAST_ONE) + && ![cs characterIsMember:[string characterAtIndex:index]]) { + index = start; + } if (index <= start && (flags & TK_AT_LEAST_ONE)) { index = start + 1; } -- cgit v0.12 From 263a20f6ac418d782304d64fe03f3c489ed5dff3 Mon Sep 17 00:00:00 2001 From: fvogel Date: Mon, 8 Oct 2018 20:32:35 +0000 Subject: Add explanatory comments in TkpMeasureCharsInContext() on macOS. --- macosx/tkMacOSXFont.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c index 2c5316c..757daf9 100644 --- a/macosx/tkMacOSXFont.c +++ b/macosx/tkMacOSXFont.c @@ -851,6 +851,10 @@ TkpMeasureCharsInContext( double maxWidth = maxLength + offset; NSCharacterSet *cs; + /* + * Get a line breakpoint in the source string. + */ + index = start; if (flags & TK_WHOLE_WORDS) { index = CTTypesetterSuggestLineBreak(typesetter, start, maxWidth); @@ -861,19 +865,43 @@ TkpMeasureCharsInContext( if (index <= start && !(flags & TK_WHOLE_WORDS)) { index = CTTypesetterSuggestClusterBreak(typesetter, start, maxWidth); } + + /* + * Trim right whitespace/lineending characters. + */ + cs = (index <= len && (flags & TK_WHOLE_WORDS)) ? whitespaceCharacterSet : lineendingCharacterSet; while (index > start && [cs characterIsMember:[string characterAtIndex:(index - 1)]]) { index--; } - if ((index >= start) && (index < len) && (flags & TK_WHOLE_WORDS) && !(flags & TK_AT_LEAST_ONE) - && ![cs characterIsMember:[string characterAtIndex:index]]) { + + /* + * If there is no line breakpoint in the source string between + * its start and the index position that fits in maxWidth, then + * CTTypesetterSuggestLineBreak() returns that very last index. + * However if the TK_WHOLE_WORDS flag is set, we want to break + * at a word boundary. In this situation, unless TK_AT_LEAST_ONE + * is set, we must report that zero chars actually fit (in other + * words the smallest word of the source string is still larger + * than maxWidth). + */ + + if ((index >= start) && (index < len) && + (flags & TK_WHOLE_WORDS) && !(flags & TK_AT_LEAST_ONE) && + ![cs characterIsMember:[string characterAtIndex:index]]) { index = start; } + if (index <= start && (flags & TK_AT_LEAST_ONE)) { index = start + 1; } + + /* + * Now measure the string width in pixels. + */ + if (index > 0) { range.length = index; line = CTTypesetterCreateLine(typesetter, range); -- cgit v0.12