summaryrefslogtreecommitdiffstats
path: root/generic/tkCanvText.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tkCanvText.c')
-rw-r--r--generic/tkCanvText.c513
1 files changed, 187 insertions, 326 deletions
diff --git a/generic/tkCanvText.c b/generic/tkCanvText.c
index eb8dfe3..24c3c7f 100644
--- a/generic/tkCanvText.c
+++ b/generic/tkCanvText.c
@@ -10,6 +10,7 @@
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
+#include <stdio.h>
#include "tkInt.h"
#include "tkCanvas.h"
#include "default.h"
@@ -54,8 +55,6 @@ typedef struct TextItem {
* means no word-wrap. */
int underline; /* Index of character to put underline beneath
* or -1 for no underlining. */
- double angle; /* What angle, in degrees, to draw the text
- * at. */
/*
* Fields whose values are derived from the current values of the
@@ -65,69 +64,70 @@ typedef struct TextItem {
int numChars; /* Length of text in characters. */
int numBytes; /* Length of text in bytes. */
Tk_TextLayout textLayout; /* Cached text layout information. */
- int actualWidth; /* Width of text as computed. Used to make
- * selections of wrapped text display
- * right. */
- double drawOrigin[2]; /* Where we start drawing from. */
+ int leftEdge; /* Pixel location of the left edge of the text
+ * item; where the left border of the text
+ * layout is drawn. */
+ int rightEdge; /* Pixel just to right of right edge of area
+ * of text item. Used for selecting up to end
+ * of line. */
GC gc; /* Graphics context for drawing text. */
GC selTextGC; /* Graphics context for selected text. */
GC cursorOffGC; /* If not None, this gives a graphics context
* to use to draw the insertion cursor when
* it's off. Used if the selection and
* insertion cursor colors are the same. */
- double sine; /* Sine of angle field. */
- double cosine; /* Cosine of angle field. */
} TextItem;
/*
* Information used for parsing configuration specs:
*/
-static const Tk_CustomOption stateOption = {
- TkStateParseProc, TkStatePrintProc, INT2PTR(2)
+static Tk_CustomOption stateOption = {
+ (Tk_OptionParseProc *) TkStateParseProc,
+ TkStatePrintProc, (ClientData) 2
};
-static const Tk_CustomOption tagsOption = {
- Tk_CanvasTagsParseProc, Tk_CanvasTagsPrintProc, NULL
+static Tk_CustomOption tagsOption = {
+ (Tk_OptionParseProc *) Tk_CanvasTagsParseProc,
+ Tk_CanvasTagsPrintProc, (ClientData) NULL
};
-static const Tk_CustomOption offsetOption = {
- TkOffsetParseProc, TkOffsetPrintProc, INT2PTR(TK_OFFSET_RELATIVE)
+static Tk_CustomOption offsetOption = {
+ (Tk_OptionParseProc *) TkOffsetParseProc,
+ TkOffsetPrintProc, (ClientData) (TK_OFFSET_RELATIVE)
};
-static const Tk_ConfigSpec configSpecs[] = {
+static Tk_ConfigSpec configSpecs[] = {
{TK_CONFIG_COLOR, "-activefill", NULL, NULL,
- NULL, Tk_Offset(TextItem, activeColor), TK_CONFIG_NULL_OK, NULL},
+ NULL, Tk_Offset(TextItem, activeColor), TK_CONFIG_NULL_OK},
{TK_CONFIG_BITMAP, "-activestipple", NULL, NULL,
- NULL, Tk_Offset(TextItem, activeStipple), TK_CONFIG_NULL_OK, NULL},
+ NULL, Tk_Offset(TextItem, activeStipple), TK_CONFIG_NULL_OK},
{TK_CONFIG_ANCHOR, "-anchor", NULL, NULL,
- "center", Tk_Offset(TextItem, anchor), TK_CONFIG_DONT_SET_DEFAULT, NULL},
- {TK_CONFIG_DOUBLE, "-angle", NULL, NULL,
- "0.0", Tk_Offset(TextItem, angle), TK_CONFIG_DONT_SET_DEFAULT, NULL},
+ "center", Tk_Offset(TextItem, anchor), TK_CONFIG_DONT_SET_DEFAULT},
{TK_CONFIG_COLOR, "-disabledfill", NULL, NULL,
- NULL, Tk_Offset(TextItem, disabledColor), TK_CONFIG_NULL_OK, NULL},
+ NULL, Tk_Offset(TextItem, disabledColor), TK_CONFIG_NULL_OK},
{TK_CONFIG_BITMAP, "-disabledstipple", NULL, NULL,
- NULL, Tk_Offset(TextItem, disabledStipple), TK_CONFIG_NULL_OK, NULL},
+ NULL, Tk_Offset(TextItem, disabledStipple), TK_CONFIG_NULL_OK},
{TK_CONFIG_COLOR, "-fill", NULL, NULL,
- "black", Tk_Offset(TextItem, color), TK_CONFIG_NULL_OK, NULL},
+ "black", Tk_Offset(TextItem, color), TK_CONFIG_NULL_OK},
{TK_CONFIG_FONT, "-font", NULL, NULL,
- DEF_CANVTEXT_FONT, Tk_Offset(TextItem, tkfont), 0, NULL},
+ DEF_CANVTEXT_FONT, Tk_Offset(TextItem, tkfont), 0},
{TK_CONFIG_JUSTIFY, "-justify", NULL, NULL,
- "left", Tk_Offset(TextItem, justify), TK_CONFIG_DONT_SET_DEFAULT, NULL},
+ "left", Tk_Offset(TextItem, justify), TK_CONFIG_DONT_SET_DEFAULT},
{TK_CONFIG_CUSTOM, "-offset", NULL, NULL,
"0,0", Tk_Offset(TextItem, tsoffset),
TK_CONFIG_DONT_SET_DEFAULT, &offsetOption},
{TK_CONFIG_CUSTOM, "-state", NULL, NULL,
NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, &stateOption},
{TK_CONFIG_BITMAP, "-stipple", NULL, NULL,
- NULL, Tk_Offset(TextItem, stipple), TK_CONFIG_NULL_OK, NULL},
+ NULL, Tk_Offset(TextItem, stipple), TK_CONFIG_NULL_OK},
{TK_CONFIG_CUSTOM, "-tags", NULL, NULL,
NULL, 0, TK_CONFIG_NULL_OK, &tagsOption},
{TK_CONFIG_STRING, "-text", NULL, NULL,
- "", Tk_Offset(TextItem, text), 0, NULL},
+ "", Tk_Offset(TextItem, text), 0},
{TK_CONFIG_INT, "-underline", NULL, NULL,
- "-1", Tk_Offset(TextItem, underline), 0, NULL},
+ "-1", Tk_Offset(TextItem, underline), 0},
{TK_CONFIG_PIXELS, "-width", NULL, NULL,
- "0", Tk_Offset(TextItem, width), TK_CONFIG_DONT_SET_DEFAULT, NULL},
- {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0, NULL}
+ "0", Tk_Offset(TextItem, width), TK_CONFIG_DONT_SET_DEFAULT},
+ {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0}
};
/*
@@ -137,10 +137,10 @@ static const Tk_ConfigSpec configSpecs[] = {
static void ComputeTextBbox(Tk_Canvas canvas, TextItem *textPtr);
static int ConfigureText(Tcl_Interp *interp,
Tk_Canvas canvas, Tk_Item *itemPtr, int argc,
- Tcl_Obj *const objv[], int flags);
+ Tcl_Obj *CONST objv[], int flags);
static int CreateText(Tcl_Interp *interp,
Tk_Canvas canvas, struct Tk_Item *itemPtr,
- int argc, Tcl_Obj *const objv[]);
+ int argc, Tcl_Obj *CONST objv[]);
static void DeleteText(Tk_Canvas canvas,
Tk_Item *itemPtr, Display *display);
static void DisplayCanvText(Tk_Canvas canvas,
@@ -159,11 +159,11 @@ static void SetTextCursor(Tk_Canvas canvas,
Tk_Item *itemPtr, int index);
static int TextCoords(Tcl_Interp *interp,
Tk_Canvas canvas, Tk_Item *itemPtr,
- int argc, Tcl_Obj *const objv[]);
+ int argc, Tcl_Obj *CONST objv[]);
static void TextDeleteChars(Tk_Canvas canvas,
Tk_Item *itemPtr, int first, int last);
static void TextInsert(Tk_Canvas canvas,
- Tk_Item *itemPtr, int beforeThis, Tcl_Obj *obj);
+ Tk_Item *itemPtr, int beforeThis, char *string);
static int TextToArea(Tk_Canvas canvas,
Tk_Item *itemPtr, double *rectPtr);
static double TextToPoint(Tk_Canvas canvas,
@@ -193,16 +193,13 @@ Tk_ItemType tkTextType = {
TextToPostscript, /* postscriptProc */
ScaleText, /* scaleProc */
TranslateText, /* translateProc */
- GetTextIndex, /* indexProc */
+ (Tk_ItemIndexProc *) GetTextIndex,/* indexProc */
SetTextCursor, /* icursorProc */
GetSelText, /* selectionProc */
TextInsert, /* insertProc */
TextDeleteChars, /* dTextProc */
NULL, /* nextPtr */
- NULL, 0, NULL, NULL
};
-
-#define ROUND(d) ((int) floor((d) + 0.5))
/*
*--------------------------------------------------------------
@@ -229,13 +226,13 @@ CreateText(
Tk_Item *itemPtr, /* Record to hold new item; header has been
* initialized by caller. */
int objc, /* Number of arguments in objv. */
- Tcl_Obj *const objv[]) /* Arguments describing rectangle. */
+ Tcl_Obj *CONST objv[]) /* Arguments describing rectangle. */
{
TextItem *textPtr = (TextItem *) itemPtr;
int i;
if (objc == 0) {
- Tcl_Panic("canvas did not pass any coords");
+ Tcl_Panic("canvas did not pass any coords\n");
}
/*
@@ -262,18 +259,15 @@ CreateText(
textPtr->text = NULL;
textPtr->width = 0;
textPtr->underline = -1;
- textPtr->angle = 0.0;
textPtr->numChars = 0;
textPtr->numBytes = 0;
textPtr->textLayout = NULL;
- textPtr->actualWidth = 0;
- textPtr->drawOrigin[0] = textPtr->drawOrigin[1] = 0.0;
+ textPtr->leftEdge = 0;
+ textPtr->rightEdge = 0;
textPtr->gc = None;
textPtr->selTextGC = None;
textPtr->cursorOffGC = None;
- textPtr->sine = 0.0;
- textPtr->cosine = 1.0;
/*
* Process the arguments to fill in the item record. Only 1 (list) or 2 (x
@@ -283,7 +277,7 @@ CreateText(
if (objc == 1) {
i = 1;
} else {
- const char *arg = Tcl_GetString(objv[1]);
+ char *arg = Tcl_GetString(objv[1]);
i = 2;
if ((arg[0] == '-') && (arg[1] >= 'a') && (arg[1] <= 'z')) {
@@ -326,44 +320,45 @@ TextCoords(
Tk_Item *itemPtr, /* Item whose coordinates are to be read or
* modified. */
int objc, /* Number of coordinates supplied in objv. */
- Tcl_Obj *const objv[]) /* Array of coordinates: x1, y1, x2, y2, ... */
+ Tcl_Obj *CONST objv[]) /* Array of coordinates: x1, y1, x2, y2, ... */
{
TextItem *textPtr = (TextItem *) itemPtr;
if (objc == 0) {
Tcl_Obj *obj = Tcl_NewObj();
- Tcl_Obj *subobj = Tcl_NewDoubleObj(textPtr->x);
+ Tcl_Obj *subobj = Tcl_NewDoubleObj(textPtr->x);
Tcl_ListObjAppendElement(interp, obj, subobj);
subobj = Tcl_NewDoubleObj(textPtr->y);
Tcl_ListObjAppendElement(interp, obj, subobj);
Tcl_SetObjResult(interp, obj);
- return TCL_OK;
- } else if (objc > 2) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "wrong # coordinates: expected 0 or 2, got %d", objc));
- Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "TEXT", NULL);
- return TCL_ERROR;
- }
-
- if (objc == 1) {
- if (Tcl_ListObjGetElements(interp, objv[0], &objc,
- (Tcl_Obj ***) &objv) != TCL_OK) {
- return TCL_ERROR;
- } else if (objc != 2) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "wrong # coordinates: expected 2, got %d", objc));
- Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "TEXT", NULL);
+ } else if (objc < 3) {
+ if (objc==1) {
+ if (Tcl_ListObjGetElements(interp, objv[0], &objc,
+ (Tcl_Obj ***) &objv) != TCL_OK) {
+ return TCL_ERROR;
+ } else if (objc != 2) {
+ char buf[64 + TCL_INTEGER_SPACE];
+
+ sprintf(buf, "wrong # coordinates: expected 2, got %d", objc);
+ Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ return TCL_ERROR;
+ }
+ }
+ if ((Tk_CanvasGetCoordFromObj(interp, canvas, objv[0],
+ &textPtr->x) != TCL_OK)
+ || (Tk_CanvasGetCoordFromObj(interp, canvas, objv[1],
+ &textPtr->y) != TCL_OK)) {
return TCL_ERROR;
}
- }
- if ((Tk_CanvasGetCoordFromObj(interp, canvas, objv[0],
- &textPtr->x) != TCL_OK)
- || (Tk_CanvasGetCoordFromObj(interp, canvas, objv[1],
- &textPtr->y) != TCL_OK)) {
+ ComputeTextBbox(canvas, textPtr);
+ } else {
+ char buf[64 + TCL_INTEGER_SPACE];
+
+ sprintf(buf, "wrong # coordinates: expected 0 or 2, got %d", objc);
+ Tcl_SetResult(interp, buf, TCL_VOLATILE);
return TCL_ERROR;
}
- ComputeTextBbox(canvas, textPtr);
return TCL_OK;
}
@@ -392,7 +387,7 @@ ConfigureText(
Tk_Canvas canvas, /* Canvas containing itemPtr. */
Tk_Item *itemPtr, /* Rectangle item to reconfigure. */
int objc, /* Number of elements in objv. */
- Tcl_Obj *const objv[], /* Arguments describing things to configure. */
+ Tcl_Obj *CONST objv[], /* Arguments describing things to configure. */
int flags) /* Flags to pass to Tk_ConfigureWidget. */
{
TextItem *textPtr = (TextItem *) itemPtr;
@@ -408,7 +403,7 @@ ConfigureText(
tkwin = Tk_CanvasTkwin(canvas);
if (TCL_OK != Tk_ConfigureWidget(interp, tkwin, configSpecs, objc,
- (const char **) objv, (char *) textPtr, flags|TK_CONFIG_OBJS)) {
+ (CONST char **) objv, (char *) textPtr, flags|TK_CONFIG_OBJS)) {
return TCL_ERROR;
}
@@ -425,24 +420,24 @@ ConfigureText(
itemPtr->redraw_flags &= ~TK_ITEM_STATE_DEPENDANT;
}
- if (state == TK_STATE_NULL) {
- state = Canvas(canvas)->canvas_state;
+ if(state == TK_STATE_NULL) {
+ state = ((TkCanvas *)canvas)->canvas_state;
}
color = textPtr->color;
stipple = textPtr->stipple;
- if (Canvas(canvas)->currentItemPtr == itemPtr) {
- if (textPtr->activeColor != NULL) {
+ if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) {
+ if (textPtr->activeColor!=NULL) {
color = textPtr->activeColor;
}
- if (textPtr->activeStipple != None) {
+ if (textPtr->activeStipple!=None) {
stipple = textPtr->activeStipple;
}
- } else if (state == TK_STATE_DISABLED) {
- if (textPtr->disabledColor != NULL) {
+ } else if (state==TK_STATE_DISABLED) {
+ if (textPtr->disabledColor!=NULL) {
color = textPtr->disabledColor;
}
- if (textPtr->disabledStipple != None) {
+ if (textPtr->disabledStipple!=None) {
stipple = textPtr->disabledStipple;
}
}
@@ -498,6 +493,7 @@ ConfigureText(
}
textPtr->cursorOffGC = newGC;
+
/*
* If the text was changed, move the selection and insertion indices to
* keep them inside the item.
@@ -523,22 +519,6 @@ ConfigureText(
textPtr->insertPos = textPtr->numChars;
}
- /*
- * Restrict so that 0.0 <= angle < 360.0, and then recompute the cached
- * sine and cosine of the angle. Note that fmod() can produce negative
- * results, and we try to avoid negative zero as well.
- */
-
- textPtr->angle = fmod(textPtr->angle, 360.0);
- if (textPtr->angle < 0.0) {
- textPtr->angle += 360.0;
- }
- if (textPtr->angle == 0.0) {
- textPtr->angle = 0.0;
- }
- textPtr->sine = sin(textPtr->angle * PI/180.0);
- textPtr->cosine = cos(textPtr->angle * PI/180.0);
-
ComputeTextBbox(canvas, textPtr);
return TCL_OK;
}
@@ -629,12 +609,11 @@ ComputeTextBbox(
TextItem *textPtr) /* Item whose bbox is to be recomputed. */
{
Tk_CanvasTextInfo *textInfoPtr;
- int leftX, topY, width, height, fudge, i;
+ int leftX, topY, width, height, fudge;
Tk_State state = textPtr->header.state;
- double x[4], y[4], dx[4], dy[4], sinA, cosA, tmp;
- if (state == TK_STATE_NULL) {
- state = Canvas(canvas)->canvas_state;
+ if(state == TK_STATE_NULL) {
+ state = ((TkCanvas *)canvas)->canvas_state;
}
Tk_FreeTextLayout(textPtr->textLayout);
@@ -651,11 +630,8 @@ ComputeTextBbox(
* bounding box for the text item.
*/
- leftX = ROUND(textPtr->x);
- topY = ROUND(textPtr->y);
- for (i=0 ; i<4 ; i++) {
- dx[i] = dy[i] = 0.0;
- }
+ leftX = (int) floor(textPtr->x + 0.5);
+ topY = (int) floor(textPtr->y + 0.5);
switch (textPtr->anchor) {
case TK_ANCHOR_NW:
case TK_ANCHOR_N:
@@ -666,18 +642,12 @@ ComputeTextBbox(
case TK_ANCHOR_CENTER:
case TK_ANCHOR_E:
topY -= height / 2;
- for (i=0 ; i<4 ; i++) {
- dy[i] = -height / 2;
- }
break;
case TK_ANCHOR_SW:
case TK_ANCHOR_S:
case TK_ANCHOR_SE:
topY -= height;
- for (i=0 ; i<4 ; i++) {
- dy[i] = -height;
- }
break;
}
switch (textPtr->anchor) {
@@ -690,27 +660,17 @@ ComputeTextBbox(
case TK_ANCHOR_CENTER:
case TK_ANCHOR_S:
leftX -= width / 2;
- for (i=0 ; i<4 ; i++) {
- dx[i] = -width / 2;
- }
break;
case TK_ANCHOR_NE:
case TK_ANCHOR_E:
case TK_ANCHOR_SE:
leftX -= width;
- for (i=0 ; i<4 ; i++) {
- dx[i] = -width;
- }
break;
}
- textPtr->actualWidth = width;
-
- sinA = textPtr->sine;
- cosA = textPtr->cosine;
- textPtr->drawOrigin[0] = textPtr->x + dx[0]*cosA + dy[0]*sinA;
- textPtr->drawOrigin[1] = textPtr->y + dy[0]*cosA - dx[0]*sinA;
+ textPtr->leftEdge = leftX;
+ textPtr->rightEdge = leftX + width;
/*
* Last of all, update the bounding box for the item. The item's bounding
@@ -723,50 +683,10 @@ ComputeTextBbox(
if (textInfoPtr->selBorderWidth > fudge) {
fudge = textInfoPtr->selBorderWidth;
}
-
- /*
- * Apply the rotation before computing the bounding box.
- */
-
- dx[0] -= fudge;
- dx[1] += width + fudge;
- dx[2] += width + fudge;
- dy[2] += height;
- dx[3] -= fudge;
- dy[3] += height;
- for (i=0 ; i<4 ; i++) {
- x[i] = textPtr->x + dx[i] * cosA + dy[i] * sinA;
- y[i] = textPtr->y + dy[i] * cosA - dx[i] * sinA;
- }
-
- /*
- * Convert to a rectilinear bounding box.
- */
-
- for (i=1,tmp=x[0] ; i<4 ; i++) {
- if (x[i] < tmp) {
- tmp = x[i];
- }
- }
- textPtr->header.x1 = ROUND(tmp);
- for (i=1,tmp=y[0] ; i<4 ; i++) {
- if (y[i] < tmp) {
- tmp = y[i];
- }
- }
- textPtr->header.y1 = ROUND(tmp);
- for (i=1,tmp=x[0] ; i<4 ; i++) {
- if (x[i] > tmp) {
- tmp = x[i];
- }
- }
- textPtr->header.x2 = ROUND(tmp);
- for (i=1,tmp=y[0] ; i<4 ; i++) {
- if (y[i] > tmp) {
- tmp = y[i];
- }
- }
- textPtr->header.y2 = ROUND(tmp);
+ textPtr->header.x1 = leftX - fudge;
+ textPtr->header.y1 = topY;
+ textPtr->header.x2 = leftX + width + fudge;
+ textPtr->header.y2 = topY + height;
}
/*
@@ -806,16 +726,16 @@ DisplayCanvText(
textPtr = (TextItem *) itemPtr;
textInfoPtr = textPtr->textInfoPtr;
- if (state == TK_STATE_NULL) {
- state = Canvas(canvas)->canvas_state;
+ if(state == TK_STATE_NULL) {
+ state = ((TkCanvas *)canvas)->canvas_state;
}
stipple = textPtr->stipple;
- if (Canvas(canvas)->currentItemPtr == itemPtr) {
- if (textPtr->activeStipple != None) {
+ if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) {
+ if (textPtr->activeStipple!=None) {
stipple = textPtr->activeStipple;
}
- } else if (state == TK_STATE_DISABLED) {
- if (textPtr->disabledStipple != None) {
+ } else if (state==TK_STATE_DISABLED) {
+ if (textPtr->disabledStipple!=None) {
stipple = textPtr->disabledStipple;
}
}
@@ -836,8 +756,6 @@ DisplayCanvText(
selFirstChar = -1;
selLastChar = 0; /* lint. */
- Tk_CanvasDrawableCoords(canvas, textPtr->drawOrigin[0],
- textPtr->drawOrigin[1], &drawableX, &drawableY);
if (textInfoPtr->selItemPtr == itemPtr) {
selFirstChar = textInfoPtr->selectFirst;
@@ -868,30 +786,20 @@ DisplayCanvText(
x = xFirst;
height = hFirst;
for (y = yFirst ; y <= yLast; y += height) {
- int dx1, dy1, dx2, dy2;
- double s = textPtr->sine, c = textPtr->cosine;
- XPoint points[4];
-
if (y == yLast) {
width = xLast + wLast - x;
} else {
- width = textPtr->actualWidth - x;
+ width = textPtr->rightEdge - textPtr->leftEdge - x;
}
- dx1 = x - textInfoPtr->selBorderWidth;
- dy1 = y;
- dx2 = width + 2 * textInfoPtr->selBorderWidth;
- dy2 = height;
- points[0].x = (short)(drawableX + dx1*c + dy1*s);
- points[0].y = (short)(drawableY + dy1*c - dx1*s);
- points[1].x = (short)(drawableX + (dx1+dx2)*c + dy1*s);
- points[1].y = (short)(drawableY + dy1*c - (dx1+dx2)*s);
- points[2].x = (short)(drawableX + (dx1+dx2)*c + (dy1+dy2)*s);
- points[2].y = (short)(drawableY + (dy1+dy2)*c - (dx1+dx2)*s);
- points[3].x = (short)(drawableX + dx1*c + (dy1+dy2)*s);
- points[3].y = (short)(drawableY + (dy1+dy2)*c - dx1*s);
- Tk_Fill3DPolygon(Tk_CanvasTkwin(canvas), drawable,
- textInfoPtr->selBorder, points, 4,
- textInfoPtr->selBorderWidth, TK_RELIEF_RAISED);
+ Tk_CanvasDrawableCoords(canvas,
+ (double) (textPtr->leftEdge + x
+ - textInfoPtr->selBorderWidth),
+ (double) (textPtr->header.y1 + y),
+ &drawableX, &drawableY);
+ Tk_Fill3DRectangle(Tk_CanvasTkwin(canvas), drawable,
+ textInfoPtr->selBorder, drawableX, drawableY,
+ width + 2 * textInfoPtr->selBorderWidth,
+ height, textInfoPtr->selBorderWidth, TK_RELIEF_RAISED);
x = 0;
}
}
@@ -909,28 +817,18 @@ DisplayCanvText(
if ((textInfoPtr->focusItemPtr == itemPtr) && (textInfoPtr->gotFocus)) {
if (Tk_CharBbox(textPtr->textLayout, textPtr->insertPos,
&x, &y, NULL, &height)) {
- int dx1, dy1, dx2, dy2;
- double s = textPtr->sine, c = textPtr->cosine;
- XPoint points[4];
-
- dx1 = x - (textInfoPtr->insertWidth / 2);
- dy1 = y;
- dx2 = textInfoPtr->insertWidth;
- dy2 = height;
- points[0].x = (short)(drawableX + dx1*c + dy1*s);
- points[0].y = (short)(drawableY + dy1*c - dx1*s);
- points[1].x = (short)(drawableX + (dx1+dx2)*c + dy1*s);
- points[1].y = (short)(drawableY + dy1*c - (dx1+dx2)*s);
- points[2].x = (short)(drawableX + (dx1+dx2)*c + (dy1+dy2)*s);
- points[2].y = (short)(drawableY + (dy1+dy2)*c - (dx1+dx2)*s);
- points[3].x = (short)(drawableX + dx1*c + (dy1+dy2)*s);
- points[3].y = (short)(drawableY + (dy1+dy2)*c - dx1*s);
-
- Tk_SetCaretPos(Tk_CanvasTkwin(canvas), points[0].x, points[0].y,
+ Tk_CanvasDrawableCoords(canvas,
+ (double) (textPtr->leftEdge + x
+ - (textInfoPtr->insertWidth / 2)),
+ (double) (textPtr->header.y1 + y),
+ &drawableX, &drawableY);
+ Tk_SetCaretPos(Tk_CanvasTkwin(canvas), drawableX, drawableY,
height);
if (textInfoPtr->cursorOn) {
- Tk_Fill3DPolygon(Tk_CanvasTkwin(canvas), drawable,
- textInfoPtr->insertBorder, points, 4,
+ Tk_Fill3DRectangle(Tk_CanvasTkwin(canvas), drawable,
+ textInfoPtr->insertBorder,
+ drawableX, drawableY,
+ textInfoPtr->insertWidth, height,
textInfoPtr->insertBorderWidth, TK_RELIEF_RAISED);
} else if (textPtr->cursorOffGC != None) {
/*
@@ -940,8 +838,10 @@ DisplayCanvText(
* where both may be drawn in the same color.
*/
- XFillPolygon(display, drawable, textPtr->cursorOffGC,
- points, 4, Convex, CoordModeOrigin);
+ XFillRectangle(display, drawable, textPtr->cursorOffGC,
+ drawableX, drawableY,
+ (unsigned) textInfoPtr->insertWidth,
+ (unsigned) height);
}
}
}
@@ -956,24 +856,23 @@ DisplayCanvText(
* anti-aliasing colors would blend together.
*/
+ Tk_CanvasDrawableCoords(canvas, (double) textPtr->leftEdge,
+ (double) textPtr->header.y1, &drawableX, &drawableY);
+
if ((selFirstChar >= 0) && (textPtr->selTextGC != textPtr->gc)) {
- TkDrawAngledTextLayout(display, drawable, textPtr->gc,
- textPtr->textLayout, drawableX, drawableY, textPtr->angle,
- 0, selFirstChar);
- TkDrawAngledTextLayout(display, drawable, textPtr->selTextGC,
- textPtr->textLayout, drawableX, drawableY, textPtr->angle,
- selFirstChar, selLastChar + 1);
- TkDrawAngledTextLayout(display, drawable, textPtr->gc,
- textPtr->textLayout, drawableX, drawableY, textPtr->angle,
- selLastChar + 1, -1);
+ Tk_DrawTextLayout(display, drawable, textPtr->gc, textPtr->textLayout,
+ drawableX, drawableY, 0, selFirstChar);
+ Tk_DrawTextLayout(display, drawable, textPtr->selTextGC,
+ textPtr->textLayout, drawableX, drawableY, selFirstChar,
+ selLastChar + 1);
+ Tk_DrawTextLayout(display, drawable, textPtr->gc, textPtr->textLayout,
+ drawableX, drawableY, selLastChar + 1, -1);
} else {
- TkDrawAngledTextLayout(display, drawable, textPtr->gc,
- textPtr->textLayout, drawableX, drawableY, textPtr->angle,
- 0, -1);
+ Tk_DrawTextLayout(display, drawable, textPtr->gc, textPtr->textLayout,
+ drawableX, drawableY, 0, -1);
}
- TkUnderlineAngledTextLayout(display, drawable, textPtr->gc,
- textPtr->textLayout, drawableX, drawableY, textPtr->angle,
- textPtr->underline);
+ Tk_UnderlineTextLayout(display, drawable, textPtr->gc, textPtr->textLayout,
+ drawableX, drawableY, textPtr->underline);
if (stipple != None) {
XSetTSOrigin(display, textPtr->gc, 0, 0);
@@ -981,7 +880,7 @@ DisplayCanvText(
}
/*
- *----------------------------------------------------------------------
+ *--------------------------------------------------------------
*
* TextInsert --
*
@@ -994,7 +893,7 @@ DisplayCanvText(
* The text in the given item is modified. The cursor and selection
* positions are also modified to reflect the insertion.
*
- *----------------------------------------------------------------------
+ *--------------------------------------------------------------
*/
static void
@@ -1003,15 +902,14 @@ TextInsert(
Tk_Item *itemPtr, /* Text item to be modified. */
int index, /* Character index before which string is to
* be inserted. */
- Tcl_Obj *obj) /* New characters to be inserted. */
+ char *string) /* New characters to be inserted. */
{
TextItem *textPtr = (TextItem *) itemPtr;
int byteIndex, byteCount, charsAdded;
char *newStr, *text;
- const char *string;
Tk_CanvasTextInfo *textInfoPtr = textPtr->textInfoPtr;
- string = Tcl_GetStringFromObj(obj, &byteCount);
+ string = Tcl_GetStringFromObj((Tcl_Obj *) string, &byteCount);
text = textPtr->text;
@@ -1027,7 +925,7 @@ TextInsert(
return;
}
- newStr = ckalloc(textPtr->numBytes + byteCount + 1);
+ newStr = (char *) ckalloc((unsigned) textPtr->numBytes + byteCount + 1);
memcpy(newStr, text, (size_t) byteIndex);
strcpy(newStr + byteIndex, string);
strcpy(newStr + byteIndex + byteCount, text + byteIndex);
@@ -1108,7 +1006,7 @@ TextDeleteChars(
byteCount = Tcl_UtfAtIndex(text + byteIndex, charsRemoved)
- (text + byteIndex);
- newStr = ckalloc(textPtr->numBytes + 1 - byteCount);
+ newStr = (char *) ckalloc((unsigned) (textPtr->numBytes + 1 - byteCount));
memcpy(newStr, text, (size_t) byteIndex);
strcpy(newStr + byteIndex, text + byteIndex + byteCount);
@@ -1184,17 +1082,15 @@ TextToPoint(
{
TextItem *textPtr;
Tk_State state = itemPtr->state;
- double value, px, py;
+ double value;
if (state == TK_STATE_NULL) {
- state = Canvas(canvas)->canvas_state;
+ state = ((TkCanvas *)canvas)->canvas_state;
}
textPtr = (TextItem *) itemPtr;
- px = pointPtr[0] - textPtr->drawOrigin[0];
- py = pointPtr[1] - textPtr->drawOrigin[1];
value = (double) Tk_DistanceToTextLayout(textPtr->textLayout,
- (int) (px*textPtr->cosine - py*textPtr->sine),
- (int) (py*textPtr->cosine + px*textPtr->sine));
+ (int) pointPtr[0] - textPtr->leftEdge,
+ (int) pointPtr[1] - textPtr->header.y1);
if ((state == TK_STATE_HIDDEN) || (textPtr->color == NULL) ||
(textPtr->text == NULL) || (*textPtr->text == 0)) {
@@ -1234,16 +1130,15 @@ TextToArea(
Tk_State state = itemPtr->state;
if (state == TK_STATE_NULL) {
- state = Canvas(canvas)->canvas_state;
+ state = ((TkCanvas *)canvas)->canvas_state;
}
textPtr = (TextItem *) itemPtr;
- return TkIntersectAngledTextLayout(textPtr->textLayout,
- (int) ((rectPtr[0] + 0.5) - textPtr->drawOrigin[0]),
- (int) ((rectPtr[1] + 0.5) - textPtr->drawOrigin[1]),
+ return Tk_IntersectTextLayout(textPtr->textLayout,
+ (int) (rectPtr[0] + 0.5) - textPtr->leftEdge,
+ (int) (rectPtr[1] + 0.5) - textPtr->header.y1,
(int) (rectPtr[2] - rectPtr[0] + 0.5),
- (int) (rectPtr[3] - rectPtr[1] + 0.5),
- textPtr->angle);
+ (int) (rectPtr[3] - rectPtr[1] + 0.5));
}
/*
@@ -1347,7 +1242,7 @@ GetTextIndex(
int c;
TkCanvas *canvasPtr = (TkCanvas *) canvas;
Tk_CanvasTextInfo *textInfoPtr = textPtr->textInfoPtr;
- const char *string = Tcl_GetStringFromObj(obj, &length);
+ char *string = Tcl_GetStringFromObj(obj, &length);
c = string[0];
@@ -1359,26 +1254,21 @@ GetTextIndex(
} else if ((c == 's') && (length >= 5)
&& (strncmp(string, "sel.first", (unsigned) length) == 0)) {
if (textInfoPtr->selItemPtr != itemPtr) {
- Tcl_SetObjResult(interp, Tcl_NewStringObj(
- "selection isn't in item", -1));
- Tcl_SetErrorCode(interp, "TK", "CANVAS", "UNSELECTED", NULL);
+ Tcl_SetResult(interp, "selection isn't in item", TCL_STATIC);
return TCL_ERROR;
}
*indexPtr = textInfoPtr->selectFirst;
} else if ((c == 's') && (length >= 5)
&& (strncmp(string, "sel.last", (unsigned) length) == 0)) {
if (textInfoPtr->selItemPtr != itemPtr) {
- Tcl_SetObjResult(interp, Tcl_NewStringObj(
- "selection isn't in item", -1));
- Tcl_SetErrorCode(interp, "TK", "CANVAS", "UNSELECTED", NULL);
+ Tcl_SetResult(interp, "selection isn't in item", TCL_STATIC);
return TCL_ERROR;
}
*indexPtr = textInfoPtr->selectLast;
} else if (c == '@') {
int x, y;
- double tmp, c = textPtr->cosine, s = textPtr->sine;
- char *end;
- const char *p;
+ double tmp;
+ char *end, *p;
p = string+1;
tmp = strtod(p, &end);
@@ -1392,12 +1282,11 @@ GetTextIndex(
goto badIndex;
}
y = (int) ((tmp < 0) ? tmp - 0.5 : tmp + 0.5);
- x += canvasPtr->scrollX1 - (int) textPtr->drawOrigin[0];
- y += canvasPtr->scrollY1 - (int) textPtr->drawOrigin[1];
*indexPtr = Tk_PointToChar(textPtr->textLayout,
- (int) (x*c - y*s), (int) (y*c + x*s));
+ x + canvasPtr->scrollX1 - textPtr->leftEdge,
+ y + canvasPtr->scrollY1 - textPtr->header.y1);
} else if (Tcl_GetIntFromObj(NULL, obj, indexPtr) == TCL_OK) {
- if (*indexPtr < 0) {
+ if (*indexPtr < 0){
*indexPtr = 0;
} else if (*indexPtr > textPtr->numChars) {
*indexPtr = textPtr->numChars;
@@ -1409,8 +1298,8 @@ GetTextIndex(
*/
badIndex:
- Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad index \"%s\"", string));
- Tcl_SetErrorCode(interp, "TK", "CANVAS", "ITEM_INDEX", "TEXT", NULL);
+ Tcl_SetResult(interp, NULL, TCL_STATIC);
+ Tcl_AppendResult(interp, "bad index \"", string, "\"", NULL);
return TCL_ERROR;
}
return TCL_OK;
@@ -1486,7 +1375,7 @@ GetSelText(
TextItem *textPtr = (TextItem *) itemPtr;
int byteCount;
char *text;
- const char *selStart, *selEnd;
+ CONST char *selStart, *selEnd;
Tk_CanvasTextInfo *textInfoPtr = textPtr->textInfoPtr;
if ((textInfoPtr->selectFirst < 0) ||
@@ -1538,73 +1427,59 @@ TextToPostscript(
* being created. */
{
TextItem *textPtr = (TextItem *) itemPtr;
- double x, y;
+ int x, y;
Tk_FontMetrics fm;
- const char *justify;
+ char *justify;
+ char buffer[500];
XColor *color;
Pixmap stipple;
Tk_State state = itemPtr->state;
- Tcl_Obj *psObj;
- Tcl_InterpState interpState;
if (state == TK_STATE_NULL) {
- state = Canvas(canvas)->canvas_state;
+ state = ((TkCanvas *)canvas)->canvas_state;
}
color = textPtr->color;
stipple = textPtr->stipple;
if (state == TK_STATE_HIDDEN || textPtr->color == NULL ||
textPtr->text == NULL || *textPtr->text == 0) {
return TCL_OK;
- } else if (Canvas(canvas)->currentItemPtr == itemPtr) {
- if (textPtr->activeColor != NULL) {
+ } else if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) {
+ if (textPtr->activeColor!=NULL) {
color = textPtr->activeColor;
}
- if (textPtr->activeStipple != None) {
+ if (textPtr->activeStipple!=None) {
stipple = textPtr->activeStipple;
}
- } else if (state == TK_STATE_DISABLED) {
- if (textPtr->disabledColor != NULL) {
+ } else if (state==TK_STATE_DISABLED) {
+ if (textPtr->disabledColor!=NULL) {
color = textPtr->disabledColor;
}
- if (textPtr->disabledStipple != None) {
+ if (textPtr->disabledStipple!=None) {
stipple = textPtr->disabledStipple;
}
}
- /*
- * Make our working space.
- */
-
- psObj = Tcl_NewObj();
- interpState = Tcl_SaveInterpState(interp, TCL_OK);
-
- /*
- * Generate postscript.
- */
-
- Tcl_ResetResult(interp);
if (Tk_CanvasPsFont(interp, canvas, textPtr->tkfont) != TCL_OK) {
- goto error;
+ return TCL_ERROR;
}
- Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));
-
if (prepass != 0) {
- goto done;
+ return TCL_OK;
}
-
- Tcl_ResetResult(interp);
if (Tk_CanvasPsColor(interp, canvas, color) != TCL_OK) {
- goto error;
+ return TCL_ERROR;
}
- Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));
-
if (stipple != None) {
- Tcl_ResetResult(interp);
+ Tcl_AppendResult(interp, "/StippleText {\n ", NULL);
Tk_CanvasPsStipple(interp, canvas, stipple);
- Tcl_AppendPrintfToObj(psObj, "/StippleText {\n %s} bind def\n",
- Tcl_GetString(Tcl_GetObjResult(interp)));
+ Tcl_AppendResult(interp, "} bind def\n", NULL);
}
+ sprintf(buffer, "%.15g %.15g [\n", textPtr->x,
+ Tk_CanvasPsY(canvas, textPtr->y));
+ Tcl_AppendResult(interp, buffer, NULL);
+
+ Tk_TextLayoutToPostscript(interp, textPtr->textLayout);
+
x = 0; y = 0; justify = NULL; /* lint. */
switch (textPtr->anchor) {
case TK_ANCHOR_NW: x = 0; y = 0; break;
@@ -1624,31 +1499,17 @@ TextToPostscript(
}
Tk_GetFontMetrics(textPtr->tkfont, &fm);
+ sprintf(buffer, "] %d ", fm.linespace);
+ Tcl_AppendResult(interp, buffer, NULL);
+ Tcl_PrintDouble(NULL, x / -2.0, buffer);
+ Tcl_AppendResult(interp, buffer, NULL);
+ Tcl_PrintDouble(NULL, y / 2.0, buffer);
+ Tcl_AppendResult(interp, " ", buffer, NULL);
+ sprintf(buffer, " %s %s DrawText\n",
+ justify, ((stipple == None) ? "false" : "true"));
+ Tcl_AppendResult(interp, buffer, NULL);
- Tcl_AppendPrintfToObj(psObj, "%.15g %.15g %.15g [\n",
- textPtr->angle, textPtr->x, Tk_CanvasPsY(canvas, textPtr->y));
- Tcl_ResetResult(interp);
- Tk_TextLayoutToPostscript(interp, textPtr->textLayout);
- Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));
- Tcl_AppendPrintfToObj(psObj,
- "] %d %g %g %s %s DrawText\n",
- fm.linespace, x / -2.0, y / 2.0, justify,
- ((stipple == None) ? "false" : "true"));
-
- /*
- * Plug the accumulated postscript back into the result.
- */
-
- done:
- (void) Tcl_RestoreInterpState(interp, interpState);
- Tcl_AppendObjToObj(Tcl_GetObjResult(interp), psObj);
- Tcl_DecrRefCount(psObj);
return TCL_OK;
-
- error:
- Tcl_DiscardInterpState(interpState);
- Tcl_DecrRefCount(psObj);
- return TCL_ERROR;
}
/*