summaryrefslogtreecommitdiffstats
path: root/generic/tkTextDisp.c
diff options
context:
space:
mode:
authorfvogel <fvogelnew1@free.fr>2014-12-28 18:00:53 (GMT)
committerfvogel <fvogelnew1@free.fr>2014-12-28 18:00:53 (GMT)
commit00c90a36f723fb24cce340db3aaadeac2d26c23b (patch)
treeb81d342878b82f52d74a31560926c46c13e9efe7 /generic/tkTextDisp.c
parentc496046c21dec2ceef5e03a5205ea6d0cc0fde9f (diff)
downloadtk-00c90a36f723fb24cce340db3aaadeac2d26c23b.zip
tk-00c90a36f723fb24cce340db3aaadeac2d26c23b.tar.gz
tk-00c90a36f723fb24cce340db3aaadeac2d26c23b.tar.bz2
Further fixed text count -ypixels with indices in elided lines, [30d6b995dc] was not always correct
Diffstat (limited to 'generic/tkTextDisp.c')
-rw-r--r--generic/tkTextDisp.c44
1 files changed, 30 insertions, 14 deletions
diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c
index ae9c341..be77550 100644
--- a/generic/tkTextDisp.c
+++ b/generic/tkTextDisp.c
@@ -3603,29 +3603,44 @@ TkTextIndexYPixels(
{
int pixelHeight;
TkTextIndex index;
+ int alreadyStartOfLine = 1;
+
+ /*
+ * Find the index denoting the closest position being at the same time
+ * the start of a logical line above indexPtr and the start of a display
+ * line.
+ */
index = *indexPtr;
- TkTextFindDisplayLineEnd(textPtr, &index, 0, NULL);
+ while (1) {
+ TkTextFindDisplayLineEnd(textPtr, &index, 0, NULL);
+ if (index.byteIndex == 0) {
+ break;
+ }
+ TkTextIndexBackBytes(textPtr, &index, 1, &index);
+ alreadyStartOfLine = 0;
+ }
pixelHeight = TkBTreePixelsTo(textPtr, index.linePtr);
/*
- * Iterate through all display-lines corresponding to the single logical
- * line belonging to index, adding up the pixel height of each such
- * display line as we go along, until we go past 'indexPtr'.
+ * Shortcut to avoid layout of a superfluous display line. We know there
+ * is nothing more to add up to the height since the index we were given
+ * was already the start of a logical line.
*/
- if (index.byteIndex == 0) {
- return pixelHeight;
+ if (alreadyStartOfLine) {
+ return pixelHeight;
}
- index.tree = textPtr->sharedTextPtr->tree;
- index.linePtr = indexPtr->linePtr;
- index.byteIndex = 0;
- index.textPtr = NULL;
+ /*
+ * Iterate through display lines, starting at the logical line belonging
+ * to index, adding up the pixel height of each such display line as we
+ * go along, until we go past 'indexPtr'.
+ */
while (1) {
- int bytes, height;
+ int bytes, height, compare;
/*
* Currently this call doesn't have many side-effects. However, if in
@@ -3637,9 +3652,10 @@ TkTextIndexYPixels(
height = CalculateDisplayLineHeight(textPtr, &index, &bytes, NULL);
- index.byteIndex += bytes;
+ TkTextIndexForwBytes(textPtr, &index, bytes, &index);
- if (index.byteIndex > indexPtr->byteIndex) {
+ compare = TkTextIndexCmp(&index,indexPtr);
+ if (compare > 0) {
return pixelHeight;
}
@@ -3647,7 +3663,7 @@ TkTextIndexYPixels(
pixelHeight += height;
}
- if (index.byteIndex == indexPtr->byteIndex) {
+ if (compare == 0) {
return pixelHeight;
}
}