summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXFont.c
diff options
context:
space:
mode:
authorfvogel <fvogelnew1@free.fr>2018-10-08 20:32:35 (GMT)
committerfvogel <fvogelnew1@free.fr>2018-10-08 20:32:35 (GMT)
commit263a20f6ac418d782304d64fe03f3c489ed5dff3 (patch)
tree0150d59f81411bdb62e2a03cab815eb4f972b21b /macosx/tkMacOSXFont.c
parentca239ce8308e98ef22024b83914e5c7e51cbdca8 (diff)
downloadtk-263a20f6ac418d782304d64fe03f3c489ed5dff3.zip
tk-263a20f6ac418d782304d64fe03f3c489ed5dff3.tar.gz
tk-263a20f6ac418d782304d64fe03f3c489ed5dff3.tar.bz2
Add explanatory comments in TkpMeasureCharsInContext() on macOS.
Diffstat (limited to 'macosx/tkMacOSXFont.c')
-rw-r--r--macosx/tkMacOSXFont.c32
1 files 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);