-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathtkCanvUtil.c
More file actions
1925 lines (1772 loc) · 50.4 KB
/
Copy pathtkCanvUtil.c
File metadata and controls
1925 lines (1772 loc) · 50.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* tkCanvUtil.c --
*
* This file contains a collection of utility functions used by the
* implementations of various canvas item types.
*
* Copyright © 1994 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
#include "tkInt.h"
#include "tkCanvas.h"
#ifdef _WIN32
#include "tkWinInt.h"
#endif
/*
* Structures defined only in this file.
*/
typedef struct SmoothAssocData {
struct SmoothAssocData *nextPtr;
/* Pointer to next SmoothAssocData. */
Tk_SmoothMethod smooth; /* Name and functions associated with this
* option. */
} SmoothAssocData;
const Tk_SmoothMethod tkBezierSmoothMethod = {
"true",
TkMakeBezierCurve,
(void (*) (Tcl_Interp *interp, Tk_Canvas canvas, double *coordPtr,
int numPoints, int numSteps))(void *)TkMakeBezierPostscript,
};
static const Tk_SmoothMethod tkRawSmoothMethod = {
"raw",
TkMakeRawCurve,
(void (*) (Tcl_Interp *interp, Tk_Canvas canvas, double *coordPtr,
int numPoints, int numSteps))(void *)TkMakeRawCurvePostscript,
};
/*
* Function forward-declarations.
*/
static void SmoothMethodCleanupProc(void *clientData,
Tcl_Interp *interp);
static SmoothAssocData *InitSmoothMethods(Tcl_Interp *interp);
static int DashConvert(char *l, const char *p, int n,
double width);
static void TranslateAndAppendCoords(TkCanvas *canvPtr,
double x, double y, XPoint *outArr, int numOut);
static inline Tcl_Obj * GetPostscriptBuffer(Tcl_Interp *interp);
#define ABS(a) ((a>=0)?(a):(-(a)))
static inline Tcl_Obj *
GetPostscriptBuffer(
Tcl_Interp *interp)
{
Tcl_Obj *psObj = Tcl_GetObjResult(interp);
if (Tcl_IsShared(psObj)) {
psObj = Tcl_DuplicateObj(psObj);
Tcl_SetObjResult(interp, psObj);
}
return psObj;
}
/*
*----------------------------------------------------------------------
*
* Tk_CanvasTkwin --
*
* Given a token for a canvas, this function returns the widget that
* represents the canvas.
*
* Results:
* The return value is a handle for the widget.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
Tk_Window
Tk_CanvasTkwin(
Tk_Canvas canvas) /* Token for the canvas. */
{
return Canvas(canvas)->tkwin;
}
/*
*----------------------------------------------------------------------
*
* Tk_CanvasDrawableCoords --
*
* Given an (x,y) coordinate pair within a canvas, this function
* returns the corresponding coordinates at which the point should
* be drawn in the drawable used for display.
*
* Results:
* There is no return value. The values at *drawableXPtr and
* *drawableYPtr are filled in with the coordinates at which x and y
* should be drawn. These coordinates are clipped to fit within a
* "short", since this is what X uses in most cases for drawing.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void
Tk_CanvasDrawableCoords(
Tk_Canvas canvas, /* Token for the canvas. */
double x, /* Coordinates in canvas space. */
double y,
short *drawableXPtr, /* Screen coordinates are stored here. */
short *drawableYPtr)
{
double tmp;
tmp = x - Canvas(canvas)->drawableXOrigin;
if (tmp > 0) {
tmp += 0.5;
} else {
tmp -= 0.5;
}
if (tmp > 32767) {
*drawableXPtr = 32767;
} else if (tmp < -32768) {
*drawableXPtr = -32768;
} else {
*drawableXPtr = (short) tmp;
}
tmp = y - Canvas(canvas)->drawableYOrigin;
if (tmp > 0) {
tmp += 0.5;
} else {
tmp -= 0.5;
}
if (tmp > 32767) {
*drawableYPtr = 32767;
} else if (tmp < -32768) {
*drawableYPtr = -32768;
} else {
*drawableYPtr = (short) tmp;
}
}
/*
*----------------------------------------------------------------------
*
* Tk_CanvasWindowCoords --
*
* Given an (x,y) coordinate pair within a canvas, this function returns
* the corresponding coordinates in the canvas's window.
*
* Results:
* There is no return value. The values at *screenXPtr and *screenYPtr
* are filled in with the coordinates at which (x,y) appears in the
* canvas's window. These coordinates are clipped to fit within a
* "short", since this is what X uses in most cases for drawing.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void
Tk_CanvasWindowCoords(
Tk_Canvas canvas, /* Token for the canvas. */
double x, /* Coordinates in canvas space. */
double y,
short *screenXPtr, /* Screen coordinates are stored here. */
short *screenYPtr)
{
double tmp;
tmp = x - Canvas(canvas)->xOrigin;
if (tmp > 0) {
tmp += 0.5;
} else {
tmp -= 0.5;
}
if (tmp > 32767) {
*screenXPtr = 32767;
} else if (tmp < -32768) {
*screenXPtr = -32768;
} else {
*screenXPtr = (short) tmp;
}
tmp = y - Canvas(canvas)->yOrigin;
if (tmp > 0) {
tmp += 0.5;
} else {
tmp -= 0.5;
}
if (tmp > 32767) {
*screenYPtr = 32767;
} else if (tmp < -32768) {
*screenYPtr = -32768;
} else {
*screenYPtr = (short) tmp;
}
}
/*
*--------------------------------------------------------------
*
* Tk_CanvasGetCoord --
*
* Given a string, returns a floating-point canvas coordinate
* corresponding to that string.
*
* Results:
* The return value is a standard Tcl return result. If TCL_OK is
* returned, then everything went well and the canvas coordinate is
* stored at *doublePtr; otherwise TCL_ERROR is returned and an error
* message is left in the interp's result.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
int
Tk_CanvasGetCoord(
TCL_UNUSED(Tcl_Interp *), /* Interpreter for error reporting. */
Tk_Canvas canvas, /* Canvas to which coordinate applies. */
const char *string, /* Describes coordinate (any screen coordinate
* form may be used here). */
double *doublePtr) /* Place to store converted coordinate. */
{
if (Tk_GetScreenMM(Canvas(canvas)->interp, Canvas(canvas)->tkwin, string,
doublePtr) != TCL_OK) {
return TCL_ERROR;
}
*doublePtr *= Canvas(canvas)->pixelsPerMM;
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* Tk_CanvasGetCoordFromObj --
*
* Given a string, returns a floating-point canvas coordinate
* corresponding to that string.
*
* Results:
* The return value is a standard Tcl return result. If TCL_OK is
* returned, then everything went well and the canvas coordinate is
* stored at *doublePtr; otherwise TCL_ERROR is returned and an error
* message is left in interp->result.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
int
Tk_CanvasGetCoordFromObj(
TCL_UNUSED(Tcl_Interp *), /* Interpreter for error reporting. */
Tk_Canvas canvas, /* Canvas to which coordinate applies. */
Tcl_Obj *obj, /* Describes coordinate (any screen coordinate
* form may be used here). */
double *doublePtr) /* Place to store converted coordinate. */
{
return Tk_GetDoublePixelsFromObj(Canvas(canvas)->interp, Canvas(canvas)->tkwin, obj, doublePtr);
}
/*
*----------------------------------------------------------------------
*
* Tk_CanvasSetStippleOrigin --
*
* This function sets the stipple origin in a graphics context so that
* stipples drawn with the GC will line up with other stipples previously
* drawn in the canvas.
*
* Results:
* None.
*
* Side effects:
* The graphics context is modified.
*
*----------------------------------------------------------------------
*/
void
Tk_CanvasSetStippleOrigin(
Tk_Canvas canvas, /* Token for a canvas. */
GC gc) /* Graphics context that is about to be used
* to draw a stippled pattern as part of
* redisplaying the canvas. */
{
XSetTSOrigin(Canvas(canvas)->display, gc,
-Canvas(canvas)->drawableXOrigin,
-Canvas(canvas)->drawableYOrigin);
}
/*
*----------------------------------------------------------------------
*
* Tk_CanvasSetOffset--
*
* This function sets the stipple offset in a graphics context so that
* stipples drawn with the GC will line up with other stipples with the
* same offset.
*
* Results:
* None.
*
* Side effects:
* The graphics context is modified.
*
*----------------------------------------------------------------------
*/
void
Tk_CanvasSetOffset(
Tk_Canvas canvas, /* Token for a canvas. */
GC gc, /* Graphics context that is about to be used
* to draw a stippled pattern as part of
* redisplaying the canvas. */
Tk_TSOffset *offset) /* Offset (may be NULL pointer)*/
{
TkCanvas *canvasPtr = Canvas(canvas);
int flags = 0;
int x = - canvasPtr->drawableXOrigin;
int y = - canvasPtr->drawableYOrigin;
if (offset != NULL) {
flags = offset->flags;
x += offset->xoffset;
y += offset->yoffset;
}
if ((flags & TK_OFFSET_RELATIVE) && !(flags & TK_OFFSET_INDEX)) {
Tk_SetTSOrigin(canvasPtr->tkwin, gc, x - canvasPtr->xOrigin,
y - canvasPtr->yOrigin);
} else {
XSetTSOrigin(canvasPtr->display, gc, x, y);
}
}
/*
*----------------------------------------------------------------------
*
* Tk_CanvasGetTextInfo --
*
* This function returns a pointer to a structure containing information
* about the selection and insertion cursor for a canvas widget. Items
* such as text items save the pointer and use it to share access to the
* information with the generic canvas code.
*
* Results:
* The return value is a pointer to the structure holding text
* information for the canvas. Most of the fields should not be modified
* outside the generic canvas code; see the user documentation for
* details.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
Tk_CanvasTextInfo *
Tk_CanvasGetTextInfo(
Tk_Canvas canvas) /* Token for the canvas widget. */
{
return &Canvas(canvas)->textInfo;
}
/*
*--------------------------------------------------------------
*
* Tk_CanvasTagsParseProc --
*
* This function is invoked during option processing to handle "-tags"
* options for canvas items.
*
* Results:
* A standard Tcl return value.
*
* Side effects:
* The tags for a given item get replaced by those indicated in the value
* argument.
*
*--------------------------------------------------------------
*/
int
Tk_CanvasTagsParseProc(
TCL_UNUSED(void *),
Tcl_Interp *interp, /* Used for reporting errors. */
TCL_UNUSED(Tk_Window), /* Window containing canvas widget. */
const char *value, /* Value of option (list of tag names). */
char *widgRec, /* Pointer to record for item. */
TCL_UNUSED(Tcl_Size)) /* Offset into item (ignored). */
{
Tk_Item *itemPtr = (Tk_Item *) widgRec;
Tcl_Size argc, i;
const char **argv;
Tk_Uid *newPtr;
/*
* Break the value up into the individual tag names.
*/
if (Tcl_SplitList(interp, value, &argc, &argv) != TCL_OK) {
return TCL_ERROR;
}
/*
* Make sure that there's enough space in the item to hold the tag names.
*/
if (itemPtr->tagSpace < argc) {
newPtr = (Tk_Uid *)ckalloc(argc * sizeof(Tk_Uid));
for (i = itemPtr->numTags - 1; i != TCL_INDEX_NONE; i--) {
newPtr[i] = itemPtr->tagPtr[i];
}
if (itemPtr->tagPtr != itemPtr->staticTagSpace) {
ckfree(itemPtr->tagPtr);
}
itemPtr->tagPtr = newPtr;
itemPtr->tagSpace = argc;
}
itemPtr->numTags = argc;
for (i = 0; i < argc; i++) {
itemPtr->tagPtr[i] = Tk_GetUid(argv[i]);
}
ckfree(argv);
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* Tk_CanvasTagsPrintProc --
*
* This function is invoked by the Tk configuration code to produce a
* printable string for the "-tags" configuration option for canvas
* items.
*
* Results:
* The return value is a string describing all the tags for the item
* referred to by "widgRec". In addition, *freeProcPtr is filled in with
* the address of a function to call to free the result string when it's
* no longer needed (or NULL to indicate that the string doesn't need to
* be freed).
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
const char *
Tk_CanvasTagsPrintProc(
TCL_UNUSED(void *),
TCL_UNUSED(Tk_Window), /* Window containing canvas widget. */
char *widgRec, /* Pointer to record for item. */
TCL_UNUSED(Tcl_Size), /* Ignored. */
Tcl_FreeProc **freeProcPtr) /* Pointer to variable to fill in with
* information about how to reclaim storage
* for return string. */
{
Tk_Item *itemPtr = (Tk_Item *) widgRec;
if (itemPtr->numTags == 0) {
*freeProcPtr = NULL;
return "";
}
if (itemPtr->numTags == 1) {
*freeProcPtr = NULL;
return (const char *) itemPtr->tagPtr[0];
}
*freeProcPtr = TCL_DYNAMIC;
return Tcl_Merge(itemPtr->numTags, (const char **) itemPtr->tagPtr);
}
/*
*--------------------------------------------------------------
*
* TkCanvasDashParseProc --
*
* This function is invoked during option processing to handle "-dash",
* "-activedash" and "-disableddash" options for canvas objects.
*
* Results:
* A standard Tcl return value.
*
* Side effects:
* The dash list for a given canvas object gets replaced by those
* indicated in the value argument.
*
*--------------------------------------------------------------
*/
int
TkCanvasDashParseProc(
TCL_UNUSED(void *),
Tcl_Interp *interp, /* Used for reporting errors. */
TCL_UNUSED(Tk_Window), /* Window containing canvas widget. */
const char *value, /* Value of option. */
char *widgRec, /* Pointer to record for item. */
Tcl_Size offset) /* Offset into item. */
{
return Tk_GetDash(interp, value, (Tk_Dash *) (widgRec+offset));
}
/*
*--------------------------------------------------------------
*
* TkCanvasDashPrintProc --
*
* This function is invoked by the Tk configuration code to produce a
* printable string for the "-dash", "-activedash" and "-disableddash"
* configuration options for canvas items.
*
* Results:
* The return value is a string describing all the dash list for the item
* referred to by "widgRec"and "offset". In addition, *freeProcPtr is
* filled in with the address of a function to call to free the result
* string when it's no longer needed (or NULL to indicate that the string
* doesn't need to be freed).
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
const char *
TkCanvasDashPrintProc(
TCL_UNUSED(void *),
TCL_UNUSED(Tk_Window), /* Window containing canvas widget. */
char *widgRec, /* Pointer to record for item. */
Tcl_Size offset, /* Offset in record for item. */
Tcl_FreeProc **freeProcPtr) /* Pointer to variable to fill in with
* information about how to reclaim storage
* for return string. */
{
Tk_Dash *dash = (Tk_Dash *) (widgRec+offset);
char *buffer, *p;
int i = dash->number;
if (i < 0) {
i = -i;
*freeProcPtr = TCL_DYNAMIC;
buffer = (char *)ckalloc((Tcl_Size)i + 1);
p = (i > (int)sizeof(char *)) ? dash->pattern.pt : dash->pattern.array;
memcpy(buffer, p, (unsigned int) i);
buffer[i] = 0;
return buffer;
} else if (!i) {
*freeProcPtr = NULL;
return "";
}
buffer = (char *)ckalloc(4 * (Tcl_Size)i);
*freeProcPtr = TCL_DYNAMIC;
p = (i > (int)sizeof(char *)) ? dash->pattern.pt : dash->pattern.array;
snprintf(buffer, 4 * (size_t)i, "%d", *p++ & 0xff);
while (--i) {
snprintf(buffer + strlen(buffer), 4 * (size_t)i - strlen(buffer), " %d", *p++ & 0xff);
}
return buffer;
}
/*
*--------------------------------------------------------------
*
* InitSmoothMethods --
*
* This function is invoked to set up the initial state of the list of
* "-smooth" methods. It should only be called when the list installed
* in the interpreter is NULL.
*
* Results:
* Pointer to the start of the list of default smooth methods.
*
* Side effects:
* A linked list of smooth methods is created and attached to the
* interpreter's association key "smoothMethod"
*
*--------------------------------------------------------------
*/
static SmoothAssocData *
InitSmoothMethods(
Tcl_Interp *interp)
{
SmoothAssocData *methods, *ptr;
methods = (SmoothAssocData *)ckalloc(sizeof(SmoothAssocData));
methods->smooth.name = tkRawSmoothMethod.name;
methods->smooth.coordProc = tkRawSmoothMethod.coordProc;
methods->smooth.postscriptProc = tkRawSmoothMethod.postscriptProc;
ptr = methods->nextPtr = (SmoothAssocData *)ckalloc(sizeof(SmoothAssocData));
ptr->smooth.name = tkBezierSmoothMethod.name;
ptr->smooth.coordProc = tkBezierSmoothMethod.coordProc;
ptr->smooth.postscriptProc = tkBezierSmoothMethod.postscriptProc;
ptr->nextPtr = NULL;
Tcl_SetAssocData(interp, "smoothMethod", SmoothMethodCleanupProc,methods);
return methods;
}
/*
*--------------------------------------------------------------
*
* Tk_CreateSmoothMethod --
*
* This function is invoked to add additional values for the "-smooth"
* option to the list.
*
* Results:
* A standard Tcl return value.
*
* Side effects:
* In the future "-smooth <name>" will be accepted as smooth method for
* the line and polygon.
*
*--------------------------------------------------------------
*/
void
Tk_CreateSmoothMethod(
Tcl_Interp *interp,
const Tk_SmoothMethod *smooth)
{
SmoothAssocData *methods, *typePtr2, *prevPtr, *ptr;
methods = (SmoothAssocData *)Tcl_GetAssocData(interp, "smoothMethod", NULL);
/*
* Initialize if we were not previously initialized.
*/
if (methods == NULL) {
methods = InitSmoothMethods(interp);
}
/*
* If there's already a smooth method with the given name, remove it.
*/
for (typePtr2 = methods, prevPtr = NULL; typePtr2 != NULL;
prevPtr = typePtr2, typePtr2 = typePtr2->nextPtr) {
if (!strcmp(typePtr2->smooth.name, smooth->name)) {
if (prevPtr == NULL) {
methods = typePtr2->nextPtr;
} else {
prevPtr->nextPtr = typePtr2->nextPtr;
}
ckfree(typePtr2);
break;
}
}
ptr = (SmoothAssocData *)ckalloc(sizeof(SmoothAssocData));
ptr->smooth.name = smooth->name;
ptr->smooth.coordProc = smooth->coordProc;
ptr->smooth.postscriptProc = smooth->postscriptProc;
ptr->nextPtr = methods;
Tcl_SetAssocData(interp, "smoothMethod", SmoothMethodCleanupProc, ptr);
}
/*
*----------------------------------------------------------------------
*
* SmoothMethodCleanupProc --
*
* This function is invoked whenever an interpreter is deleted to
* cleanup the smooth methods.
*
* Results:
* None.
*
* Side effects:
* Smooth methods are removed.
*
*----------------------------------------------------------------------
*/
static void
SmoothMethodCleanupProc(
void *clientData, /* Points to "smoothMethod" AssocData for the
* interpreter. */
TCL_UNUSED(Tcl_Interp *)) /* Interpreter that is being deleted. */
{
SmoothAssocData *ptr, *methods = (SmoothAssocData *)clientData;
while (methods != NULL) {
ptr = methods;
methods = methods->nextPtr;
ckfree(ptr);
}
}
/*
*--------------------------------------------------------------
*
* TkSmoothParseProc --
*
* This function is invoked during option processing to handle the
* "-smooth" option.
*
* Results:
* A standard Tcl return value.
*
* Side effects:
* The smooth option for a given item gets replaced by the value
* indicated in the value argument.
*
*--------------------------------------------------------------
*/
int
TkSmoothParseProc(
TCL_UNUSED(void *),
Tcl_Interp *interp, /* Used for reporting errors. */
TCL_UNUSED(Tk_Window), /* Window containing canvas widget. */
const char *value, /* Value of option. */
char *widgRec, /* Pointer to record for item. */
Tcl_Size offset) /* Offset into item. */
{
const Tk_SmoothMethod **smoothPtr =
(const Tk_SmoothMethod **) (widgRec + offset);
const Tk_SmoothMethod *smooth = NULL;
int b;
size_t length;
SmoothAssocData *methods;
if (value == NULL || *value == 0) {
*smoothPtr = NULL;
return TCL_OK;
}
length = strlen(value);
methods = (SmoothAssocData *)Tcl_GetAssocData(interp, "smoothMethod", NULL);
/*
* Not initialized yet; fix that now.
*/
if (methods == NULL) {
methods = InitSmoothMethods(interp);
}
/*
* Backward compatibility hack.
*/
if (strncmp(value, "bezier", length) == 0) {
smooth = &tkBezierSmoothMethod;
}
/*
* Search the list of installed smooth methods.
*/
while (methods != NULL) {
if (strncmp(value, methods->smooth.name, length) == 0) {
if (smooth != NULL) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"ambiguous smooth method \"%s\"", value));
Tcl_SetErrorCode(interp, "TK", "LOOKUP", "SMOOTH", value,
(char *)NULL);
return TCL_ERROR;
}
smooth = &methods->smooth;
}
methods = methods->nextPtr;
}
if (smooth) {
*smoothPtr = smooth;
return TCL_OK;
}
/*
* Did not find it. Try parsing as a boolean instead.
*/
if (Tcl_GetBoolean(interp, (char *) value, &b) != TCL_OK) {
return TCL_ERROR;
}
*smoothPtr = b ? &tkBezierSmoothMethod : NULL;
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* TkSmoothPrintProc --
*
* This function is invoked by the Tk configuration code to produce a
* printable string for the "-smooth" configuration option.
*
* Results:
* The return value is a string describing the smooth option for the item
* referred to by "widgRec". In addition, *freeProcPtr is filled in with
* the address of a function to call to free the result string when it's
* no longer needed (or NULL to indicate that the string doesn't need to
* be freed).
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
const char *
TkSmoothPrintProc(
TCL_UNUSED(void *),
TCL_UNUSED(Tk_Window), /* Window containing canvas widget. */
char *widgRec, /* Pointer to record for item. */
Tcl_Size offset, /* Offset into item. */
TCL_UNUSED(Tcl_FreeProc **)) /* Pointer to variable to fill in with
* information about how to reclaim storage
* for return string. */
{
const Tk_SmoothMethod *smoothPtr =
* (Tk_SmoothMethod **) (widgRec + offset);
return smoothPtr ? smoothPtr->name : "0";
}
/*
*--------------------------------------------------------------
*
* Tk_GetDash
*
* This function is used to parse a string, assuming it is dash
* information.
*
* Results:
* The return value is a standard Tcl result: TCL_OK means that the dash
* information was parsed ok, and TCL_ERROR means it couldn't be parsed.
*
* Side effects:
* Dash information in the dash structure is updated.
*
*--------------------------------------------------------------
*/
int
Tk_GetDash(
Tcl_Interp *interp, /* Used for error reporting. */
const char *value, /* Textual specification of dash list. */
Tk_Dash *dash) /* Pointer to record in which to store dash
* information. */
{
Tcl_Size argc;
int i;
const char **largv, **argv = NULL;
char *pt;
if ((value == NULL) || (*value == '\0')) {
dash->number = 0;
return TCL_OK;
}
/*
* switch is usually compiled more efficiently than a chain of conditions.
*/
switch (*value) {
case '.': case ',': case '-': case '_':
i = DashConvert(NULL, value, -1, 0.0);
if (i <= 0) {
goto badDashList;
}
i = (int)strlen(value);
if (i > (int) sizeof(char *)) {
dash->pattern.pt = pt = (char *)ckalloc(strlen(value));
} else {
pt = dash->pattern.array;
}
memcpy(pt, value, (unsigned) i);
dash->number = -i;
return TCL_OK;
}
if (Tcl_SplitList(interp, (char *) value, &argc, &argv) != TCL_OK) {
Tcl_ResetResult(interp);
goto badDashList;
}
if ((unsigned) ABS(dash->number) > sizeof(char *)) {
ckfree(dash->pattern.pt);
}
if (argc > (int) sizeof(char *)) {
dash->pattern.pt = pt = (char *)ckalloc(argc);
} else {
pt = dash->pattern.array;
}
dash->number = argc;
largv = argv;
while (argc > 0) {
if (Tcl_GetInt(interp, *largv, &i) != TCL_OK || i < 1 || i>255) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"expected integer in the range 1..255 but got \"%s\"",
*largv));
Tcl_SetErrorCode(interp, "TK", "VALUE", "DASH", (char *)NULL);
goto syntaxError;
}
*pt++ = i;
argc--;
largv++;
}
if (argv != NULL) {
ckfree(argv);
}
return TCL_OK;
/*
* Something went wrong. Generate error message, clean up and return.
*/
badDashList:
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"bad dash list \"%s\": must be a list of integers or a format like \"-..\"",
value));
Tcl_SetErrorCode(interp, "TK", "VALUE", "DASH", (char *)NULL);
syntaxError:
if (argv != NULL) {
ckfree(argv);
}
if ((unsigned) ABS(dash->number) > sizeof(char *)) {
ckfree(dash->pattern.pt);
}
dash->number = 0;
return TCL_ERROR;
}
/*
*--------------------------------------------------------------
*
* Tk_CreateOutline
*
* This function initializes the Tk_Outline structure with default
* values.
*
* Results:
* None
*
* Side effects:
* None
*
*--------------------------------------------------------------
*/
void
Tk_CreateOutline(
Tk_Outline *outline) /* Outline structure to be filled in. */
{
outline->gc = NULL;
outline->width = 1.0;
outline->activeWidth = 0.0;
outline->disabledWidth = 0.0;
outline->offset = 0;
outline->offsetObj = NULL;
outline->reserved2 = NULL;
outline->reserved3 = NULL;
outline->dash.number = 0;
outline->activeDash.number = 0;
outline->disabledDash.number = 0;
outline->tsoffset.flags = 0;
outline->tsoffset.xoffset = 0;
outline->tsoffset.yoffset = 0;
outline->color = NULL;
outline->activeColor = NULL;
outline->disabledColor = NULL;
outline->stipple = None;
outline->activeStipple = None;
outline->disabledStipple = None;
}
/*
*--------------------------------------------------------------
*
* Tk_DeleteOutline
*
* This function frees all memory that might be allocated and referenced
* in the Tk_Outline structure.
*
* Results:
* None