Debian Codegraph @

pTk/mTk/generic/tkCanvLine.c

raw symbols SCIP
1 /*
2 * tkCanvLine.c --
3 *
4 * This file implements line items for canvas widgets.
5 *
6 * Copyright (c) 1991-1994 The Regents of the University of California.
7 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
8 * Copyright (c) 1998-1999 by Scriptics Corporation.
9 *
10 * See the file "license.terms" for information on usage and redistribution
11 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 *
13 * RCS: @(#) $Id: tkCanvLine.c,v 1.13 2003/02/09 07:48:22 hobbs Exp $
14 */
15
16 #include "tkPort.h"
17 #include "tkInt.h"
18 #include "tkCanvases.h"
19
20 /*
21 * The structure below defines the record for each line item.
22 */
23
24 typedef enum {
25 ARROWS_NONE, ARROWS_FIRST, ARROWS_LAST, ARROWS_BOTH
26 } Arrows;
27
28 typedef struct LineItem {
29 Tk_Item header; /* Generic stuff that's the same for all
30 * types. MUST BE FIRST IN STRUCTURE. */
31 Tk_Outline outline; /* Outline structure */
32 Tk_Canvas canvas; /* Canvas containing item. Needed for
33 * parsing arrow shapes. */
34 int numPoints; /* Number of points in line (always >= 0). */
35 double *coordPtr; /* Pointer to malloc-ed array containing
36 * x- and y-coords of all points in line.
37 * X-coords are even-valued indices, y-coords
38 * are corresponding odd-valued indices. If
39 * the line has arrowheads then the first
40 * and last points have been adjusted to refer
41 * to the necks of the arrowheads rather than
42 * their tips. The actual endpoints are
43 * stored in the *firstArrowPtr and
44 * *lastArrowPtr, if they exist. */
45 int capStyle; /* Cap style for line. */
46 int joinStyle; /* Join style for line. */
47 GC arrowGC; /* Graphics context for drawing arrowheads. */
48 Arrows arrow; /* Indicates whether or not to draw arrowheads:
49 * "none", "first", "last", or "both". */
50 float arrowShapeA; /* Distance from tip of arrowhead to center. */
51 float arrowShapeB; /* Distance from tip of arrowhead to trailing
52 * point, measured along shaft. */
53 float arrowShapeC; /* Distance of trailing points from outside
54 * edge of shaft. */
55 double *firstArrowPtr; /* Points to array of PTS_IN_ARROW points
56 * describing polygon for arrowhead at first
57 * point in line. First point of arrowhead
58 * is tip. Malloc'ed. NULL means no arrowhead
59 * at first point. */
60 double *lastArrowPtr; /* Points to polygon for arrowhead at last
61 * point in line (PTS_IN_ARROW points, first
62 * of which is tip). Malloc'ed. NULL means
63 * no arrowhead at last point. */
64 Tk_SmoothMethod *smooth; /* Non-zero means draw line smoothed (i.e.
65 * with Bezier splines). */
66 int splineSteps; /* Number of steps in each spline segment. */
67 } LineItem;
68
69 /*
70 * Number of points in an arrowHead:
71 */
72
73 #define PTS_IN_ARROW 6
74
75 /*
76 * Prototypes for procedures defined in this file:
77 */
78
79 static int ArrowheadPostscript _ANSI_ARGS_((Tcl_Interp *interp,
80 Tk_Canvas canvas, LineItem *linePtr,
81 double *arrowPtr));
82 static void ComputeLineBbox _ANSI_ARGS_((Tk_Canvas canvas,
83 LineItem *linePtr));
84 static int ConfigureLine _ANSI_ARGS_((Tcl_Interp *interp,
85 Tk_Canvas canvas, Tk_Item *itemPtr, int objc,
86 Tcl_Obj *CONST objv[], int flags));
87 static int ConfigureArrows _ANSI_ARGS_((Tk_Canvas canvas,
88 LineItem *linePtr));
89 static int CreateLine _ANSI_ARGS_((Tcl_Interp *interp,
90 Tk_Canvas canvas, struct Tk_Item *itemPtr,
91 int objc, Tcl_Obj *CONST objv[]));
92 static void DeleteLine _ANSI_ARGS_((Tk_Canvas canvas,
93 Tk_Item *itemPtr, Display *display));
94 static void DisplayLine _ANSI_ARGS_((Tk_Canvas canvas,
95 Tk_Item *itemPtr, Display *display, Drawable dst,
96 int x, int y, int width, int height));
97 static int GetLineIndex _ANSI_ARGS_((Tcl_Interp *interp,
98 Tk_Canvas canvas, Tk_Item *itemPtr,
99 Tcl_Obj *obj, int *indexPtr));
100 static int LineCoords _ANSI_ARGS_((Tcl_Interp *interp,
101 Tk_Canvas canvas, Tk_Item *itemPtr,
102 int objc, Tcl_Obj *CONST objv[]));
103 static void LineDeleteCoords _ANSI_ARGS_((Tk_Canvas canvas,
104 Tk_Item *itemPtr, int first, int last));
105 static void LineInsert _ANSI_ARGS_((Tk_Canvas canvas,
106 Tk_Item *itemPtr, int beforeThis, Tcl_Obj *obj));
107 static int LineToArea _ANSI_ARGS_((Tk_Canvas canvas,
108 Tk_Item *itemPtr, double *rectPtr));
109 static double LineToPoint _ANSI_ARGS_((Tk_Canvas canvas,
110 Tk_Item *itemPtr, double *coordPtr));
111 static int LineToPostscript _ANSI_ARGS_((Tcl_Interp *interp,
112 Tk_Canvas canvas, Tk_Item *itemPtr, int prepass));
113 static int ArrowParseProc _ANSI_ARGS_((ClientData clientData,
114 Tcl_Interp *interp, Tk_Window tkwin,
115 Tcl_Obj * value, char *recordPtr, int offset));
116 static Tcl_Obj * ArrowPrintProc _ANSI_ARGS_((ClientData clientData,
117 Tk_Window tkwin, char *recordPtr, int offset,
118 Tcl_FreeProc **freeProcPtr));
119 static int ParseArrowShape _ANSI_ARGS_((ClientData clientData,
120 Tcl_Interp *interp, Tk_Window tkwin,
121 Tcl_Obj * value, char *recordPtr, int offset));
122 static Tcl_Obj * PrintArrowShape _ANSI_ARGS_((ClientData clientData,
123 Tk_Window tkwin, char *recordPtr, int offset,
124 Tcl_FreeProc **freeProcPtr));
125 static void ScaleLine _ANSI_ARGS_((Tk_Canvas canvas,
126 Tk_Item *itemPtr, double originX, double originY,
127 double scaleX, double scaleY));
128 static void TranslateLine _ANSI_ARGS_((Tk_Canvas canvas,
129 Tk_Item *itemPtr, double deltaX, double deltaY));
130
131 /*
132 * Information used for parsing configuration specs. If you change any
133 * of the default strings, be sure to change the corresponding default
134 * values in CreateLine.
135 */
136
137 static Tk_CustomOption arrowShapeOption = {
138 ParseArrowShape,
139 PrintArrowShape, (ClientData) NULL
140 };
141 static Tk_CustomOption arrowOption = {
142 ArrowParseProc,
143 ArrowPrintProc, (ClientData) NULL
144 };
145 static Tk_CustomOption smoothOption = {
146 TkSmoothParseProc,
147 TkSmoothPrintProc, (ClientData) NULL
148 };
149 static Tk_CustomOption stateOption = {
150 TkStateParseProc,
151 TkStatePrintProc, (ClientData) 2
152 };
153 static Tk_CustomOption tagsOption = {
154 Tk_CanvasTagsParseProc,
155 Tk_CanvasTagsPrintProc, (ClientData) NULL
156 };
157 static Tk_CustomOption dashOption = {
158 TkCanvasDashParseProc,
159 TkCanvasDashPrintProc, (ClientData) NULL
160 };
161 static Tk_CustomOption tileOption = {
162 Tk_TileParseProc,
163 Tk_TilePrintProc, (ClientData) NULL
164 };
165 static Tk_CustomOption offsetOption = {
166 Tk_OffsetParseProc,
167 Tk_OffsetPrintProc,
168 (ClientData) (TK_OFFSET_RELATIVE|TK_OFFSET_INDEX)
169 };
170 static Tk_CustomOption pixelOption = {
171 Tk_PixelParseProc,
172 Tk_PixelPrintProc, (ClientData) NULL
173 };
174
175 static Tk_ConfigSpec configSpecs[] = {
176 {TK_CONFIG_CUSTOM, "-activedash", (char *) NULL, (char *) NULL,
177 (char *) NULL, Tk_Offset(LineItem, outline.activeDash),
178 TK_CONFIG_NULL_OK, &dashOption},
179 {TK_CONFIG_COLOR, "-activefill", (char *) NULL, (char *) NULL,
180 (char *) NULL, Tk_Offset(LineItem, outline.activeColor),
181 TK_CONFIG_NULL_OK},
182 {TK_CONFIG_BITMAP, "-activestipple", (char *) NULL, (char *) NULL,
183 (char *) NULL, Tk_Offset(LineItem, outline.activeStipple),
184 TK_CONFIG_NULL_OK},
185 {TK_CONFIG_CUSTOM, "-activewidth", (char *) NULL, (char *) NULL,
186 "0.0", Tk_Offset(LineItem, outline.activeWidth),
187 TK_CONFIG_DONT_SET_DEFAULT, &pixelOption},
188 {TK_CONFIG_CUSTOM, "-arrow", (char *) NULL, (char *) NULL,
189 "none", Tk_Offset(LineItem, arrow), TK_CONFIG_DONT_SET_DEFAULT, &arrowOption},
190 {TK_CONFIG_CUSTOM, "-arrowshape", (char *) NULL, (char *) NULL,
191 "8 10 3", Tk_Offset(LineItem, arrowShapeA),
192 TK_CONFIG_DONT_SET_DEFAULT, &arrowShapeOption},
193 {TK_CONFIG_CAP_STYLE, "-capstyle", (char *) NULL, (char *) NULL,
194 "butt", Tk_Offset(LineItem, capStyle), TK_CONFIG_DONT_SET_DEFAULT},
195 {TK_CONFIG_COLOR, "-fill", (char *) NULL, (char *) NULL,
196 "black", Tk_Offset(LineItem, outline.color), TK_CONFIG_NULL_OK},
197 {TK_CONFIG_CUSTOM, "-dash", (char *) NULL, (char *) NULL,
198 (char *) NULL, Tk_Offset(LineItem, outline.dash),
199 TK_CONFIG_NULL_OK, &dashOption},
200 {TK_CONFIG_PIXELS, "-dashoffset", (char *) NULL, (char *) NULL,
201 "0", Tk_Offset(LineItem, outline.offset),
202 TK_CONFIG_DONT_SET_DEFAULT},
203 {TK_CONFIG_CUSTOM, "-disableddash", (char *) NULL, (char *) NULL,
204 (char *) NULL, Tk_Offset(LineItem, outline.disabledDash),
205 TK_CONFIG_NULL_OK, &dashOption},
206 {TK_CONFIG_COLOR, "-disabledfill", (char *) NULL, (char *) NULL,
207 (char *) NULL, Tk_Offset(LineItem, outline.disabledColor),
208 TK_CONFIG_NULL_OK},
209 {TK_CONFIG_BITMAP, "-disabledstipple", (char *) NULL, (char *) NULL,
210 (char *) NULL, Tk_Offset(LineItem, outline.disabledStipple),
211 TK_CONFIG_NULL_OK},
212 {TK_CONFIG_CUSTOM, "-disabledwidth", (char *) NULL, (char *) NULL,
213 "0.0", Tk_Offset(LineItem, outline.disabledWidth),
214 TK_CONFIG_DONT_SET_DEFAULT, &pixelOption},
215 {TK_CONFIG_JOIN_STYLE, "-joinstyle", (char *) NULL, (char *) NULL,
216 "round", Tk_Offset(LineItem, joinStyle), TK_CONFIG_DONT_SET_DEFAULT},
217 {TK_CONFIG_CUSTOM, "-offset", (char *) NULL, (char *) NULL,
218 "0 0", Tk_Offset(LineItem, outline.tsoffset),
219 TK_CONFIG_DONT_SET_DEFAULT, &offsetOption},
220 {TK_CONFIG_CUSTOM, "-smooth", (char *) NULL, (char *) NULL,
221 "0", Tk_Offset(LineItem, smooth),
222 TK_CONFIG_DONT_SET_DEFAULT, &smoothOption},
223 {TK_CONFIG_INT, "-splinesteps", (char *) NULL, (char *) NULL,
224 "12", Tk_Offset(LineItem, splineSteps), TK_CONFIG_DONT_SET_DEFAULT},
225 {TK_CONFIG_CUSTOM, "-state", (char *) NULL, (char *) NULL,
226 (char *) NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK,
227 &stateOption},
228 {TK_CONFIG_BITMAP, "-stipple", (char *) NULL, (char *) NULL,
229 (char *) NULL, Tk_Offset(LineItem, outline.stipple),
230 TK_CONFIG_NULL_OK},
231 {TK_CONFIG_CUSTOM, "-tags", (char *) NULL, (char *) NULL,
232 (char *) NULL, 0, TK_CONFIG_NULL_OK, &tagsOption},
233 {TK_CONFIG_CUSTOM, "-width", (char *) NULL, (char *) NULL,
234 "1.0", Tk_Offset(LineItem, outline.width),
235 TK_CONFIG_DONT_SET_DEFAULT, &pixelOption},
236 {TK_CONFIG_CALLBACK, "-updatecommand", (char *) NULL, (char *) NULL,
237 (char *) NULL, Tk_Offset(Tk_Item, updateCmd), TK_CONFIG_NULL_OK},
238 {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
239 (char *) NULL, 0, 0}
240 };
241
242 /*
243 * The structures below defines the line item type by means
244 * of procedures that can be invoked by generic item code.
245 */
246
247 Tk_ItemType tkLineType = {
248 "line", /* name */
249 sizeof(LineItem), /* itemSize */
250 CreateLine, /* createProc */
251 configSpecs, /* configSpecs */
252 ConfigureLine, /* configureProc */
253 LineCoords, /* coordProc */
254 DeleteLine, /* deleteProc */
255 DisplayLine, /* displayProc */
256 TK_CONFIG_OBJS, /* flags */
257 LineToPoint, /* pointProc */
258 LineToArea, /* areaProc */
259 LineToPostscript, /* postscriptProc */
260 ScaleLine, /* scaleProc */
261 TranslateLine, /* translateProc */
262 GetLineIndex, /* indexProc */
263 (Tk_ItemCursorProc *) NULL, /* icursorProc */
264 (Tk_ItemSelectionProc *) NULL, /* selectionProc */
265 LineInsert, /* insertProc */
266 LineDeleteCoords, /* dTextProc */
267 (Tk_ItemType *) NULL, /* nextPtr */
268 (Tk_ItemBboxProc *) ComputeLineBbox,/* bboxProc */
269 Tk_Offset(Tk_VisitorType, visitLine), /* acceptProc */
270 NULL, /* getCoordProc */
271 NULL /* setCoordProc */
272 };
273
274 /*
275 * The definition below determines how large are static arrays
276 * used to hold spline points (splines larger than this have to
277 * have their arrays malloc-ed).
278 */
279
280 #define MAX_STATIC_POINTS 200
281
282 /*
283 *--------------------------------------------------------------
284 *
285 * CreateLine --
286 *
287 * This procedure is invoked to create a new line item in
288 * a canvas.
289 *
290 * Results:
291 * A standard Tcl return value. If an error occurred in
292 * creating the item, then an error message is left in
293 * the interp's result; in this case itemPtr is left uninitialized,
294 * so it can be safely freed by the caller.
295 *
296 * Side effects:
297 * A new line item is created.
298 *
299 *--------------------------------------------------------------
300 */
301
302 static int
303 CreateLine(interp, canvas, itemPtr, objc, objv)
304 Tcl_Interp *interp; /* Interpreter for error reporting. */
305 Tk_Canvas canvas; /* Canvas to hold new item. */
306 Tk_Item *itemPtr; /* Record to hold new item; header
307 * has been initialized by caller. */
308 int objc; /* Number of arguments in objv. */
309 Tcl_Obj *CONST objv[]; /* Arguments describing line. */
310 {
311 LineItem *linePtr = (LineItem *) itemPtr;
312 int i;
313
314 if (objc == 0) {
315 panic("canvas did not pass any coords\n");
316 }
317
318 /*
319 * Carry out initialization that is needed to set defaults and to
320 * allow proper cleanup after errors during the the remainder of
321 * this procedure.
322 */
323
324 Tk_CreateOutline(&(linePtr->outline));
325 linePtr->canvas = canvas;
326 linePtr->numPoints = 0;
327 linePtr->coordPtr = NULL;
328 linePtr->capStyle = CapButt;
329 linePtr->joinStyle = JoinRound;
330 linePtr->arrowGC = None;
331 linePtr->arrow = ARROWS_NONE;
332 linePtr->arrowShapeA = (float)8.0;
333 linePtr->arrowShapeB = (float)10.0;
334 linePtr->arrowShapeC = (float)3.0;
335 linePtr->firstArrowPtr = NULL;
336 linePtr->lastArrowPtr = NULL;
337 linePtr->smooth = (Tk_SmoothMethod *) NULL;
338 linePtr->splineSteps = 12;
339
340 /*
341 * Count the number of points and then parse them into a point
342 * array. Leading arguments are assumed to be points if they
343 * start with a digit or a minus sign followed by a digit.
344 */
345
346 for (i = 1; i < objc; i++) {
347 char *arg = Tcl_GetString(objv[i]);
348 if ((arg[0] == '-') && (arg[1] >= 'a') && (arg[1] <= 'z')) {
349 break;
350 }
351 }
352 if (LineCoords(interp, canvas, itemPtr, i, objv) != TCL_OK) {
353 goto error;
354 }
355 if (ConfigureLine(interp, canvas, itemPtr, objc-i, objv+i, 0) == TCL_OK) {
356 return TCL_OK;
357 }
358
359 error:
360 DeleteLine(canvas, itemPtr, Tk_Display(Tk_CanvasTkwin(canvas)));
361 return TCL_ERROR;
362 }
363
364 /*
365 *--------------------------------------------------------------
366 *
367 * LineCoords --
368 *
369 * This procedure is invoked to process the "coords" widget
370 * command on lines. See the user documentation for details
371 * on what it does.
372 *
373 * Results:
374 * Returns TCL_OK or TCL_ERROR, and sets the interp's result.
375 *
376 * Side effects:
377 * The coordinates for the given item may be changed.
378 *
379 *--------------------------------------------------------------
380 */
381
382 static int
383 LineCoords(interp, canvas, itemPtr, objc, objv)
384 Tcl_Interp *interp; /* Used for error reporting. */
385 Tk_Canvas canvas; /* Canvas containing item. */
386 Tk_Item *itemPtr; /* Item whose coordinates are to be
387 * read or modified. */
388 int objc; /* Number of coordinates supplied in
389 * objv. */
390 Tcl_Obj *CONST objv[]; /* Array of coordinates: x1, y1,
391 * x2, y2, ... */
392 {
393 LineItem *linePtr = (LineItem *) itemPtr;
394 int i, numPoints;
395 double *coordPtr;
396
397 if (objc == 0) {
398 int numCoords;
399 Tcl_Obj *subobj, *obj = Tcl_NewObj();
400
401 numCoords = 2*linePtr->numPoints;
402 if (linePtr->firstArrowPtr != NULL) {
403 coordPtr = linePtr->firstArrowPtr;
404 } else {
405 coordPtr = linePtr->coordPtr;
406 }
407 for (i = 0; i < numCoords; i++, coordPtr++) {
408 if (i == 2) {
409 coordPtr = linePtr->coordPtr+2;
410 }
411 if ((linePtr->lastArrowPtr != NULL) && (i == (numCoords-2))) {
412 coordPtr = linePtr->lastArrowPtr;
413 }
414 subobj = Tcl_NewDoubleObj(*coordPtr);
415 Tcl_ListObjAppendElement(interp, obj, subobj);
416 }
417 Tcl_SetObjResult(interp, obj);
418 return TCL_OK;
419 }
420 if (objc == 1) {
421 if (Tcl_ListObjGetElements(interp, objv[0], &objc,
422 (Tcl_Obj ***) &objv) != TCL_OK) {
423 return TCL_ERROR;
424 }
425 }
426 if (objc & 1) {
427 char buf[64 + TCL_INTEGER_SPACE];
428 sprintf(buf, "wrong # coordinates: expected an even number, got %d",
429 objc);
430 Tcl_SetResult(interp, buf, TCL_VOLATILE);
431 return TCL_ERROR;
432 } else if (objc < 4) {
433 char buf[64 + TCL_INTEGER_SPACE];
434 sprintf(buf, "wrong # coordinates: expected at least 4, got %d", objc);
435 Tcl_SetResult(interp, buf, TCL_VOLATILE);
436 return TCL_ERROR;
437 } else {
438 numPoints = objc/2;
439 if (linePtr->numPoints != numPoints) {
440 coordPtr = (double *) ckalloc((unsigned)
441 (sizeof(double) * objc));
442 if (linePtr->coordPtr != NULL) {
443 ckfree((char *) linePtr->coordPtr);
444 }
445 linePtr->coordPtr = coordPtr;
446 linePtr->numPoints = numPoints;
447 }
448 coordPtr = linePtr->coordPtr;
449 for (i = 0; i <objc; i++) {
450 if (Tk_CanvasGetCoordFromObj(interp, canvas, objv[i],
451 coordPtr++) != TCL_OK) {
452 return TCL_ERROR;
453 }
454 }
455
456 /*
457 * Update arrowheads by throwing away any existing arrow-head
458 * information and calling ConfigureArrows to recompute it.
459 */
460
461 if (linePtr->firstArrowPtr != NULL) {
462 ckfree((char *) linePtr->firstArrowPtr);
463 linePtr->firstArrowPtr = NULL;
464 }
465 if (linePtr->lastArrowPtr != NULL) {
466 ckfree((char *) linePtr->lastArrowPtr);
467 linePtr->lastArrowPtr = NULL;
468 }
469 if (linePtr->arrow != ARROWS_NONE) {
470 ConfigureArrows(canvas, linePtr);
471 }
472 ComputeLineBbox(canvas, linePtr);
473 }
474 return TCL_OK;
475 }
476
477 /*
478 *--------------------------------------------------------------
479 *
480 * ConfigureLine --
481 *
482 * This procedure is invoked to configure various aspects
483 * of a line item such as its background color.
484 *
485 * Results:
486 * A standard Tcl result code. If an error occurs, then
487 * an error message is left in the interp's result.
488 *
489 * Side effects:
490 * Configuration information, such as colors and stipple
491 * patterns, may be set for itemPtr.
492 *
493 *--------------------------------------------------------------
494 */
495
496 static int
497 ConfigureLine(interp, canvas, itemPtr, objc, objv, flags)
498 Tcl_Interp *interp; /* Used for error reporting. */
499 Tk_Canvas canvas; /* Canvas containing itemPtr. */
500 Tk_Item *itemPtr; /* Line item to reconfigure. */
501 int objc; /* Number of elements in objv. */
502 Tcl_Obj *CONST objv[]; /* Arguments describing things to configure. */
503 int flags; /* Flags to pass to Tk_ConfigureWidget. */
504 {
505 LineItem *linePtr = (LineItem *) itemPtr;
506 XGCValues gcValues;
507 GC newGC, arrowGC;
508 unsigned long mask;
509 Tk_Window tkwin;
510 Tk_State state;
511
512 tkwin = Tk_CanvasTkwin(canvas);
513 if (TCL_OK != Tk_ConfigureWidget(interp, tkwin, configSpecs, objc,
514 objv, (char *) linePtr, flags|TK_CONFIG_OBJS)) {
515 return TCL_ERROR;
516 }
517
518 /*
519 * A few of the options require additional processing, such as
520 * graphics contexts.
521 */
522
523 state = Tk_GetItemState(canvas, itemPtr);
524
525 if (linePtr->outline.activeWidth > linePtr->outline.width ||
526 linePtr->outline.activeDash.number != 0 ||
527 linePtr->outline.activeColor != NULL ||
528 linePtr->outline.activeStipple != None) {
529 itemPtr->redraw_flags |= TK_ITEM_STATE_DEPENDANT;
530 } else {
531 itemPtr->redraw_flags &= ~TK_ITEM_STATE_DEPENDANT;
532 }
533 mask = Tk_ConfigOutlineGC(&gcValues, canvas, itemPtr,
534 &(linePtr->outline));
535 if (mask) {
536 if (linePtr->arrow == ARROWS_NONE) {
537 gcValues.cap_style = linePtr->capStyle;
538 mask |= GCCapStyle;
539 }
540 gcValues.join_style = linePtr->joinStyle;
541 mask |= GCJoinStyle;
542 newGC = Tk_GetGC(tkwin, mask, &gcValues);
543 gcValues.line_width = 0;
544 arrowGC = Tk_GetGC(tkwin, mask, &gcValues);
545 } else {
546 newGC = arrowGC = None;
547 }
548 if (linePtr->outline.gc != None) {
549 Tk_FreeGC(Tk_Display(tkwin), linePtr->outline.gc);
550 }
551 if (linePtr->arrowGC != None) {
552 Tk_FreeGC(Tk_Display(tkwin), linePtr->arrowGC);
553 }
554 linePtr->outline.gc = newGC;
555 linePtr->arrowGC = arrowGC;
556
557 /*
558 * Keep spline parameters within reasonable limits.
559 */
560
561 if (linePtr->splineSteps < 1) {
562 linePtr->splineSteps = 1;
563 } else if (linePtr->splineSteps > 100) {
564 linePtr->splineSteps = 100;
565 }
566
567 if ((!linePtr->numPoints) || (state==TK_STATE_HIDDEN)) {
568 ComputeLineBbox(canvas, linePtr);
569 return TCL_OK;
570 }
571
572 /*
573 * Setup arrowheads, if needed. If arrowheads are turned off,
574 * restore the line's endpoints (they were shortened when the
575 * arrowheads were added).
576 */
577
578 if ((linePtr->firstArrowPtr != NULL) && (linePtr->arrow != ARROWS_FIRST)
579 && (linePtr->arrow != ARROWS_BOTH)) {
580 linePtr->coordPtr[0] = linePtr->firstArrowPtr[0];
581 linePtr->coordPtr[1] = linePtr->firstArrowPtr[1];
582 ckfree((char *) linePtr->firstArrowPtr);
583 linePtr->firstArrowPtr = NULL;
584 }
585 if ((linePtr->lastArrowPtr != NULL) && (linePtr->arrow != ARROWS_LAST)
586 && (linePtr->arrow != ARROWS_BOTH)) {
587 int i;
588
589 i = 2*(linePtr->numPoints-1);
590 linePtr->coordPtr[i] = linePtr->lastArrowPtr[0];
591 linePtr->coordPtr[i+1] = linePtr->lastArrowPtr[1];
592 ckfree((char *) linePtr->lastArrowPtr);
593 linePtr->lastArrowPtr = NULL;
594 }
595 if (linePtr->arrow != ARROWS_NONE) {
596 ConfigureArrows(canvas, linePtr);
597 }
598
599 /*
600 * Recompute bounding box for line.
601 */
602
603 ComputeLineBbox(canvas, linePtr);
604
605 return TCL_OK;
606 }
607
608 /*
609 *--------------------------------------------------------------
610 *
611 * DeleteLine --
612 *
613 * This procedure is called to clean up the data structure
614 * associated with a line item.
615 *
616 * Results:
617 * None.
618 *
619 * Side effects:
620 * Resources associated with itemPtr are released.
621 *
622 *--------------------------------------------------------------
623 */
624
625 static void
626 DeleteLine(canvas, itemPtr, display)
627 Tk_Canvas canvas; /* Info about overall canvas widget. */
628 Tk_Item *itemPtr; /* Item that is being deleted. */
629 Display *display; /* Display containing window for
630 * canvas. */
631 {
632 LineItem *linePtr = (LineItem *) itemPtr;
633
634 Tk_DeleteOutline(display, &(linePtr->outline));
635 if (linePtr->coordPtr != NULL) {
636 ckfree((char *) linePtr->coordPtr);
637 }
638 if (linePtr->arrowGC != None) {
639 Tk_FreeGC(display, linePtr->arrowGC);
640 }
641 if (linePtr->firstArrowPtr != NULL) {
642 ckfree((char *) linePtr->firstArrowPtr);
643 }
644 if (linePtr->lastArrowPtr != NULL) {
645 ckfree((char *) linePtr->lastArrowPtr);
646 }
647 }
648
649 /*
650 *--------------------------------------------------------------
651 *
652 * ComputeLineBbox --
653 *
654 * This procedure is invoked to compute the bounding box of
655 * all the pixels that may be drawn as part of a line.
656 *
657 * Results:
658 * None.
659 *
660 * Side effects:
661 * The fields x1, y1, x2, and y2 are updated in the header
662 * for itemPtr.
663 *
664 *--------------------------------------------------------------
665 */
666
667 static void
668 ComputeLineBbox(canvas, linePtr)
669 Tk_Canvas canvas; /* Canvas that contains item. */
670 LineItem *linePtr; /* Item whose bbos is to be
671 * recomputed. */
672 {
673 double *coordPtr;
674 int i, intWidth;
675 double width;
676 Tk_State state = Tk_GetItemState(canvas, &linePtr->header);
677 Tk_TSOffset *tsoffset;
678
679 if (!(linePtr->numPoints) || (state==TK_STATE_HIDDEN)) {
680 linePtr->header.x1 = -1;
681 linePtr->header.x2 = -1;
682 linePtr->header.y1 = -1;
683 linePtr->header.y2 = -1;
684 return;
685 }
686
687 width = linePtr->outline.width;
688 if (((TkCanvas *)canvas)->currentItemPtr == (Tk_Item *)linePtr) {
689 if (linePtr->outline.activeWidth>width) {
690 width = linePtr->outline.activeWidth;
691 }
692 } else if (state==TK_STATE_DISABLED) {
693 if (linePtr->outline.disabledWidth>0) {
694 width = linePtr->outline.disabledWidth;
695 }
696 }
697
698 coordPtr = linePtr->coordPtr;
699 linePtr->header.x1 = linePtr->header.x2 = (int) *coordPtr;
700 linePtr->header.y1 = linePtr->header.y2 = (int) coordPtr[1];
701
702 /*
703 * Compute the bounding box of all the points in the line,
704 * then expand in all directions by the line's width to take
705 * care of butting or rounded corners and projecting or
706 * rounded caps. This expansion is an overestimate (worst-case
707 * is square root of two over two) but it's simple. Don't do
708 * anything special for curves. This causes an additional
709 * overestimate in the bounding box, but is faster.
710 */
711
712 for (i = 1, coordPtr = linePtr->coordPtr+2; i < linePtr->numPoints;
713 i++, coordPtr += 2) {
714 TkIncludePoint((Tk_Item *) linePtr, coordPtr);
715 }
716 width = linePtr->outline.width;
717 if (width < 1.0) {
718 width = 1.0;
719 }
720 if (linePtr->arrow != ARROWS_NONE) {
721 if (linePtr->arrow != ARROWS_LAST) {
722 TkIncludePoint((Tk_Item *) linePtr, linePtr->firstArrowPtr);
723 }
724 if (linePtr->arrow != ARROWS_FIRST) {
725 TkIncludePoint((Tk_Item *) linePtr, linePtr->lastArrowPtr);
726 }
727 }
728
729 tsoffset = &linePtr->outline.tsoffset;
730 if (tsoffset->flags & TK_OFFSET_INDEX) {
731 double *coordPtr = linePtr->coordPtr + (tsoffset->flags & ~TK_OFFSET_INDEX);
732 if (tsoffset->flags <= 0) {
733 coordPtr = linePtr->coordPtr;
734 if ((linePtr->arrow == ARROWS_FIRST) || (linePtr->arrow == ARROWS_BOTH)) {
735 coordPtr = linePtr->firstArrowPtr;
736 }
737 }
738 if (tsoffset->flags > (linePtr->numPoints * 2)) {
739 coordPtr = linePtr->coordPtr + (linePtr->numPoints * 2);
740 if ((linePtr->arrow == ARROWS_LAST) || (linePtr->arrow == ARROWS_BOTH)) {
741 coordPtr = linePtr->lastArrowPtr;
742 }
743 }
744 tsoffset->xoffset = (int) (coordPtr[0] + 0.5);
745 tsoffset->yoffset = (int) (coordPtr[1] + 0.5);
746 } else {
747 if (tsoffset->flags & TK_OFFSET_LEFT) {
748 tsoffset->xoffset = linePtr->header.x1;
749 } else if (tsoffset->flags & TK_OFFSET_CENTER) {
750 tsoffset->xoffset = (linePtr->header.x1 + linePtr->header.x2)/2;
751 } else if (tsoffset->flags & TK_OFFSET_RIGHT) {
752 tsoffset->xoffset = linePtr->header.x2;
753 }
754 if (tsoffset->flags & TK_OFFSET_TOP) {
755 tsoffset->yoffset = linePtr->header.y1;
756 } else if (tsoffset->flags & TK_OFFSET_MIDDLE) {
757 tsoffset->yoffset = (linePtr->header.y1 + linePtr->header.y2)/2;
758 } else if (tsoffset->flags & TK_OFFSET_BOTTOM) {
759 tsoffset->yoffset = linePtr->header.y2;
760 }
761 }
762
763 intWidth = (int) (width + 0.5);
764 linePtr->header.x1 -= intWidth;
765 linePtr->header.x2 += intWidth;
766 linePtr->header.y1 -= intWidth;
767 linePtr->header.y2 += intWidth;
768
769 if (linePtr->numPoints==1) {
770 linePtr->header.x1 -= 1;
771 linePtr->header.x2 += 1;
772 linePtr->header.y1 -= 1;
773 linePtr->header.y2 += 1;
774 return;
775 }
776
777 /*
778 * For mitered lines, make a second pass through all the points.
779 * Compute the locations of the two miter vertex points and add
780 * those into the bounding box.
781 */
782
783 if (linePtr->joinStyle == JoinMiter) {
784 for (i = linePtr->numPoints, coordPtr = linePtr->coordPtr; i >= 3;
785 i--, coordPtr += 2) {
786 double miter[4];
787 int j;
788
789 if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4,
790 width, miter, miter+2)) {
791 for (j = 0; j < 4; j += 2) {
792 TkIncludePoint((Tk_Item *) linePtr, miter+j);
793 }
794 }
795 }
796 }
797
798 /*
799 * Add in the sizes of arrowheads, if any.
800 */
801
802 if (linePtr->arrow != ARROWS_NONE) {
803 if (linePtr->arrow != ARROWS_LAST) {
804 for (i = 0, coordPtr = linePtr->firstArrowPtr; i < PTS_IN_ARROW;
805 i++, coordPtr += 2) {
806 TkIncludePoint((Tk_Item *) linePtr, coordPtr);
807 }
808 }
809 if (linePtr->arrow != ARROWS_FIRST) {
810 for (i = 0, coordPtr = linePtr->lastArrowPtr; i < PTS_IN_ARROW;
811 i++, coordPtr += 2) {
812 TkIncludePoint((Tk_Item *) linePtr, coordPtr);
813 }
814 }
815 }
816
817 /*
818 * Add one more pixel of fudge factor just to be safe (e.g.
819 * X may round differently than we do).
820 */
821
822 linePtr->header.x1 -= 1;
823 linePtr->header.x2 += 1;
824 linePtr->header.y1 -= 1;
825 linePtr->header.y2 += 1;
826 }
827
828 /*
829 *--------------------------------------------------------------
830 *
831 * DisplayLine --
832 *
833 * This procedure is invoked to draw a line item in a given
834 * drawable.
835 *
836 * Results:
837 * None.
838 *
839 * Side effects:
840 * ItemPtr is drawn in drawable using the transformation
841 * information in canvas.
842 *
843 *--------------------------------------------------------------
844 */
845
846 static void
847 DisplayLine(canvas, itemPtr, display, drawable, x, y, width, height)
848 Tk_Canvas canvas; /* Canvas that contains item. */
849 Tk_Item *itemPtr; /* Item to be displayed. */
850 Display *display; /* Display on which to draw item. */
851 Drawable drawable; /* Pixmap or window in which to draw
852 * item. */
853 int x, y, width, height; /* Describes region of canvas that
854 * must be redisplayed (not used). */
855 {
856 LineItem *linePtr = (LineItem *) itemPtr;
857 XPoint staticPoints[MAX_STATIC_POINTS*3];
858 XPoint *pointPtr;
859 double linewidth;
860 int numPoints;
861 Tk_State state = Tk_GetItemState(canvas, itemPtr);
862 Pixmap stipple = linePtr->outline.stipple;
863
864 if ((!linePtr->numPoints)||(linePtr->outline.gc==None)) {
865 return;
866 }
867
868 linewidth = linePtr->outline.width;
869 if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) {
870 if (linePtr->outline.activeStipple != None) {
871 stipple = linePtr->outline.activeStipple;
872 }
873 if (linePtr->outline.activeWidth != linewidth) {
874 linewidth = linePtr->outline.activeWidth;
875 }
876 } else if (state==TK_STATE_DISABLED) {
877 if (linePtr->outline.disabledStipple != None) {
878 stipple = linePtr->outline.disabledStipple;
879 }
880 if (linePtr->outline.disabledWidth != linewidth) {
881 linewidth = linePtr->outline.disabledWidth;
882 }
883 }
884 /*
885 * Build up an array of points in screen coordinates. Use a
886 * static array unless the line has an enormous number of points;
887 * in this case, dynamically allocate an array. For smoothed lines,
888 * generate the curve points on each redisplay.
889 */
890
891 if ((linePtr->smooth) && (linePtr->numPoints > 2)) {
892 numPoints = linePtr->smooth->coordProc(canvas, (double *) NULL,
893 linePtr->numPoints, linePtr->splineSteps, (XPoint *) NULL,
894 (double *) NULL);
895 } else {
896 numPoints = linePtr->numPoints;
897 }
898
899 if (numPoints <= MAX_STATIC_POINTS) {
900 pointPtr = staticPoints;
901 } else {
902 pointPtr = (XPoint *)ckalloc((unsigned)(numPoints * 3*sizeof(XPoint)));
903 }
904
905 if ((linePtr->smooth) && (linePtr->numPoints > 2)) {
906 numPoints = linePtr->smooth->coordProc(canvas, linePtr->coordPtr,
907 linePtr->numPoints, linePtr->splineSteps, pointPtr,
908 (double *) NULL);
909 } else {
910 numPoints = TkCanvTranslatePath((TkCanvas*)canvas, numPoints,
911 linePtr->coordPtr, 0, pointPtr);
912 }
913
914 /*
915 * Display line, the free up line storage if it was dynamically
916 * allocated. If we're stippling, then modify the stipple offset
917 * in the GC. Be sure to reset the offset when done, since the
918 * GC is supposed to be read-only.
919 */
920
921 if (Tk_ChangeOutlineGC(canvas, itemPtr, &(linePtr->outline))) {
922 Tk_CanvasSetOffset(canvas, linePtr->arrowGC, &linePtr->outline.tsoffset);
923 }
924 if (numPoints>1) {
925 XDrawLines(display, drawable, linePtr->outline.gc, pointPtr, numPoints,
926 CoordModeOrigin);
927 } else {
928 int intwidth = (int) (linewidth + 0.5);
929 if (intwidth<1) {
930 intwidth=1;
931 }
932 XFillArc(display, drawable, linePtr->outline.gc,
933 pointPtr->x - intwidth/2, pointPtr->y - intwidth/2,
934 (unsigned int)intwidth+1, (unsigned int)intwidth+1, 0, 64*360);
935 }
936 if (pointPtr != staticPoints) {
937 ckfree((char *) pointPtr);
938 }
939
940 /*
941 * Display arrowheads, if they are wanted.
942 */
943
944 if (linePtr->firstArrowPtr != NULL) {
945 TkFillPolygon(canvas, linePtr->firstArrowPtr, PTS_IN_ARROW,
946 display, drawable, linePtr->arrowGC, NULL);
947 }
948 if (linePtr->lastArrowPtr != NULL) {
949 TkFillPolygon(canvas, linePtr->lastArrowPtr, PTS_IN_ARROW,
950 display, drawable, linePtr->arrowGC, NULL);
951 }
952 if (Tk_ResetOutlineGC(canvas, itemPtr, &(linePtr->outline))) {
953 XSetTSOrigin(display, linePtr->arrowGC, 0, 0);
954 }
955 }
956
957 /*
958 *--------------------------------------------------------------
959 *
960 * LineInsert --
961 *
962 * Insert coords into a line item at a given index.
963 *
964 * Results:
965 * None.
966 *
967 * Side effects:
968 * The coords in the given item is modified.
969 *
970 *--------------------------------------------------------------
971 */
972
973 static void
974 LineInsert(canvas, itemPtr, beforeThis, obj)
975 Tk_Canvas canvas; /* Canvas containing text item. */
976 Tk_Item *itemPtr; /* Line item to be modified. */
977 int beforeThis; /* Index before which new coordinates
978 * are to be inserted. */
979 Tcl_Obj *obj; /* New coordinates to be inserted. */
980 {
981 LineItem *linePtr = (LineItem *) itemPtr;
982 int length, objc, i;
983 double *new, *coordPtr;
984 Tk_State state = Tk_GetItemState(canvas, itemPtr);
985
986 Tcl_Obj **objv;
987
988 if(state == TK_STATE_NULL) {
989 state = ((TkCanvas *)canvas)->canvas_state;
990 }
991
992 if (!obj || (Tcl_ListObjGetElements((Tcl_Interp *) NULL, obj, &objc, &objv) != TCL_OK)
993 || !objc || objc&1) {
994 return;
995 }
996 length = 2*linePtr->numPoints;
997 if (beforeThis < 0) {
998 beforeThis = 0;
999 }
1000 if (beforeThis > length) {
1001 beforeThis = length;
1002 }
1003 if (linePtr->firstArrowPtr != NULL) {
1004 linePtr->coordPtr[0] = linePtr->firstArrowPtr[0];
1005 linePtr->coordPtr[1] = linePtr->firstArrowPtr[1];
1006 }
1007 if (linePtr->lastArrowPtr != NULL) {
1008 linePtr->coordPtr[length-2] = linePtr->lastArrowPtr[0];
1009 linePtr->coordPtr[length-1] = linePtr->lastArrowPtr[1];
1010 }
1011 new = (double *) ckalloc((unsigned)(sizeof(double) * (length + objc)));
1012 for(i=0; i<beforeThis; i++) {
1013 new[i] = linePtr->coordPtr[i];
1014 }
1015 for(i=0; i<objc; i++) {
1016 if (Tcl_GetDoubleFromObj((Tcl_Interp *) NULL,objv[i],
1017 new+(i+beforeThis))!=TCL_OK) {
1018 Tcl_ResetResult(((TkCanvas *)canvas)->interp);
1019 ckfree((char *) new);
1020 return;
1021 }
1022 }
1023
1024 for(i=beforeThis; i<length; i++) {
1025 new[i+objc] = linePtr->coordPtr[i];
1026 }
1027 if(linePtr->coordPtr) ckfree((char *)linePtr->coordPtr);
1028 linePtr->coordPtr = new;
1029 linePtr->numPoints = (length + objc)/2;
1030
1031 if ((length>3) && (state != TK_STATE_HIDDEN)) {
1032 /*
1033 * This is some optimizing code that will result that only the part
1034 * of the polygon that changed (and the objects that are overlapping
1035 * with that part) need to be redrawn. A special flag is set that
1036 * instructs the general canvas code not to redraw the whole
1037 * object. If this flag is not set, the canvas will do the redrawing,
1038 * otherwise I have to do it here.
1039 */
1040 itemPtr->redraw_flags |= TK_ITEM_DONT_REDRAW;
1041
1042 if (beforeThis>0) {beforeThis -= 2; objc+=2; }
1043 if ((beforeThis+objc)<length) objc+=2;
1044 if (linePtr->smooth) {
1045 if(beforeThis>0) {
1046 beforeThis-=2; objc+=2;
1047 }
1048 if((beforeThis+objc+2)<length) {
1049 objc+=2;
1050 }
1051 }
1052 itemPtr->x1 = itemPtr->x2 = (int) linePtr->coordPtr[beforeThis];
1053 itemPtr->y1 = itemPtr->y2 = (int) linePtr->coordPtr[beforeThis+1];
1054 if ((linePtr->firstArrowPtr != NULL) && (beforeThis<1)) {
1055 /* include old first arrow */
1056 for (i = 0, coordPtr = linePtr->firstArrowPtr; i < PTS_IN_ARROW;
1057 i++, coordPtr += 2) {
1058 TkIncludePoint(itemPtr, coordPtr);
1059 }
1060 }
1061 if ((linePtr->lastArrowPtr != NULL) && ((beforeThis+objc)>=length)) {
1062 /* include old last arrow */
1063 for (i = 0, coordPtr = linePtr->lastArrowPtr; i < PTS_IN_ARROW;
1064 i++, coordPtr += 2) {
1065 TkIncludePoint(itemPtr, coordPtr);
1066 }
1067 }
1068 coordPtr = linePtr->coordPtr+beforeThis+2;
1069 for(i=2; i<objc; i+=2) {
1070 TkIncludePoint(itemPtr, coordPtr);
1071 coordPtr+=2;
1072 }
1073 }
1074 if (linePtr->firstArrowPtr != NULL) {
1075 ckfree((char *) linePtr->firstArrowPtr);
1076 linePtr->firstArrowPtr = NULL;
1077 }
1078 if (linePtr->lastArrowPtr != NULL) {
1079 ckfree((char *) linePtr->lastArrowPtr);
1080 linePtr->lastArrowPtr = NULL;
1081 }
1082 if (linePtr->arrow != ARROWS_NONE) {
1083 ConfigureArrows(canvas, linePtr);
1084 }
1085
1086 if(itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW) {
1087 double width;
1088 int intWidth;
1089 if ((linePtr->firstArrowPtr != NULL) && (beforeThis>2)) {
1090 /* include new first arrow */
1091 for (i = 0, coordPtr = linePtr->firstArrowPtr; i < PTS_IN_ARROW;
1092 i++, coordPtr += 2) {
1093 TkIncludePoint(itemPtr, coordPtr);
1094 }
1095 }
1096 if ((linePtr->lastArrowPtr != NULL) && ((beforeThis+objc)<(length-2))) {
1097 /* include new right arrow */
1098 for (i = 0, coordPtr = linePtr->lastArrowPtr; i < PTS_IN_ARROW;
1099 i++, coordPtr += 2) {
1100 TkIncludePoint(itemPtr, coordPtr);
1101 }
1102 }
1103 width = linePtr->outline.width;
1104 if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) {
1105 if (linePtr->outline.activeWidth>width) {
1106 width = linePtr->outline.activeWidth;
1107 }
1108 } else if (state==TK_STATE_DISABLED) {
1109 if (linePtr->outline.disabledWidth>0) {
1110 width = linePtr->outline.disabledWidth;
1111 }
1112 }
1113 intWidth = (int) (width + 0.5);
1114 if (intWidth < 1) {
1115 intWidth = 1;
1116 }
1117 itemPtr->x1 -= intWidth; itemPtr->y1 -= intWidth;
1118 itemPtr->x2 += intWidth; itemPtr->y2 += intWidth;
1119 Tk_CanvasEventuallyRedraw(canvas, itemPtr->x1, itemPtr->y1,
1120 itemPtr->x2, itemPtr->y2);
1121 }
1122
1123 ComputeLineBbox(canvas, linePtr);
1124 }
1125
1126 /*
1127 *--------------------------------------------------------------
1128 *
1129 * LineDeleteCoords --
1130 *
1131 * Delete one or more coordinates from a line item.
1132 *
1133 * Results:
1134 * None.
1135 *
1136 * Side effects:
1137 * Characters between "first" and "last", inclusive, get
1138 * deleted from itemPtr.
1139 *
1140 *--------------------------------------------------------------
1141 */
1142
1143 static void
1144 LineDeleteCoords(canvas, itemPtr, first, last)
1145 Tk_Canvas canvas; /* Canvas containing itemPtr. */
1146 Tk_Item *itemPtr; /* Item in which to delete characters. */
1147 int first; /* Index of first character to delete. */
1148 int last; /* Index of last character to delete. */
1149 {
1150 LineItem *linePtr = (LineItem *) itemPtr;
1151 int count, i, first1, last1;
1152 int length = 2*linePtr->numPoints;
1153 double *coordPtr;
1154 Tk_State state = Tk_GetItemState(canvas, itemPtr);
1155
1156 first &= -2;
1157 last &= -2;
1158
1159 if (first < 0) {
1160 first = 0;
1161 }
1162 if (last >= length) {
1163 last = length-2;
1164 }
1165 if (first > last) {
1166 return;
1167 }
1168 if (linePtr->firstArrowPtr != NULL) {
1169 linePtr->coordPtr[0] = linePtr->firstArrowPtr[0];
1170 linePtr->coordPtr[1] = linePtr->firstArrowPtr[1];
1171 }
1172 if (linePtr->lastArrowPtr != NULL) {
1173 linePtr->coordPtr[length-2] = linePtr->lastArrowPtr[0];
1174 linePtr->coordPtr[length-1] = linePtr->lastArrowPtr[1];
1175 }
1176 first1 = first; last1 = last;
1177 if(first1>0) first1 -= 2;
1178 if(last1<length-2) last1 += 2;
1179 if (linePtr->smooth) {
1180 if(first1>0) first1 -= 2;
1181 if(last1<length-2) last1 += 2;
1182 }
1183
1184 if((first1<2) && (last1 >= length-2)) {
1185 /*
1186 * This is some optimizing code that will result that only the part
1187 * of the line that changed (and the objects that are overlapping
1188 * with that part) need to be redrawn. A special flag is set that
1189 * instructs the general canvas code not to redraw the whole
1190 * object. If this flag is set, the redrawing has to be done here,
1191 * otherwise the general Canvas code will take care of it.
1192 */
1193
1194 itemPtr->redraw_flags |= TK_ITEM_DONT_REDRAW;
1195 itemPtr->x1 = itemPtr->x2 = (int) linePtr->coordPtr[first1];
1196 itemPtr->y1 = itemPtr->y2 = (int) linePtr->coordPtr[first1+1];
1197 if ((linePtr->firstArrowPtr != NULL) && (first1<2)) {
1198 /* include old first arrow */
1199 for (i = 0, coordPtr = linePtr->firstArrowPtr; i < PTS_IN_ARROW;
1200 i++, coordPtr += 2) {
1201 TkIncludePoint(itemPtr, coordPtr);
1202 }
1203 }
1204 if ((linePtr->lastArrowPtr != NULL) && (last1>=length-2)) {
1205 /* include old last arrow */
1206 for (i = 0, coordPtr = linePtr->lastArrowPtr; i < PTS_IN_ARROW;
1207 i++, coordPtr += 2) {
1208 TkIncludePoint(itemPtr, coordPtr);
1209 }
1210 }
1211 coordPtr = linePtr->coordPtr+first1+2;
1212 for (i=first1+2; i<=last1; i+=2) {
1213 TkIncludePoint(itemPtr, coordPtr);
1214 coordPtr+=2;
1215 }
1216 }
1217
1218 count = last + 2 - first;
1219 for (i=last+2; i<length; i++) {
1220 linePtr->coordPtr[i-count] = linePtr->coordPtr[i];
1221 }
1222 linePtr->numPoints -= count/2;
1223 if (linePtr->firstArrowPtr != NULL) {
1224 ckfree((char *) linePtr->firstArrowPtr);
1225 linePtr->firstArrowPtr = NULL;
1226 }
1227 if (linePtr->lastArrowPtr != NULL) {
1228 ckfree((char *) linePtr->lastArrowPtr);
1229 linePtr->lastArrowPtr = NULL;
1230 }
1231 if (linePtr->arrow != ARROWS_NONE) {
1232 ConfigureArrows(canvas, linePtr);
1233 }
1234 if(itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW) {
1235 double width;
1236 int intWidth;
1237 if ((linePtr->firstArrowPtr != NULL) && (first1<4)) {
1238 /* include new first arrow */
1239 for (i = 0, coordPtr = linePtr->firstArrowPtr; i < PTS_IN_ARROW;
1240 i++, coordPtr += 2) {
1241 TkIncludePoint(itemPtr, coordPtr);
1242 }
1243 }
1244 if ((linePtr->lastArrowPtr != NULL) && (last1>(length-4))) {
1245 /* include new right arrow */
1246 for (i = 0, coordPtr = linePtr->lastArrowPtr; i < PTS_IN_ARROW;
1247 i++, coordPtr += 2) {
1248 TkIncludePoint(itemPtr, coordPtr);
1249 }
1250 }
1251 width = linePtr->outline.width;
1252 if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) {
1253 if (linePtr->outline.activeWidth>width) {
1254 width = linePtr->outline.activeWidth;
1255 }
1256 } else if (state==TK_STATE_DISABLED) {
1257 if (linePtr->outline.disabledWidth>0) {
1258 width = linePtr->outline.disabledWidth;
1259 }
1260 }
1261 intWidth = (int) (width + 0.5);
1262 if (intWidth < 1) {
1263 intWidth = 1;
1264 }
1265 itemPtr->x1 -= intWidth; itemPtr->y1 -= intWidth;
1266 itemPtr->x2 += intWidth; itemPtr->y2 += intWidth;
1267 Tk_CanvasEventuallyRedraw(canvas, itemPtr->x1, itemPtr->y1,
1268 itemPtr->x2, itemPtr->y2);
1269 }
1270 ComputeLineBbox(canvas, linePtr);
1271 }
1272
1273 /*
1274 *--------------------------------------------------------------
1275 *
1276 * LineToPoint --
1277 *
1278 * Computes the distance from a given point to a given
1279 * line, in canvas units.
1280 *
1281 * Results:
1282 * The return value is 0 if the point whose x and y coordinates
1283 * are pointPtr[0] and pointPtr[1] is inside the line. If the
1284 * point isn't inside the line then the return value is the
1285 * distance from the point to the line.
1286 *
1287 * Side effects:
1288 * None.
1289 *
1290 *--------------------------------------------------------------
1291 */
1292
1293 /* ARGSUSED */
1294 static double
1295 LineToPoint(canvas, itemPtr, pointPtr)
1296 Tk_Canvas canvas; /* Canvas containing item. */
1297 Tk_Item *itemPtr; /* Item to check against point. */
1298 double *pointPtr; /* Pointer to x and y coordinates. */
1299 {
1300 Tk_State state = Tk_GetItemState(canvas, itemPtr);
1301 LineItem *linePtr = (LineItem *) itemPtr;
1302 double *coordPtr, *linePoints;
1303 double staticSpace[2*MAX_STATIC_POINTS];
1304 double poly[10];
1305 double bestDist, dist, width;
1306 int numPoints, count;
1307 int changedMiterToBevel; /* Non-zero means that a mitered corner
1308 * had to be treated as beveled after all
1309 * because the angle was < 11 degrees. */
1310
1311 bestDist = 1.0e36;
1312
1313 /*
1314 * Handle smoothed lines by generating an expanded set of points
1315 * against which to do the check.
1316 */
1317
1318 width = linePtr->outline.width;
1319 if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) {
1320 if (linePtr->outline.activeWidth>width) {
1321 width = linePtr->outline.activeWidth;
1322 }
1323 } else if (state==TK_STATE_DISABLED) {
1324 if (linePtr->outline.disabledWidth>0) {
1325 width = linePtr->outline.disabledWidth;
1326 }
1327 }
1328
1329 if ((linePtr->smooth) && (linePtr->numPoints > 2)) {
1330 numPoints = linePtr->smooth->coordProc(canvas, (double *) NULL,
1331 linePtr->numPoints, linePtr->splineSteps, (XPoint *) NULL,
1332 (double *) NULL);
1333 if (numPoints <= MAX_STATIC_POINTS) {
1334 linePoints = staticSpace;
1335 } else {
1336 linePoints = (double *) ckalloc((unsigned)
1337 (2*numPoints*sizeof(double)));
1338 }
1339 numPoints = linePtr->smooth->coordProc(canvas, linePtr->coordPtr,
1340 linePtr->numPoints, linePtr->splineSteps, (XPoint *) NULL,
1341 linePoints);
1342 } else {
1343 numPoints = linePtr->numPoints;
1344 linePoints = linePtr->coordPtr;
1345 }
1346
1347 if (width < 1.0) {
1348 width = 1.0;
1349 }
1350
1351 if (!numPoints || itemPtr->state==TK_STATE_HIDDEN) {
1352 return bestDist;
1353 } else if (numPoints == 1) {
1354 bestDist = hypot(linePoints[0] - pointPtr[0], linePoints[1] - pointPtr[1])
1355 - width/2.0;
1356 if (bestDist < 0) bestDist = 0;
1357 return bestDist;
1358 }
1359
1360 /*
1361 * The overall idea is to iterate through all of the edges of
1362 * the line, computing a polygon for each edge and testing the
1363 * point against that polygon. In addition, there are additional
1364 * tests to deal with rounded joints and caps.
1365 */
1366
1367 changedMiterToBevel = 0;
1368 for (count = numPoints, coordPtr = linePoints; count >= 2;
1369 count--, coordPtr += 2) {
1370
1371 /*
1372 * If rounding is done around the first point then compute
1373 * the distance between the point and the point.
1374 */
1375
1376 if (((linePtr->capStyle == CapRound) && (count == numPoints))
1377 || ((linePtr->joinStyle == JoinRound)
1378 && (count != numPoints))) {
1379 dist = hypot(coordPtr[0] - pointPtr[0], coordPtr[1] - pointPtr[1])
1380 - width/2.0;
1381 if (dist <= 0.0) {
1382 bestDist = 0.0;
1383 goto done;
1384 } else if (dist < bestDist) {
1385 bestDist = dist;
1386 }
1387 }
1388
1389 /*
1390 * Compute the polygonal shape corresponding to this edge,
1391 * consisting of two points for the first point of the edge
1392 * and two points for the last point of the edge.
1393 */
1394
1395 if (count == numPoints) {
1396 TkGetButtPoints(coordPtr+2, coordPtr, width,
1397 linePtr->capStyle == CapProjecting, poly, poly+2);
1398 } else if ((linePtr->joinStyle == JoinMiter) && !changedMiterToBevel) {
1399 poly[0] = poly[6];
1400 poly[1] = poly[7];
1401 poly[2] = poly[4];
1402 poly[3] = poly[5];
1403 } else {
1404 TkGetButtPoints(coordPtr+2, coordPtr, width, 0,
1405 poly, poly+2);
1406
1407 /*
1408 * If this line uses beveled joints, then check the distance
1409 * to a polygon comprising the last two points of the previous
1410 * polygon and the first two from this polygon; this checks
1411 * the wedges that fill the mitered joint.
1412 */
1413
1414 if ((linePtr->joinStyle == JoinBevel) || changedMiterToBevel) {
1415 poly[8] = poly[0];
1416 poly[9] = poly[1];
1417 dist = TkPolygonToPoint(poly, 5, pointPtr);
1418 if (dist <= 0.0) {
1419 bestDist = 0.0;
1420 goto done;
1421 } else if (dist < bestDist) {
1422 bestDist = dist;
1423 }
1424 changedMiterToBevel = 0;
1425 }
1426 }
1427 if (count == 2) {
1428 TkGetButtPoints(coordPtr, coordPtr+2, width,
1429 linePtr->capStyle == CapProjecting, poly+4, poly+6);
1430 } else if (linePtr->joinStyle == JoinMiter) {
1431 if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4,
1432 width, poly+4, poly+6) == 0) {
1433 changedMiterToBevel = 1;
1434 TkGetButtPoints(coordPtr, coordPtr+2, width,
1435 0, poly+4, poly+6);
1436 }
1437 } else {
1438 TkGetButtPoints(coordPtr, coordPtr+2, width, 0,
1439 poly+4, poly+6);
1440 }
1441 poly[8] = poly[0];
1442 poly[9] = poly[1];
1443 dist = TkPolygonToPoint(poly, 5, pointPtr);
1444 if (dist <= 0.0) {
1445 bestDist = 0.0;
1446 goto done;
1447 } else if (dist < bestDist) {
1448 bestDist = dist;
1449 }
1450 }
1451
1452 /*
1453 * If caps are rounded, check the distance to the cap around the
1454 * final end point of the line.
1455 */
1456
1457 if (linePtr->capStyle == CapRound) {
1458 dist = hypot(coordPtr[0] - pointPtr[0], coordPtr[1] - pointPtr[1])
1459 - width/2.0;
1460 if (dist <= 0.0) {
1461 bestDist = 0.0;
1462 goto done;
1463 } else if (dist < bestDist) {
1464 bestDist = dist;
1465 }
1466 }
1467
1468 /*
1469 * If there are arrowheads, check the distance to the arrowheads.
1470 */
1471
1472 if (linePtr->arrow != ARROWS_NONE) {
1473 if (linePtr->arrow != ARROWS_LAST) {
1474 dist = TkPolygonToPoint(linePtr->firstArrowPtr, PTS_IN_ARROW,
1475 pointPtr);
1476 if (dist <= 0.0) {
1477 bestDist = 0.0;
1478 goto done;
1479 } else if (dist < bestDist) {
1480 bestDist = dist;
1481 }
1482 }
1483 if (linePtr->arrow != ARROWS_FIRST) {
1484 dist = TkPolygonToPoint(linePtr->lastArrowPtr, PTS_IN_ARROW,
1485 pointPtr);
1486 if (dist <= 0.0) {
1487 bestDist = 0.0;
1488 goto done;
1489 } else if (dist < bestDist) {
1490 bestDist = dist;
1491 }
1492 }
1493 }
1494
1495 done:
1496 if ((linePoints != staticSpace) && (linePoints != linePtr->coordPtr)) {
1497 ckfree((char *) linePoints);
1498 }
1499 return bestDist;
1500 }
1501
1502 /*
1503 *--------------------------------------------------------------
1504 *
1505 * LineToArea --
1506 *
1507 * This procedure is called to determine whether an item
1508 * lies entirely inside, entirely outside, or overlapping
1509 * a given rectangular area.
1510 *
1511 * Results:
1512 * -1 is returned if the item is entirely outside the
1513 * area, 0 if it overlaps, and 1 if it is entirely
1514 * inside the given area.
1515 *
1516 * Side effects:
1517 * None.
1518 *
1519 *--------------------------------------------------------------
1520 */
1521
1522 /* ARGSUSED */
1523 static int
1524 LineToArea(canvas, itemPtr, rectPtr)
1525 Tk_Canvas canvas; /* Canvas containing item. */
1526 Tk_Item *itemPtr; /* Item to check against line. */
1527 double *rectPtr;
1528 {
1529 LineItem *linePtr = (LineItem *) itemPtr;
1530 double staticSpace[2*MAX_STATIC_POINTS];
1531 double *linePoints;
1532 int numPoints, result;
1533 double radius, width;
1534 Tk_State state = Tk_GetItemState(canvas, itemPtr);
1535
1536 width = linePtr->outline.width;
1537 if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) {
1538 if (linePtr->outline.activeWidth>width) {
1539 width = linePtr->outline.activeWidth;
1540 }
1541 } else if (state==TK_STATE_DISABLED) {
1542 if (linePtr->outline.disabledWidth>0) {
1543 width = linePtr->outline.disabledWidth;
1544 }
1545 }
1546
1547 radius = (width+1.0)/2.0;
1548
1549 if ((state==TK_STATE_HIDDEN) || !linePtr->numPoints) {
1550 return -1;
1551 } else if (linePtr->numPoints == 1) {
1552 double oval[4];
1553 oval[0] = linePtr->coordPtr[0]-radius;
1554 oval[1] = linePtr->coordPtr[1]-radius;
1555 oval[2] = linePtr->coordPtr[0]+radius;
1556 oval[3] = linePtr->coordPtr[1]+radius;
1557 return TkOvalToArea(oval, rectPtr);
1558 }
1559
1560 /*
1561 * Handle smoothed lines by generating an expanded set of points
1562 * against which to do the check.
1563 */
1564
1565 if ((linePtr->smooth) && (linePtr->numPoints > 2)) {
1566 numPoints = linePtr->smooth->coordProc(canvas, (double *) NULL,
1567 linePtr->numPoints, linePtr->splineSteps, (XPoint *) NULL,
1568 (double *) NULL);
1569 if (numPoints <= MAX_STATIC_POINTS) {
1570 linePoints = staticSpace;
1571 } else {
1572 linePoints = (double *) ckalloc((unsigned)
1573 (2*numPoints*sizeof(double)));
1574 }
1575 numPoints = linePtr->smooth->coordProc(canvas, linePtr->coordPtr,
1576 linePtr->numPoints, linePtr->splineSteps, (XPoint *) NULL,
1577 linePoints);
1578 } else {
1579 numPoints = linePtr->numPoints;
1580 linePoints = linePtr->coordPtr;
1581 }
1582
1583 /*
1584 * Check the segments of the line.
1585 */
1586
1587 if (width < 1.0) {
1588 width = 1.0;
1589 }
1590
1591 result = TkThickPolyLineToArea(linePoints, numPoints,
1592 width, linePtr->capStyle, linePtr->joinStyle,
1593 rectPtr);
1594 if (result == 0) {
1595 goto done;
1596 }
1597
1598 /*
1599 * Check arrowheads, if any.
1600 */
1601
1602 if (linePtr->arrow != ARROWS_NONE) {
1603 if (linePtr->arrow != ARROWS_LAST) {
1604 if (TkPolygonToArea(linePtr->firstArrowPtr, PTS_IN_ARROW,
1605 rectPtr) != result) {
1606 result = 0;
1607 goto done;
1608 }
1609 }
1610 if (linePtr->arrow != ARROWS_FIRST) {
1611 if (TkPolygonToArea(linePtr->lastArrowPtr, PTS_IN_ARROW,
1612 rectPtr) != result) {
1613 result = 0;
1614 goto done;
1615 }
1616 }
1617 }
1618
1619 done:
1620 if ((linePoints != staticSpace) && (linePoints != linePtr->coordPtr)) {
1621 ckfree((char *) linePoints);
1622 }
1623 return result;
1624 }
1625
1626 /*
1627 *--------------------------------------------------------------
1628 *
1629 * ScaleLine --
1630 *
1631 * This procedure is invoked to rescale a line item.
1632 *
1633 * Results:
1634 * None.
1635 *
1636 * Side effects:
1637 * The line referred to by itemPtr is rescaled so that the
1638 * following transformation is applied to all point
1639 * coordinates:
1640 * x' = originX + scaleX*(x-originX)
1641 * y' = originY + scaleY*(y-originY)
1642 *
1643 *--------------------------------------------------------------
1644 */
1645
1646 static void
1647 ScaleLine(canvas, itemPtr, originX, originY, scaleX, scaleY)
1648 Tk_Canvas canvas; /* Canvas containing line. */
1649 Tk_Item *itemPtr; /* Line to be scaled. */
1650 double originX, originY; /* Origin about which to scale rect. */
1651 double scaleX; /* Amount to scale in X direction. */
1652 double scaleY; /* Amount to scale in Y direction. */
1653 {
1654 LineItem *linePtr = (LineItem *) itemPtr;
1655 double *coordPtr;
1656 int i;
1657
1658 /*
1659 * Delete any arrowheads before scaling all the points (so that
1660 * the end-points of the line get restored).
1661 */
1662
1663 if (linePtr->firstArrowPtr != NULL) {
1664 linePtr->coordPtr[0] = linePtr->firstArrowPtr[0];
1665 linePtr->coordPtr[1] = linePtr->firstArrowPtr[1];
1666 ckfree((char *) linePtr->firstArrowPtr);
1667 linePtr->firstArrowPtr = NULL;
1668 }
1669 if (linePtr->lastArrowPtr != NULL) {
1670 int i;
1671
1672 i = 2*(linePtr->numPoints-1);
1673 linePtr->coordPtr[i] = linePtr->lastArrowPtr[0];
1674 linePtr->coordPtr[i+1] = linePtr->lastArrowPtr[1];
1675 ckfree((char *) linePtr->lastArrowPtr);
1676 linePtr->lastArrowPtr = NULL;
1677 }
1678 for (i = 0, coordPtr = linePtr->coordPtr; i < linePtr->numPoints;
1679 i++, coordPtr += 2) {
1680 coordPtr[0] = originX + scaleX*(*coordPtr - originX);
1681 coordPtr[1] = originY + scaleY*(coordPtr[1] - originY);
1682 }
1683 if (linePtr->arrow != ARROWS_NONE) {
1684 ConfigureArrows(canvas, linePtr);
1685 }
1686 ComputeLineBbox(canvas, linePtr);
1687 }
1688
1689 /*
1690 *--------------------------------------------------------------
1691 *
1692 * GetLineIndex --
1693 *
1694 * Parse an index into a line item and return either its value
1695 * or an error.
1696 *
1697 * Results:
1698 * A standard Tcl result. If all went well, then *indexPtr is
1699 * filled in with the index (into itemPtr) corresponding to
1700 * string. Otherwise an error message is left in
1701 * interp->result.
1702 *
1703 * Side effects:
1704 * None.
1705 *
1706 *--------------------------------------------------------------
1707 */
1708
1709 static int
1710 GetLineIndex(interp, canvas, itemPtr, obj, indexPtr)
1711 Tcl_Interp *interp; /* Used for error reporting. */
1712 Tk_Canvas canvas; /* Canvas containing item. */
1713 Tk_Item *itemPtr; /* Item for which the index is being
1714 * specified. */
1715 Tcl_Obj *obj; /* Specification of a particular coord
1716 * in itemPtr's line. */
1717 int *indexPtr; /* Where to store converted index. */
1718 {
1719 LineItem *linePtr = (LineItem *) itemPtr;
1720 int length;
1721 char *string;
1722 int i;
1723 double x ,y, bestDist, dist, *coordPtr;
1724 char *end, *p;
1725 Tcl_Obj **objv;
1726
1727 if (Tcl_ListObjGetElements(interp, obj, &i, &objv) == TCL_OK && i == 2
1728 && Tcl_GetDoubleFromObj(interp, objv[0], &x) == TCL_OK
1729 && Tcl_GetDoubleFromObj(interp, objv[1], &y) == TCL_OK) {
1730 goto doxy;
1731 }
1732
1733 string = Tcl_GetStringFromObj(obj, &length);
1734 if (string[0] == 'e') {
1735 if (strncmp(string, "end", length) == 0) {
1736 *indexPtr = 2*linePtr->numPoints;
1737 } else {
1738 badIndex:
1739
1740 /*
1741 * Some of the paths here leave messages in interp->result,
1742 * so we have to clear it out before storing our own message.
1743 */
1744
1745 Tcl_SetResult(interp, (char *) NULL, TCL_STATIC);
1746 Tcl_AppendResult(interp, "bad index \"", string, "\"",
1747 (char *) NULL);
1748 return TCL_ERROR;
1749 }
1750 } else if (string[0] == '@') {
1751 p = string+1;
1752 x = strtod(p, &end);
1753 if ((end == p) || (*end != ',')) {
1754 goto badIndex;
1755 }
1756 p = end+1;
1757 y = strtod(p, &end);
1758 if ((end == p) || (*end != 0)) {
1759 goto badIndex;
1760 }
1761 doxy:
1762 bestDist = 1.0e36;
1763 coordPtr = linePtr->coordPtr;
1764 *indexPtr = 0;
1765 for(i=0; i<linePtr->numPoints; i++) {
1766 dist = hypot(coordPtr[0] - x, coordPtr[1] - y);
1767 if (dist<bestDist) {
1768 bestDist = dist;
1769 *indexPtr = 2*i;
1770 }
1771 coordPtr += 2;
1772 }
1773 } else {
1774 if (Tcl_GetIntFromObj(interp, obj, indexPtr) != TCL_OK) {
1775 goto badIndex;
1776 }
1777 *indexPtr &= -2; /* if index is odd, make it even */
1778 if (*indexPtr < 0){
1779 *indexPtr = 0;
1780 } else if (*indexPtr > (2*linePtr->numPoints)) {
1781 *indexPtr = (2*linePtr->numPoints);
1782 }
1783 }
1784 return TCL_OK;
1785 }
1786
1787 /*
1788 *--------------------------------------------------------------
1789 *
1790 * TranslateLine --
1791 *
1792 * This procedure is called to move a line by a given amount.
1793 *
1794 * Results:
1795 * None.
1796 *
1797 * Side effects:
1798 * The position of the line is offset by (xDelta, yDelta), and
1799 * the bounding box is updated in the generic part of the item
1800 * structure.
1801 *
1802 *--------------------------------------------------------------
1803 */
1804
1805 static void
1806 TranslateLine(canvas, itemPtr, deltaX, deltaY)
1807 Tk_Canvas canvas; /* Canvas containing item. */
1808 Tk_Item *itemPtr; /* Item that is being moved. */
1809 double deltaX, deltaY; /* Amount by which item is to be
1810 * moved. */
1811 {
1812 LineItem *linePtr = (LineItem *) itemPtr;
1813 double *coordPtr;
1814 int i;
1815
1816 for (i = 0, coordPtr = linePtr->coordPtr; i < linePtr->numPoints;
1817 i++, coordPtr += 2) {
1818 coordPtr[0] += deltaX;
1819 coordPtr[1] += deltaY;
1820 }
1821 if (linePtr->firstArrowPtr != NULL) {
1822 for (i = 0, coordPtr = linePtr->firstArrowPtr; i < PTS_IN_ARROW;
1823 i++, coordPtr += 2) {
1824 coordPtr[0] += deltaX;
1825 coordPtr[1] += deltaY;
1826 }
1827 }
1828 if (linePtr->lastArrowPtr != NULL) {
1829 for (i = 0, coordPtr = linePtr->lastArrowPtr; i < PTS_IN_ARROW;
1830 i++, coordPtr += 2) {
1831 coordPtr[0] += deltaX;
1832 coordPtr[1] += deltaY;
1833 }
1834 }
1835 ComputeLineBbox(canvas, linePtr);
1836 }
1837
1838 /*
1839 *--------------------------------------------------------------
1840 *
1841 * ParseArrowShape --
1842 *
1843 * This procedure is called back during option parsing to
1844 * parse arrow shape information.
1845 *
1846 * Results:
1847 * The return value is a standard Tcl result: TCL_OK means
1848 * that the arrow shape information was parsed ok, and
1849 * TCL_ERROR means it couldn't be parsed.
1850 *
1851 * Side effects:
1852 * Arrow information in recordPtr is updated.
1853 *
1854 *--------------------------------------------------------------
1855 */
1856
1857 /* ARGSUSED */
1858 static int
1859 ParseArrowShape(clientData, interp, tkwin, value, recordPtr, offset)
1860 ClientData clientData; /* Not used. */
1861 Tcl_Interp *interp; /* Used for error reporting. */
1862 Tk_Window tkwin; /* Not used. */
1863 Tcl_Obj * value; /* Textual specification of arrow shape. */
1864 char *recordPtr; /* Pointer to item record in which to
1865 * store arrow information. */
1866 int offset; /* Offset of shape information in widget
1867 * record. */
1868 {
1869 LineItem *linePtr = (LineItem *) recordPtr;
1870 double a, b, c;
1871 int argc;
1872 Tcl_Obj **objv = NULL;
1873
1874 if (offset != Tk_Offset(LineItem, arrowShapeA)) {
1875 panic("ParseArrowShape received bogus offset");
1876 }
1877
1878 if (Tcl_ListObjGetElements(interp, value, &argc, &objv) != TCL_OK) {
1879 syntaxError:
1880 Tcl_ResetResult(interp);
1881 Tcl_AppendResult(interp, "bad arrow shape \"", Tcl_GetString(value),
1882 "\": must be list with three numbers", (char *) NULL);
1883 return TCL_ERROR;
1884 }
1885 if (argc != 3) {
1886 goto syntaxError;
1887 }
1888 if ((Tk_CanvasGetCoordFromObj(interp, linePtr->canvas, objv[0], &a) != TCL_OK)
1889 || (Tk_CanvasGetCoordFromObj(interp, linePtr->canvas, objv[1], &b)
1890 != TCL_OK)
1891 || (Tk_CanvasGetCoordFromObj(interp, linePtr->canvas, objv[2], &c)
1892 != TCL_OK)) {
1893 goto syntaxError;
1894 }
1895 linePtr->arrowShapeA = (float) a;
1896 linePtr->arrowShapeB = (float) b;
1897 linePtr->arrowShapeC = (float) c;
1898 return TCL_OK;
1899 }
1900
1901 /*
1902 *--------------------------------------------------------------
1903 *
1904 * PrintArrowShape --
1905 *
1906 * This procedure is a callback invoked by the configuration
1907 * code to return a printable value describing an arrow shape.
1908 *
1909 * Results:
1910 * None.
1911 *
1912 * Side effects:
1913 * None.
1914 *
1915 *--------------------------------------------------------------
1916 */
1917
1918 /* ARGSUSED */
1919 static Tcl_Obj *
1920 PrintArrowShape(clientData, tkwin, recordPtr, offset, freeProcPtr)
1921 ClientData clientData; /* Not used. */
1922 Tk_Window tkwin; /* Window associated with linePtr's widget. */
1923 char *recordPtr; /* Pointer to item record containing current
1924 * shape information. */
1925 int offset; /* Offset of arrow information in record. */
1926 Tcl_FreeProc **freeProcPtr; /* Store address of procedure to call to
1927 * free string here. */
1928 {
1929 LineItem *linePtr = (LineItem *) recordPtr;
1930 Tcl_Obj * result = Tcl_NewListObj(0,NULL);
1931 Tcl_ListObjAppendElement(NULL,result,Tcl_NewDoubleObj(linePtr->arrowShapeA));
1932 Tcl_ListObjAppendElement(NULL,result,Tcl_NewDoubleObj(linePtr->arrowShapeB));
1933 Tcl_ListObjAppendElement(NULL,result,Tcl_NewDoubleObj(linePtr->arrowShapeC));
1934 return result;
1935 }
1936
1937
1938 /*
1939 *--------------------------------------------------------------
1940 *
1941 * ArrowParseProc --
1942 *
1943 * This procedure is invoked during option processing to handle
1944 * the "-arrow" option.
1945 *
1946 * Results:
1947 * A standard Tcl return value.
1948 *
1949 * Side effects:
1950 * The arrow for a given item gets replaced by the arrow
1951 * indicated in the value argument.
1952 *
1953 *--------------------------------------------------------------
1954 */
1955
1956 static int
1957 ArrowParseProc(clientData, interp, tkwin, ovalue, widgRec, offset)
1958 ClientData clientData; /* some flags.*/
1959 Tcl_Interp *interp; /* Used for reporting errors. */
1960 Tk_Window tkwin; /* Window containing canvas widget. */
1961 Tcl_Obj * ovalue; /* Value of option. */
1962 char *widgRec; /* Pointer to record for item. */
1963 int offset; /* Offset into item. */
1964 {
1965 int c;
1966 size_t length;
1967 char *value = Tcl_GetString(ovalue);
1968
1969 register Arrows *arrowPtr = (Arrows *) (widgRec + offset);
1970
1971 if(value == NULL || *value == 0) {
1972 *arrowPtr = ARROWS_NONE;
1973 return TCL_OK;
1974 }
1975
1976 c = value[0];
1977 length = strlen(value);
1978
1979 if ((c == 'n') && (strncmp(value, "none", length) == 0)) {
1980 *arrowPtr = ARROWS_NONE;
1981 return TCL_OK;
1982 }
1983 if ((c == 'f') && (strncmp(value, "first", length) == 0)) {
1984 *arrowPtr = ARROWS_FIRST;
1985 return TCL_OK;
1986 }
1987 if ((c == 'l') && (strncmp(value, "last", length) == 0)) {
1988 *arrowPtr = ARROWS_LAST;
1989 return TCL_OK;
1990 }
1991 if ((c == 'b') && (strncmp(value, "both", length) == 0)) {
1992 *arrowPtr = ARROWS_BOTH;
1993 return TCL_OK;
1994 }
1995
1996 Tcl_AppendResult(interp, "bad arrow spec \"", value,
1997 "\": must be none, first, last, or both",
1998 (char *) NULL);
1999 *arrowPtr = ARROWS_NONE;
2000 return TCL_ERROR;
2001 }
2002
2003 /*
2004 *--------------------------------------------------------------
2005 *
2006 * ArrowPrintProc --
2007 *
2008 * This procedure is invoked by the Tk configuration code
2009 * to produce a printable string for the "-arrow"
2010 * configuration option.
2011 *
2012 * Results:
2013 * The return value is a string describing the arrows for
2014 * the item referred to by "widgRec". In addition, *freeProcPtr
2015 * is filled in with the address of a procedure to call to free
2016 * the result string when it's no longer needed (or NULL to
2017 * indicate that the string doesn't need to be freed).
2018 *
2019 * Side effects:
2020 * None.
2021 *
2022 *--------------------------------------------------------------
2023 */
2024
2025 static Tcl_Obj *
2026 ArrowPrintProc(clientData, tkwin, widgRec, offset, freeProcPtr)
2027 ClientData clientData; /* Ignored. */
2028 Tk_Window tkwin; /* Window containing canvas widget. */
2029 char *widgRec; /* Pointer to record for item. */
2030 int offset; /* Offset into item. */
2031 Tcl_FreeProc **freeProcPtr; /* Pointer to variable to fill in with
2032 * information about how to reclaim
2033 * storage for return string. */
2034 {
2035 register Arrows *arrowPtr = (Arrows *) (widgRec + offset);
2036 Tcl_Obj * result = NULL;
2037
2038 switch (*arrowPtr) {
2039 case ARROWS_FIRST:
2040 return LangStringArg("first");
2041 case ARROWS_LAST:
2042 return LangStringArg("last");
2043 case ARROWS_BOTH:
2044 return LangStringArg("both");
2045 default:
2046 return LangStringArg("none");
2047 }
2048 }
2049
2050 /*
2051 *--------------------------------------------------------------
2052 *
2053 * ConfigureArrows --
2054 *
2055 * If arrowheads have been requested for a line, this
2056 * procedure makes arrangements for the arrowheads.
2057 *
2058 * Results:
2059 * Always returns TCL_OK.
2060 *
2061 * Side effects:
2062 * Information in linePtr is set up for one or two arrowheads.
2063 * the firstArrowPtr and lastArrowPtr polygons are allocated
2064 * and initialized, if need be, and the end points of the line
2065 * are adjusted so that a thick line doesn't stick out past
2066 * the arrowheads.
2067 *
2068 *--------------------------------------------------------------
2069 */
2070
2071 /* ARGSUSED */
2072 static int
2073 ConfigureArrows(canvas, linePtr)
2074 Tk_Canvas canvas; /* Canvas in which arrows will be
2075 * displayed (interp and tkwin
2076 * fields are needed). */
2077 LineItem *linePtr; /* Item to configure for arrows. */
2078 {
2079 double *poly, *coordPtr;
2080 double dx, dy, length, sinTheta, cosTheta, temp;
2081 double fracHeight; /* Line width as fraction of
2082 * arrowhead width. */
2083 double backup; /* Distance to backup end points
2084 * so the line ends in the middle
2085 * of the arrowhead. */
2086 double vertX, vertY; /* Position of arrowhead vertex. */
2087 double shapeA, shapeB, shapeC; /* Adjusted coordinates (see
2088 * explanation below). */
2089 double width;
2090 Tk_State state = Tk_GetItemState(canvas, &linePtr->header);
2091
2092 if (linePtr->numPoints <2) {
2093 return TCL_OK;
2094 }
2095
2096 width = linePtr->outline.width;
2097 if (((TkCanvas *)canvas)->currentItemPtr == (Tk_Item *)linePtr) {
2098 if (linePtr->outline.activeWidth>width) {
2099 width = linePtr->outline.activeWidth;
2100 }
2101 } else if (state==TK_STATE_DISABLED) {
2102 if (linePtr->outline.disabledWidth>0) {
2103 width = linePtr->outline.disabledWidth;
2104 }
2105 }
2106
2107 /*
2108 * The code below makes a tiny increase in the shape parameters
2109 * for the line. This is a bit of a hack, but it seems to result
2110 * in displays that more closely approximate the specified parameters.
2111 * Without the adjustment, the arrows come out smaller than expected.
2112 */
2113
2114 shapeA = linePtr->arrowShapeA + 0.001;
2115 shapeB = linePtr->arrowShapeB + 0.001;
2116 shapeC = linePtr->arrowShapeC + width/2.0 + 0.001;
2117
2118 /*
2119 * If there's an arrowhead on the first point of the line, compute
2120 * its polygon and adjust the first point of the line so that the
2121 * line doesn't stick out past the leading edge of the arrowhead.
2122 */
2123
2124 fracHeight = (width/2.0)/shapeC;
2125 backup = fracHeight*shapeB + shapeA*(1.0 - fracHeight)/2.0;
2126 if (linePtr->arrow != ARROWS_LAST) {
2127 poly = linePtr->firstArrowPtr;
2128 if (poly == NULL) {
2129 poly = (double *) ckalloc((unsigned)
2130 (2*PTS_IN_ARROW*sizeof(double)));
2131 poly[0] = poly[10] = linePtr->coordPtr[0];
2132 poly[1] = poly[11] = linePtr->coordPtr[1];
2133 linePtr->firstArrowPtr = poly;
2134 }
2135 dx = poly[0] - linePtr->coordPtr[2];
2136 dy = poly[1] - linePtr->coordPtr[3];
2137 length = hypot(dx, dy);
2138 if (length == 0) {
2139 sinTheta = cosTheta = 0.0;
2140 } else {
2141 sinTheta = dy/length;
2142 cosTheta = dx/length;
2143 }
2144 vertX = poly[0] - shapeA*cosTheta;
2145 vertY = poly[1] - shapeA*sinTheta;
2146 temp = shapeC*sinTheta;
2147 poly[2] = poly[0] - shapeB*cosTheta + temp;
2148 poly[8] = poly[2] - 2*temp;
2149 temp = shapeC*cosTheta;
2150 poly[3] = poly[1] - shapeB*sinTheta - temp;
2151 poly[9] = poly[3] + 2*temp;
2152 poly[4] = poly[2]*fracHeight + vertX*(1.0-fracHeight);
2153 poly[5] = poly[3]*fracHeight + vertY*(1.0-fracHeight);
2154 poly[6] = poly[8]*fracHeight + vertX*(1.0-fracHeight);
2155 poly[7] = poly[9]*fracHeight + vertY*(1.0-fracHeight);
2156
2157 /*
2158 * Polygon done. Now move the first point towards the second so
2159 * that the corners at the end of the line are inside the
2160 * arrowhead.
2161 */
2162
2163 linePtr->coordPtr[0] = poly[0] - backup*cosTheta;
2164 linePtr->coordPtr[1] = poly[1] - backup*sinTheta;
2165 }
2166
2167 /*
2168 * Similar arrowhead calculation for the last point of the line.
2169 */
2170
2171 if (linePtr->arrow != ARROWS_FIRST) {
2172 coordPtr = linePtr->coordPtr + 2*(linePtr->numPoints-2);
2173 poly = linePtr->lastArrowPtr;
2174 if (poly == NULL) {
2175 poly = (double *) ckalloc((unsigned)
2176 (2*PTS_IN_ARROW*sizeof(double)));
2177 poly[0] = poly[10] = coordPtr[2];
2178 poly[1] = poly[11] = coordPtr[3];
2179 linePtr->lastArrowPtr = poly;
2180 }
2181 dx = poly[0] - coordPtr[0];
2182 dy = poly[1] - coordPtr[1];
2183 length = hypot(dx, dy);
2184 if (length == 0) {
2185 sinTheta = cosTheta = 0.0;
2186 } else {
2187 sinTheta = dy/length;
2188 cosTheta = dx/length;
2189 }
2190 vertX = poly[0] - shapeA*cosTheta;
2191 vertY = poly[1] - shapeA*sinTheta;
2192 temp = shapeC*sinTheta;
2193 poly[2] = poly[0] - shapeB*cosTheta + temp;
2194 poly[8] = poly[2] - 2*temp;
2195 temp = shapeC*cosTheta;
2196 poly[3] = poly[1] - shapeB*sinTheta - temp;
2197 poly[9] = poly[3] + 2*temp;
2198 poly[4] = poly[2]*fracHeight + vertX*(1.0-fracHeight);
2199 poly[5] = poly[3]*fracHeight + vertY*(1.0-fracHeight);
2200 poly[6] = poly[8]*fracHeight + vertX*(1.0-fracHeight);
2201 poly[7] = poly[9]*fracHeight + vertY*(1.0-fracHeight);
2202 coordPtr[2] = poly[0] - backup*cosTheta;
2203 coordPtr[3] = poly[1] - backup*sinTheta;
2204 }
2205
2206 return TCL_OK;
2207 }
2208
2209 /*
2210 *--------------------------------------------------------------
2211 *
2212 * LineToPostscript --
2213 *
2214 * This procedure is called to generate Postscript for
2215 * line items.
2216 *
2217 * Results:
2218 * The return value is a standard Tcl result. If an error
2219 * occurs in generating Postscript then an error message is
2220 * left in the interp's result, replacing whatever used
2221 * to be there. If no error occurs, then Postscript for the
2222 * item is appended to the result.
2223 *
2224 * Side effects:
2225 * None.
2226 *
2227 *--------------------------------------------------------------
2228 */
2229
2230 static int
2231 LineToPostscript(interp, canvas, itemPtr, prepass)
2232 Tcl_Interp *interp; /* Leave Postscript or error message
2233 * here. */
2234 Tk_Canvas canvas; /* Information about overall canvas. */
2235 Tk_Item *itemPtr; /* Item for which Postscript is
2236 * wanted. */
2237 int prepass; /* 1 means this is a prepass to
2238 * collect font information; 0 means
2239 * final Postscript is being created. */
2240 {
2241 LineItem *linePtr = (LineItem *) itemPtr;
2242 char buffer[64 + TCL_INTEGER_SPACE];
2243 char *style;
2244
2245 double width;
2246 XColor *color;
2247 Pixmap stipple;
2248 Tk_State state = Tk_GetItemState(canvas, itemPtr);
2249
2250 width = linePtr->outline.width;
2251 color = linePtr->outline.color;
2252 stipple = linePtr->outline.stipple;
2253 if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) {
2254 if (linePtr->outline.activeWidth>width) {
2255 width = linePtr->outline.activeWidth;
2256 }
2257 if (linePtr->outline.activeColor!=NULL) {
2258 color = linePtr->outline.activeColor;
2259 }
2260 if (linePtr->outline.activeStipple!=None) {
2261 stipple = linePtr->outline.activeStipple;
2262 }
2263 } else if (state==TK_STATE_DISABLED) {
2264 if (linePtr->outline.disabledWidth>0) {
2265 width = linePtr->outline.disabledWidth;
2266 }
2267 if (linePtr->outline.disabledColor!=NULL) {
2268 color = linePtr->outline.disabledColor;
2269 }
2270 if (linePtr->outline.disabledStipple!=None) {
2271 stipple = linePtr->outline.disabledStipple;
2272 }
2273 }
2274
2275 if (color == NULL || linePtr->numPoints<1 || linePtr->coordPtr==NULL) {
2276 return TCL_OK;
2277 }
2278
2279 if (linePtr->numPoints==1) {
2280 sprintf(buffer, "%.15g %.15g translate %.15g %.15g",
2281 linePtr->coordPtr[0], Tk_CanvasPsY(canvas, linePtr->coordPtr[1]),
2282 width/2.0, width/2.0);
2283 Tcl_AppendResult(interp, "matrix currentmatrix\n",buffer,
2284 " scale 1 0 moveto 0 0 1 0 360 arc\nsetmatrix\n", (char *) NULL);
2285 if (Tk_CanvasPsColor(interp, canvas, color)
2286 != TCL_OK) {
2287 return TCL_ERROR;
2288 }
2289 if (stipple != None) {
2290 Tcl_AppendResult(interp, "clip ", (char *) NULL);
2291 if (Tk_CanvasPsStipple(interp, canvas, stipple) != TCL_OK) {
2292 return TCL_ERROR;
2293 }
2294 } else {
2295 Tcl_AppendResult(interp, "fill\n", (char *) NULL);
2296 }
2297 return TCL_OK;
2298 }
2299 /*
2300 * Generate a path for the line's center-line (do this differently
2301 * for straight lines and smoothed lines).
2302 */
2303
2304 if ((!linePtr->smooth) || (linePtr->numPoints < 3)) {
2305 Tk_CanvasPsPath(interp, canvas, linePtr->coordPtr, linePtr->numPoints);
2306 } else {
2307 if ((stipple == None) && linePtr->smooth->postscriptProc) {
2308 linePtr->smooth->postscriptProc(interp, canvas,
2309 linePtr->coordPtr, linePtr->numPoints, linePtr->splineSteps);
2310 } else {
2311 /*
2312 * Special hack: Postscript printers don't appear to be able
2313 * to turn a path drawn with "curveto"s into a clipping path
2314 * without exceeding resource limits, so TkMakeBezierPostscript
2315 * won't work for stippled curves. Instead, generate all of
2316 * the intermediate points here and output them into the
2317 * Postscript file with "lineto"s instead.
2318 */
2319
2320 double staticPoints[2*MAX_STATIC_POINTS];
2321 double *pointPtr;
2322 int numPoints;
2323
2324 numPoints = linePtr->smooth->coordProc(canvas, (double *) NULL,
2325 linePtr->numPoints, linePtr->splineSteps, (XPoint *) NULL,
2326 (double *) NULL);
2327 pointPtr = staticPoints;
2328 if (numPoints > MAX_STATIC_POINTS) {
2329 pointPtr = (double *) ckalloc((unsigned)
2330 (numPoints * 2 * sizeof(double)));
2331 }
2332 numPoints = linePtr->smooth->coordProc(canvas, linePtr->coordPtr,
2333 linePtr->numPoints, linePtr->splineSteps, (XPoint *) NULL,
2334 pointPtr);
2335 Tk_CanvasPsPath(interp, canvas, pointPtr, numPoints);
2336 if (pointPtr != staticPoints) {
2337 ckfree((char *) pointPtr);
2338 }
2339 }
2340 }
2341
2342 /*
2343 * Set other line-drawing parameters and stroke out the line.
2344 */
2345
2346 style = "0 setlinecap\n";
2347 if (linePtr->capStyle == CapRound) {
2348 style = "1 setlinecap\n";
2349 } else if (linePtr->capStyle == CapProjecting) {
2350 style = "2 setlinecap\n";
2351 }
2352 Tcl_AppendResult(interp, style, (char *) NULL);
2353 style = "0 setlinejoin\n";
2354 if (linePtr->joinStyle == JoinRound) {
2355 style = "1 setlinejoin\n";
2356 } else if (linePtr->joinStyle == JoinBevel) {
2357 style = "2 setlinejoin\n";
2358 }
2359 Tcl_AppendResult(interp, style, (char *) NULL);
2360
2361 if (Tk_CanvasPsOutline(canvas, itemPtr,
2362 &(linePtr->outline)) != TCL_OK) {
2363 return TCL_ERROR;
2364 }
2365
2366 /*
2367 * Output polygons for the arrowheads, if there are any.
2368 */
2369
2370 if (linePtr->firstArrowPtr != NULL) {
2371 if (stipple != None) {
2372 Tcl_AppendResult(interp, "grestore gsave\n",
2373 (char *) NULL);
2374 }
2375 if (ArrowheadPostscript(interp, canvas, linePtr,
2376 linePtr->firstArrowPtr) != TCL_OK) {
2377 return TCL_ERROR;
2378 }
2379 }
2380 if (linePtr->lastArrowPtr != NULL) {
2381 if (stipple != None) {
2382 Tcl_AppendResult(interp, "grestore gsave\n", (char *) NULL);
2383 }
2384 if (ArrowheadPostscript(interp, canvas, linePtr,
2385 linePtr->lastArrowPtr) != TCL_OK) {
2386 return TCL_ERROR;
2387 }
2388 }
2389 return TCL_OK;
2390 }
2391
2392 /*
2393 *--------------------------------------------------------------
2394 *
2395 * ArrowheadPostscript --
2396 *
2397 * This procedure is called to generate Postscript for
2398 * an arrowhead for a line item.
2399 *
2400 * Results:
2401 * The return value is a standard Tcl result. If an error
2402 * occurs in generating Postscript then an error message is
2403 * left in the interp's result, replacing whatever used
2404 * to be there. If no error occurs, then Postscript for the
2405 * arrowhead is appended to the result.
2406 *
2407 * Side effects:
2408 * None.
2409 *
2410 *--------------------------------------------------------------
2411 */
2412
2413 static int
2414 ArrowheadPostscript(interp, canvas, linePtr, arrowPtr)
2415 Tcl_Interp *interp; /* Leave Postscript or error message
2416 * here. */
2417 Tk_Canvas canvas; /* Information about overall canvas. */
2418 LineItem *linePtr; /* Line item for which Postscript is
2419 * being generated. */
2420 double *arrowPtr; /* Pointer to first of five points
2421 * describing arrowhead polygon. */
2422 {
2423 Pixmap stipple;
2424 Tk_State state = Tk_GetItemState(canvas, &linePtr->header);
2425
2426 stipple = linePtr->outline.stipple;
2427 if (((TkCanvas *)canvas)->currentItemPtr == (Tk_Item *)linePtr) {
2428 if (linePtr->outline.activeStipple!=None) {
2429 stipple = linePtr->outline.activeStipple;
2430 }
2431 } else if (state==TK_STATE_DISABLED) {
2432 if (linePtr->outline.activeStipple!=None) {
2433 stipple = linePtr->outline.disabledStipple;
2434 }
2435 }
2436
2437 Tk_CanvasPsPath(interp, canvas, arrowPtr, PTS_IN_ARROW);
2438 if (stipple != None) {
2439 Tcl_AppendResult(interp, "clip ", (char *) NULL);
2440 if (Tk_CanvasPsStipple(interp, canvas, stipple)
2441 != TCL_OK) {
2442 return TCL_ERROR;
2443 }
2444 } else {
2445 Tcl_AppendResult(interp, "fill\n", (char *) NULL);
2446 }
2447 return TCL_OK;
2448 }
2449
2450