summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorvincentdarley <vincentdarley>2003-11-21 18:51:18 (GMT)
committervincentdarley <vincentdarley>2003-11-21 18:51:18 (GMT)
commit85439d568d2731ed385680654bbc6980c725539e (patch)
treeb496eb8e8536a2cf8b8507d74d0a2f3e4afe60eb /generic
parent676bd9c8a05ae92ee4832067b4065beba76b2122 (diff)
downloadtk-85439d568d2731ed385680654bbc6980c725539e.zip
tk-85439d568d2731ed385680654bbc6980c725539e.tar.gz
tk-85439d568d2731ed385680654bbc6980c725539e.tar.bz2
correct handling of interpolated tabs using fractional pixel widths
Diffstat (limited to 'generic')
-rw-r--r--generic/tkText.c22
-rw-r--r--generic/tkText.h8
-rw-r--r--generic/tkTextDisp.c35
3 files changed, 40 insertions, 25 deletions
diff --git a/generic/tkText.c b/generic/tkText.c
index 133d88d..c5c8baa 100644
--- a/generic/tkText.c
+++ b/generic/tkText.c
@@ -14,7 +14,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkText.c,v 1.44 2003/11/15 02:33:50 vincentdarley Exp $
+ * RCS: @(#) $Id: tkText.c,v 1.45 2003/11/21 18:51:18 vincentdarley Exp $
*/
#include "default.h"
@@ -3310,6 +3310,7 @@ TkTextGetTabs(interp, tkwin, stringPtr)
TkTextTabArray *tabArrayPtr;
TkTextTab *tabPtr;
Tcl_UniChar ch;
+ double prevStop, lastStop;
/* Map these strings to TkTextTabAlign values */
@@ -3342,6 +3343,8 @@ TkTextGetTabs(interp, tkwin, stringPtr)
tabArrayPtr = (TkTextTabArray *) ckalloc((unsigned)
(sizeof(TkTextTabArray) + (count-1)*sizeof(TkTextTab)));
tabArrayPtr->numTabs = 0;
+ prevStop = 0.0;
+ lastStop = 0.0;
for (i = 0, tabPtr = &tabArrayPtr->tabs[0]; i < objc; i++, tabPtr++) {
int index;
@@ -3349,6 +3352,14 @@ TkTextGetTabs(interp, tkwin, stringPtr)
!= TCL_OK) {
goto error;
}
+
+ prevStop = lastStop;
+ if (Tk_GetMMFromObj(interp, tkwin, objv[i], &lastStop) != TCL_OK) {
+ goto error;
+ }
+ lastStop *= WidthOfScreen(Tk_Screen(tkwin));
+ lastStop /= WidthMMOfScreen(Tk_Screen(tkwin));
+
tabArrayPtr->numTabs++;
/*
@@ -3373,6 +3384,15 @@ TkTextGetTabs(interp, tkwin, stringPtr)
}
tabPtr->alignment = ((TkTextTabAlign)index);
}
+
+ /*
+ * For when we need to interpolate tab stops, store
+ * these two so we know the tab stop size to very
+ * high precision.
+ */
+ tabArrayPtr->lastTab = lastStop;
+ tabArrayPtr->tabIncrement = lastStop - prevStop;
+
return tabArrayPtr;
error:
diff --git a/generic/tkText.h b/generic/tkText.h
index ee19ad2..bf79bc7 100644
--- a/generic/tkText.h
+++ b/generic/tkText.h
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkText.h,v 1.21 2003/11/15 02:33:50 vincentdarley Exp $
+ * RCS: @(#) $Id: tkText.h,v 1.22 2003/11/21 18:51:18 vincentdarley Exp $
*/
#ifndef _TKTEXT
@@ -474,6 +474,12 @@ typedef struct TkTextTab {
typedef struct TkTextTabArray {
int numTabs; /* Number of tab stops. */
+ double lastTab; /* The accurate fractional pixel
+ * position of the last tab. */
+ double tabIncrement; /* The accurate fractional pixel
+ * increment between interpolated
+ * tabs we have to create when
+ * we exceed numTabs. */
TkTextTab tabs[1]; /* Array of tabs. The actual size
* will be numTabs. THIS FIELD MUST
* BE THE LAST IN THE STRUCTURE. */
diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c
index 623570a..b218a79 100644
--- a/generic/tkTextDisp.c
+++ b/generic/tkTextDisp.c
@@ -13,7 +13,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkTextDisp.c,v 1.34 2003/11/21 17:29:13 vincentdarley Exp $
+ * RCS: @(#) $Id: tkTextDisp.c,v 1.35 2003/11/21 18:51:18 vincentdarley Exp $
*/
#include "tkPort.h"
@@ -6596,7 +6596,7 @@ AdjustForTab(textPtr, tabArrayPtr, index, chunkPtr)
int x, desired, delta, width, decimal, i, gotDigit;
TkTextDispChunk *chunkPtr2, *decimalChunkPtr;
CharInfo *ciPtr;
- int tabX, prev, spaceWidth;
+ int tabX, spaceWidth;
char *p;
TkTextTabAlign alignment;
@@ -6633,15 +6633,10 @@ AdjustForTab(textPtr, tabArrayPtr, index, chunkPtr)
* from the last two tab positions.
*/
- if (tabArrayPtr->numTabs > 1) {
- prev = tabArrayPtr->tabs[tabArrayPtr->numTabs-2].location;
- } else {
- prev = 0;
- }
+ tabX = (int) (tabArrayPtr->lastTab
+ + (index + 1 - tabArrayPtr->numTabs)
+ * tabArrayPtr->tabIncrement + 0.5);
alignment = tabArrayPtr->tabs[tabArrayPtr->numTabs-1].alignment;
- tabX = tabArrayPtr->tabs[tabArrayPtr->numTabs-1].location
- + (index + 1 - tabArrayPtr->numTabs)
- * (tabArrayPtr->tabs[tabArrayPtr->numTabs-1].location - prev);
}
if (alignment == LEFT) {
@@ -6780,7 +6775,7 @@ SizeOfTab(textPtr, tabArrayPtr, indexPtr, x, maxX)
int maxX; /* X-location of pixel just past the
* right edge of the line. */
{
- int tabX, prev, result, index, spaceWidth;
+ int tabX, result, index, spaceWidth;
TkTextTabAlign alignment;
index = *indexPtr;
@@ -6796,7 +6791,7 @@ SizeOfTab(textPtr, tabArrayPtr, indexPtr, x, maxX)
do {
/*
- * We were given the count before this tabs, so increment it
+ * We were given the count before this tab, so increment it
* first.
*/
index++;
@@ -6805,18 +6800,12 @@ SizeOfTab(textPtr, tabArrayPtr, indexPtr, x, maxX)
alignment = tabArrayPtr->tabs[index].alignment;
} else {
/*
- * Ran out of tab stops; compute a tab position by extrapolating
- * from the last two tab positions.
+ * Ran out of tab stops; compute a tab position by
+ * extrapolating.
*/
-
- if (tabArrayPtr->numTabs > 1) {
- prev = tabArrayPtr->tabs[tabArrayPtr->numTabs-2].location;
- } else {
- prev = 0;
- }
- tabX = tabArrayPtr->tabs[tabArrayPtr->numTabs-1].location
- + (index + 1 - tabArrayPtr->numTabs)
- * (tabArrayPtr->tabs[tabArrayPtr->numTabs-1].location - prev);
+ tabX = (int) (tabArrayPtr->lastTab
+ + (index + 1 - tabArrayPtr->numTabs)
+ * tabArrayPtr->tabIncrement + 0.5);
alignment = tabArrayPtr->tabs[tabArrayPtr->numTabs-1].alignment;
}
/*