summaryrefslogtreecommitdiffstats
path: root/generic/tkRectOval.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tkRectOval.c')
-rw-r--r--generic/tkRectOval.c110
1 files changed, 76 insertions, 34 deletions
diff --git a/generic/tkRectOval.c b/generic/tkRectOval.c
index 630737c..a51ca33 100644
--- a/generic/tkRectOval.c
+++ b/generic/tkRectOval.c
@@ -318,17 +318,13 @@ RectOvalCoords(
*/
if (objc == 0) {
- Tcl_Obj *obj = Tcl_NewObj();
-
- Tcl_ListObjAppendElement(NULL, obj,
- Tcl_NewDoubleObj(rectOvalPtr->bbox[0]));
- Tcl_ListObjAppendElement(NULL, obj,
- Tcl_NewDoubleObj(rectOvalPtr->bbox[1]));
- Tcl_ListObjAppendElement(NULL, obj,
- Tcl_NewDoubleObj(rectOvalPtr->bbox[2]));
- Tcl_ListObjAppendElement(NULL, obj,
- Tcl_NewDoubleObj(rectOvalPtr->bbox[3]));
- Tcl_SetObjResult(interp, obj);
+ Tcl_Obj *bbox[4];
+
+ bbox[0] = Tcl_NewDoubleObj(rectOvalPtr->bbox[0]);
+ bbox[1] = Tcl_NewDoubleObj(rectOvalPtr->bbox[1]);
+ bbox[2] = Tcl_NewDoubleObj(rectOvalPtr->bbox[2]);
+ bbox[3] = Tcl_NewDoubleObj(rectOvalPtr->bbox[3]);
+ Tcl_SetObjResult(interp, Tcl_NewListObj(4, bbox));
return TCL_OK;
}
@@ -348,10 +344,11 @@ RectOvalCoords(
*/
if (objc != 4) {
- char buf[64 + TCL_INTEGER_SPACE];
-
- sprintf(buf, "wrong # coordinates: expected 0 or 4, got %d", objc);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "wrong # coordinates: expected 0 or 4, got %d", objc));
+ Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS",
+ (rectOvalPtr->header.typePtr == &tkRectangleType
+ ? "RECTANGLE" : "OVAL"), NULL);
return TCL_ERROR;
}
@@ -515,9 +512,10 @@ ConfigureRectOval(
}
#ifdef MAC_OSX_TK
/*
- * Mac OS X CG drawing needs access to the outline linewidth
- * even for fills (as linewidth controls antialiasing).
+ * Mac OS X CG drawing needs access to the outline linewidth even for
+ * fills (as linewidth controls antialiasing).
*/
+
gcValues.line_width = rectOvalPtr->outline.gc != None ?
rectOvalPtr->outline.gc->line_width : 0;
mask |= GCLineWidth;
@@ -677,7 +675,7 @@ ComputeRectOvalBbox(
bloat = 1;
#else
bloat = 0;
-#endif
+#endif /* __WIN32__ */
} else {
#ifdef MAC_OSX_TK
/*
@@ -689,7 +687,7 @@ ComputeRectOvalBbox(
bloat = (int) (width+1.5)/2;
#else
bloat = (int) (width+1)/2;
-#endif
+#endif /* MAC_OSX_TK */
}
/*
@@ -757,9 +755,9 @@ DisplayRectOval(
* will die if it isn't.
*/
- Tk_CanvasDrawableCoords(canvas, rectOvalPtr->bbox[0], rectOvalPtr->bbox[1],
+ Tk_CanvasDrawableCoords(canvas, rectOvalPtr->bbox[0],rectOvalPtr->bbox[1],
&x1, &y1);
- Tk_CanvasDrawableCoords(canvas, rectOvalPtr->bbox[2], rectOvalPtr->bbox[3],
+ Tk_CanvasDrawableCoords(canvas, rectOvalPtr->bbox[2],rectOvalPtr->bbox[3],
&x2, &y2);
if (x2 <= x1) {
x2 = x1+1;
@@ -1293,13 +1291,14 @@ RectOvalToPostscript(
* information; 0 means final Postscript is
* being created. */
{
- char pathCmd[500];
+ Tcl_Obj *pathObj, *psObj;
RectOvalItem *rectOvalPtr = (RectOvalItem *) itemPtr;
double y1, y2;
XColor *color;
XColor *fillColor;
Pixmap fillStipple;
Tk_State state = itemPtr->state;
+ Tcl_InterpState interpState;
y1 = Tk_CanvasPsY(canvas, rectOvalPtr->bbox[1]);
y2 = Tk_CanvasPsY(canvas, rectOvalPtr->bbox[3]);
@@ -1310,12 +1309,23 @@ RectOvalToPostscript(
*/
if (rectOvalPtr->header.typePtr == &tkRectangleType) {
- sprintf(pathCmd, "%.15g %.15g moveto %.15g 0 rlineto 0 %.15g rlineto %.15g 0 rlineto closepath\n",
+ pathObj = Tcl_ObjPrintf(
+ "%.15g %.15g moveto "
+ "%.15g 0 rlineto "
+ "0 %.15g rlineto "
+ "%.15g 0 rlineto "
+ "closepath\n",
rectOvalPtr->bbox[0], y1,
- rectOvalPtr->bbox[2]-rectOvalPtr->bbox[0], y2-y1,
+ rectOvalPtr->bbox[2]-rectOvalPtr->bbox[0],
+ y2-y1,
rectOvalPtr->bbox[0]-rectOvalPtr->bbox[2]);
} else {
- sprintf(pathCmd, "matrix currentmatrix\n%.15g %.15g translate %.15g %.15g scale 1 0 moveto 0 0 1 0 360 arc\nsetmatrix\n",
+ pathObj = Tcl_ObjPrintf(
+ "matrix currentmatrix\n"
+ "%.15g %.15g translate "
+ "%.15g %.15g scale "
+ "1 0 moveto 0 0 1 0 360 arc\n"
+ "setmatrix\n",
(rectOvalPtr->bbox[0] + rectOvalPtr->bbox[2])/2, (y1 + y2)/2,
(rectOvalPtr->bbox[2] - rectOvalPtr->bbox[0])/2, (y1 - y2)/2);
}
@@ -1349,24 +1359,38 @@ RectOvalToPostscript(
}
/*
+ * Make our working space.
+ */
+
+ psObj = Tcl_NewObj();
+ interpState = Tcl_SaveInterpState(interp, TCL_OK);
+
+ /*
* First draw the filled area of the rectangle.
*/
if (fillColor != NULL) {
- Tcl_AppendResult(interp, pathCmd, NULL);
+ Tcl_AppendObjToObj(psObj, pathObj);
+
+ Tcl_ResetResult(interp);
if (Tk_CanvasPsColor(interp, canvas, fillColor) != TCL_OK) {
- return TCL_ERROR;
+ goto error;
}
+ Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));
+
if (fillStipple != None) {
- Tcl_AppendResult(interp, "clip ", NULL);
+ Tcl_AppendToObj(psObj, "clip ", -1);
+
+ Tcl_ResetResult(interp);
if (Tk_CanvasPsStipple(interp, canvas, fillStipple) != TCL_OK) {
- return TCL_ERROR;
+ goto error;
}
+ Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));
if (color != NULL) {
- Tcl_AppendResult(interp, "grestore gsave\n", NULL);
+ Tcl_AppendToObj(psObj, "grestore gsave\n", -1);
}
} else {
- Tcl_AppendResult(interp, "fill\n", NULL);
+ Tcl_AppendToObj(psObj, "fill\n", -1);
}
}
@@ -1375,14 +1399,32 @@ RectOvalToPostscript(
*/
if (color != NULL) {
- Tcl_AppendResult(interp, pathCmd, "0 setlinejoin 2 setlinecap\n",
- NULL);
+ Tcl_AppendObjToObj(psObj, pathObj);
+ Tcl_AppendToObj(psObj, "0 setlinejoin 2 setlinecap\n", -1);
+
+ Tcl_ResetResult(interp);
if (Tk_CanvasPsOutline(canvas, itemPtr,
&rectOvalPtr->outline)!= TCL_OK) {
- return TCL_ERROR;
+ goto error;
}
+ Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));
}
+
+ /*
+ * Plug the accumulated postscript back into the result.
+ */
+
+ (void) Tcl_RestoreInterpState(interp, interpState);
+ Tcl_AppendObjToObj(Tcl_GetObjResult(interp), psObj);
+ Tcl_DecrRefCount(psObj);
+ Tcl_DecrRefCount(pathObj);
return TCL_OK;
+
+ error:
+ Tcl_DiscardInterpState(interpState);
+ Tcl_DecrRefCount(psObj);
+ Tcl_DecrRefCount(pathObj);
+ return TCL_ERROR;
}
/*