Skip Menu |

This queue is for tickets about the Tk CPAN distribution.

Report information
The Basics
Id: 11083
Status: resolved
Priority: 0/
Queue: Tk

People
Owner: Nobody in particular
Requestors: wolfgang.laun [...] alcatel.at
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 804.027
Fixed in: (no value)



Subject: Tk::Canvas: -dash, Bitmap
Here are some patches against bugs in Tk-804.027. I've tested them on Linux only. Some of the fixes may have to go into the original Tk code and documentation. Correcting the handling of the -dash option for canvas items ------------------------------------------------------------ The problems addressed by this patch are: (1) For all canvas items supporting the option -dash, any pattern specified as a list of exactly two identical integers, e.g. -dash => [ 4, 4 ] is ignored, and a solid line is drawn. (2) With a list consisting of a single integer, or a scalar integer, e.g. -dash => [ 4 ] -dash => 4 no error is reported. (3) Error reporting is broken in some cases (producing weird messages about bad utf8 encoding), e.g. -dash => ',;' -dash => [ 'x', 4 ] (4) The feature of specifying dash patterns by a string consisting of [.,-_ ] isn't implemented according to the documentation: (a) The '.' should produce a "dot", but results in a 2x1-rectangle. Since all other values are longer, there is no way to produces "dots". (b) According to the examples, a defult gap has the same width as a dash resulting from a ",". An additional space, however, increments the preceding gap by the -width value plus 1, which is surprising and, moreover, doesn't scale well with increased width. (5) If some dash or gap length resulting from a string specification exceeds the capacity of a char (UCHAR_MAX), the result is silently taken modulo 256. Using UCHAR_MAX appears to be closer to the real value. (Perhaps raising a fatal error would be even better.) (6) Outlines of rectangles and ovals are drawn as solid lines whenever the width is greater than or equal to the gap. The fix of (4) is bound to change the behaviour of existing programs using this form of dash specifications. If this must be avoided, the documentation would have to be rewritten. Affected files: pTk/tkCanvUtil.c, pTk/tkRectOval.c, pod/Canvas.pod Documenting and checking a restriction on canvas bitmaps -------------------------------------------------------- This patch does two things: First it documents the restriction that a set of canvas bitmaps specified as the normal, active and disabled bitmap must have identical dimensions. Second, it adds a check, resulting in an error if this is rule violated. Trying to use bitmaps of various x- and/or y-sizes results in the active or disabled bitmap to appear in wrong positions with respect to the anchor. Fixing this (e.g. by computing the minimum-maximum rectangle across all bitmaps) doesn't help because drawing a bitmap is still restricted to the bitmap's own rectangle. Even if this were fixed, it'd still not be satisfactory. Consider the case where the cursor hits the 'normal' bitmap in an area that is not covered by the 'active' bitmap. This would then result in the 'active' bitmap replacing the 'normal' one - but then the cursor won't be on the bitmap any more, so that the 'normal' one would return, and so on. Affected files: pTk/tkCanvBmap.c, pod/Canvas.pod
{\rtf1\ansi\ansicpg1252\deff0\deflang1031{\fonttbl{\f0\froman\fcharset0 Times New Roman;}{\f1\fswiss\fcharset0 Arial;}} \viewkind4\uc1\pard\f0\fs20 --- pTk/tkCanvUtil.c.old Sun Dec 26 19:06:26 2004\fs24 \line\fs20 +++ pTk/tkCanvUtil.c Sun Dec 26 19:06:58 2004\fs24 \line\fs20 @@ -798,9 +798,7 @@\fs24 \line\fs20 if ((*value == '.') || (*value == ',') ||\fs24 \line\fs20 (*value == '-') || (*value == '_')) \{\fs24 \line\fs20 i = DashConvert( NULL, value, -1, 0.0);\fs24 \line\fs20 - if (i>0) \{\fs24 \line\fs20 - i = strlen(value);\fs24 \line\fs20 - \} else \{\fs24 \line\fs20 + if (i<0) \{\fs24 \line\fs20 goto badDashList;\fs24 \line\fs20\}\fs24 \line\fs20 if (i > (int) sizeof(char *)) \{\fs24 \line\fs20 @@ -812,7 +810,8 @@\fs24 \line\fs20 dash->number = -i;\fs24 \line\fs20 return TCL_OK;\fs24 \line\fs20\}\fs24 \line\fs20 - if (Tcl_ListObjGetElements(interp, ovalue, &argc, &objv) != TCL_OK)\fs24 \line\fs20\{\fs24 \line\fs20 + if (Tcl_ListObjGetElements(interp, ovalue, &argc, &objv) != TCL_OK\fs24 \line\fs20 ||\fs24 \line\fs20 + argc <= 1) \{\fs24 \line\fs20 Tcl_ResetResult(interp);\fs24 \line\fs20 badDashList:\fs24 \line\fs20 Tcl_AppendResult(interp, "bad dash list \\"", value,\fs24 \line\fs20 @@ -841,7 +840,7 @@\fs24 \line\fs20 i < 1 || i>255) \{\fs24 \line\fs20 Tcl_ResetResult(interp);\fs24 \line\fs20 Tcl_AppendResult(interp, "expected integer in the range\fs24 \line\fs20 1..255 but got \\"",\fs24 \line\fs20 - *largv, "\\"", NULL);\fs24 \line\fs20 + Tcl_GetString(*largv), "\\"",\fs24 \line\fs20 NULL);\fs24 \line\fs20 goto syntaxError;\fs24 \line\fs20\}\fs24 \line\fs20 *pt++ = i;\fs24 \line\fs20 @@ -1054,8 +1053,6 @@\fs24 \line\fs20 gcValues->dash_offset = outline->offset;\fs24 \line\fs20 if (dash->number >= 2) \{\fs24 \line\fs20 gcValues->dashes = 4;\fs24 \line\fs20 - \} else if (dash->number > 0) \{\fs24 \line\fs20 - gcValues->dashes = dash->pattern.array[0];\fs24 \line\fs20\} else \{\fs24 \line\fs20 gcValues->dashes = (char) (4 * width);\fs24 \line\fs20\}\fs24 \line\fs20 @@ -1141,7 +1138,7 @@\fs24 \line\fs20 return 0;\fs24 \line\fs20\}\fs24 \line\line\fs20 - if ((dash->number<-1) || ((dash->number == -1) &&\fs24 \line\fs20 (dash->pattern.array[1]!=','))) \{\fs24 \line\fs20 + if ( dash->number<=-2 ) \{\fs24 \line\fs20 char *q;\fs24 \line\fs20 int i = -dash->number;\fs24 \line\line\fs20 @@ -1151,8 +1148,7 @@\fs24 \line\fs20 XSetDashes(((TkCanvas *)canvas)->display, outline->gc,\fs24 \line\fs20 outline->offset, q, i);\fs24 \line\fs20 values.line_style = LineOnOffDash;\fs24 \line\fs20 ckfree(q);\fs24 \line\fs20 - \} else if ( dash->number>2 || (dash->number==2 &&\fs24 \line\fs20 - (dash->pattern.array[0]!=dash->pattern.array[1]))) \{\fs24 \line\fs20 + \} else if ( dash->number>=2 ) \{\fs24 \line\fs20 p = (char *) (dash->number > (int) sizeof(char *)) ?\fs24 \line\fs20 dash->pattern.pt : dash->pattern.array;\fs24 \line\fs20 XSetDashes(((TkCanvas *)canvas)->display, outline->gc,\fs24 \line\fs20 outline->offset, p, dash->number);\fs24 \line\fs20 values.line_style = LineOnOffDash;\fs24 \line\fs20 @@ -1262,13 +1258,9 @@\fs24 \line\fs20 return 0;\fs24 \line\fs20\}\fs24 \line\line\fs20 - if ((dash->number > 2) || (dash->number < -1) || (dash->number==2\fs24 \line\fs20 &&\fs24 \line\fs20 - (dash->pattern.array[0] != dash->pattern.array[1])) ||\fs24 \line\fs20 - ((dash->number == -1) && (dash->pattern.array[1] !=\fs24 \line\fs20 ','))) \{\fs24 \line\fs20 + if ( (dash->number >= 2) || (dash->number <= -2) ) \{\fs24 \line\fs20 if (dash->number < 0) \{\fs24 \line\fs20 dashList = (int) (4 * width + 0.5);\fs24 \line\fs20 - \} else if (dash->number<3) \{\fs24 \line\fs20 - dashList = dash->pattern.array[0];\fs24 \line\fs20\} else \{\fs24 \line\fs20 dashList = 4;\fs24 \line\fs20\}\fs24 \line\fs20 @@ -1449,7 +1441,7 @@\fs24 \line\fs20 double width;\fs24 \line\fs20\{\fs24 \line\fs20 int result = 0;\fs24 \line\fs20 - int size, intWidth;\fs24 \line\fs20 + int size, intWidth, actWidth;\fs24 \line\line\fs20 if (n<0) \{\fs24 \line\fs20 n = strlen(p);\fs24 \line\fs20 @@ -1463,7 +1455,7 @@\fs24 \line\fs20 case ' ':\fs24 \line\fs20 if (result) \{\fs24 \line\fs20 if (l) \{\fs24 \line\fs20 - l[-1] += intWidth + 1;\fs24 \line\fs20 + l[-1] += intWidth;\fs24 \line\fs20\}\fs24 \line\fs20 continue;\fs24 \line\fs20\} else \{\fs24 \line\fs20 @@ -1471,23 +1463,25 @@\fs24 \line\fs20\}\fs24 \line\fs20 break;\fs24 \line\fs20 case '_':\fs24 \line\fs20 - size = 8;\fs24 \line\fs20 + size = 4;\fs24 \line\fs20 break;\fs24 \line\fs20 case '-':\fs24 \line\fs20 - size = 6;\fs24 \line\fs20 + size = 3;\fs24 \line\fs20 break;\fs24 \line\fs20 case ',':\fs24 \line\fs20 - size = 4;\fs24 \line\fs20 + size = 2;\fs24 \line\fs20 break;\fs24 \line\fs20 case '.':\fs24 \line\fs20 - size = 2;\fs24 \line\fs20 + size = 1;\fs24 \line\fs20 break;\fs24 \line\fs20 default:\fs24 \line\fs20 return -1;\fs24 \line\fs20\}\fs24 \line\fs20 if (l) \{\fs24 \line\fs20 - *l++ = size * intWidth;\fs24 \line\fs20 - *l++ = 4 * intWidth;\fs24 \line\fs20 + actWidth = size * intWidth;\fs24 \line\fs20 + *l++ = actWidth > UCHAR_MAX ? UCHAR_MAX : actWidth;\fs24 \line\fs20 + actWidth = 2 * intWidth;\fs24 \line\fs20 + *l++ = actWidth > UCHAR_MAX ? UCHAR_MAX : actWidth;\fs24 \line\fs20\}\fs24 \line\fs20 result += 2;\fs24 \line\fs20\}\fs24 \line\fs20 --- pTk/tkRectOval.c.old Tue Dec 28 07:39:21 2004\fs24 \line\fs20 +++ pTk/tkRectOval.c Tue Dec 28 08:07:29 2004\fs24 \line\fs20 @@ -476,8 +476,6 @@\fs24 \line\fs20 if (mask && \\\fs24 \line\fs20 rectOvalPtr->outline.width != 0 && \\\fs24 \line\fs20 rectOvalPtr->outline.color != NULL) \{\fs24 \line\fs20 - gcValues.cap_style = CapProjecting;\fs24 \line\fs20 - mask |= GCCapStyle;\fs24 \line\fs20 newGC = Tk_GetGC(tkwin, mask, &gcValues);\fs24 \line\fs20\} else \{\fs24 \line\fs20 newGC = None;\fs24 \line\fs20 --- pTk/tkCanvBmap.c.old Wed Nov 24 11:13:10 2004\fs24 \line\fs20 +++ pTk/tkCanvBmap.c Sat Dec 18 22:46:23 2004\fs24 \line\fs20 @@ -331,6 +331,8 @@\fs24 \line\fs20 XColor *bgColor;\fs24 \line\fs20 Pixmap bitmap;\fs24 \line\fs20 Tk_State state;\fs24 \line\fs20 + int width, height;\fs24 \line\fs20 + int width1, height1;\fs24 \line\line\fs20 tkwin = Tk_CanvasTkwin(canvas);\fs24 \line\fs20 if (TCL_OK != Tk_ConfigureWidget(interp, tkwin, configSpecs, objc,\fs24 \line\fs20 @@ -353,6 +355,28 @@\fs24 \line\fs20 itemPtr->redraw_flags &= ~TK_ITEM_STATE_DEPENDANT;\fs24 \line\fs20\}\fs24 \line\line\fs20 + /* Check that bitmaps have same width and height */\fs24 \line\fs20 + Tk_SizeOfBitmap(Tk_Display(Tk_CanvasTkwin(canvas)),\fs24 \line\fs20 bmapPtr->bitmap,\fs24 \line\fs20 + &width, &height);\fs24 \line\fs20 + if (bmapPtr->activeBitmap!=None) \{\fs24 \line\fs20 + Tk_SizeOfBitmap(Tk_Display(Tk_CanvasTkwin(canvas)),\fs24 \line\fs20 + bmapPtr->activeBitmap,\fs24 \line\fs20 + &width1, &height1);\fs24 \line\fs20 + if (width != width1 || height != height1) \{\fs24 \line\fs20 + Tcl_SetResult(interp, "active bitmap dimensions differ",\fs24 \line\fs20 TCL_STATIC);\fs24 \line\fs20 + return TCL_ERROR;\fs24 \line\fs20 + \}\fs24 \line\fs20 + \}\fs24 \line\fs20 + if (bmapPtr->disabledBitmap!=None) \{\fs24 \line\fs20 + Tk_SizeOfBitmap(Tk_Display(Tk_CanvasTkwin(canvas)),\fs24 \line\fs20 + bmapPtr->disabledBitmap,\fs24 \line\fs20 + &width1, &height1);\fs24 \line\fs20 + if (width != width1 || height != height1) \{\fs24 \line\fs20 + Tcl_SetResult(interp, "disabled bitmap dimensions differ",\fs24 \line\fs20 TCL_STATIC);\fs24 \line\fs20 + return TCL_ERROR;\fs24 \line\fs20 + \}\fs24 \line\fs20 + \}\fs24 \line\fs20 +\fs24 \line\fs20 if (state==TK_STATE_HIDDEN) \{\fs24 \line\fs20 ComputeBitmapBbox(canvas, bmapPtr);\fs24 \line\fs20 return TCL_OK;\fs24 \line\fs20 --- pod/Canvas.pod.old Sat Dec 25 10:34:16 2004\fs24 \line\fs20 +++ pod/Canvas.pod Sun Dec 26 18:45:41 2004\fs24 \line\fs20 @@ -346,26 +346,29 @@\fs24 \line\fs20 The first possible syntax is a list of integers. Each element\fs24 \line\fs20 represents the number of pixels of a line segment. Only the odd\fs24 \line\fs20 segments are drawn using the "outline" color. The other segments\fs24 \line\fs20 -are drawn transparant.\fs24 \line\fs20 +are drawn transparent.\fs24 \line\line\fs20 The second possible syntax is a character list containing only\fs24 \line\fs20 -5 possible characters B<[.,-_ ]>. The space can be used\fs24 \line\fs20 -to enlarge the space between other line elements, and can not\fs24 \line\fs20 -occur as the first position in the string. Some examples:\fs24 \line\fs20 +5 possible characters B<[.,-_ ]>, with the first 4 characters\fs24 \line\fs20 +producing a segment of length 1 to 4, respectively, followed\fs24 \line\fs20 +by a transparent segment of length 2. The space can be used\fs24 \line\fs20 +repeatedly to enlarge the space between other line elements\fs24 \line\fs20 +by 1, and can not occur as the first position in the string.\fs24 \line\fs20 +The main difference of this syntax with the previous is that it\fs24 \line\fs20 +it shape-conserving. This means that all values in the dash\fs24 \line\fs20 +list will be multiplied by the line width before display. This\fs24 \line\fs20 +assures that "." will always be displayed as a dot and "-"\fs24 \line\fs20 +always as a dash regardless of the line width.\fs24 \line\fs20 +\fs24 \line\fs20 +Some examples, for a line width of 2:\fs24 \line\line\fs20 -dash . = -dash [2,4]\fs24 \line\fs20 -dash - = -dash [6,4]\fs24 \line\fs20 -dash -. = -dash [6,4,2,4]\fs24 \line\fs20 -dash -.. = -dash [6,4,2,4,2,4]\fs24 \line\fs20 - -dash '. ' = -dash [2,8]\fs24 \line\fs20 + -dash '. ' = -dash [2,6]\fs24 \line\fs20 -dash ',' = -dash [4,4]\fs24 \line\line\fs20 -The main difference of this syntax with the previous is that it\fs24 \line\fs20 -it shape-conserving. This means that all values in the dash\fs24 \line\fs20 -list will be multiplied by the line width before display. This\fs24 \line\fs20 -assures that "." will always be displayed as a dot and "-"\fs24 \line\fs20 -always as a dash regardless of the line width.\fs24 \line\fs20 -\fs24 \line\fs20 On systems where only a limited set of dash patterns, the dash\fs24 \line\fs20 pattern will be displayed as the most close dash pattern that\fs24 \line\fs20 is available. For example, on Windows only the first 4 of the\fs24 \line\fs20 @@ -1355,14 +1358,14 @@\fs24 \line\fs20 =item B<-disabledbitmap> =E<gt> I<bitmap>\fs24 \line\line\fs20 Specifies the bitmaps to display in the item in its normal, active and\fs24 \line\fs20 -disabled states.\fs24 \line\fs20 +disabled states. All bitmaps must have the same width and height.\fs24 \line\fs20 I<Bitmap> may have any of the forms accepted by B<Tk_GetBitmap>.\fs24 \line\line\fs20 =item B<-foreground> =E<gt> I<color>\fs24 \line\line\fs20 -=item B<-activeforeground> =E<gt> I<bitmap>\fs24 \line\fs20 +=item B<-activeforeground> =E<gt> I<color>\fs24 \line\line\fs20 -=item B<-disabledforeground> =E<gt> I<bitmap>\fs24 \line\fs20 +=item B<-disabledforeground> =E<gt> I<color>\fs24 \line\line\fs20 Specifies the color to use for each of the bitmap's '1' valued pixels\fs24 \line\fs20 in its normal, active and disabled states.\fs24 \par \f1\fs20\par }
On Wed Jan 19 08:09:43 2005, guest wrote: Show quoted text
> Here are some patches against bugs in Tk-804.027. I've > tested them on Linux only. Some of the fixes may have to > go into the original Tk code and documentation. > > > > Correcting the handling of the -dash option for canvas items > ------------------------------------------------------------ > > The problems addressed by this patch are: > > (1) For all canvas items supporting the option -dash, any pattern > specified as a list of exactly two identical integers, e.g. > -dash => [ 4, 4 ] > is ignored, and a solid line is drawn. > > (2) With a list consisting of a single integer, or a scalar integer, > e.g. > -dash => [ 4 ] > -dash => 4 > no error is reported. > > (3) Error reporting is broken in some cases (producing weird > messages about bad utf8 encoding), e.g. > -dash => ',;' > -dash => [ 'x', 4 ] > > (4) The feature of specifying dash patterns by a string consisting > of [.,-_ ] isn't implemented according to the documentation: > (a) The '.' should produce a "dot", but results in a 2x1-rectangle. > Since all other values are longer, there is no way to produces > "dots". > (b) According to the examples, a defult gap has the same width as a > dash resulting from a ",". An additional space, however, > increments the preceding gap by the -width value plus 1, which > is surprising and, moreover, doesn't scale well with increased > width. > > (5) If some dash or gap length resulting from a string specification > exceeds the capacity of a char (UCHAR_MAX), the result is > silently taken modulo 256. Using UCHAR_MAX appears to be closer > to the real value. (Perhaps raising a fatal error would be > even better.) > > (6) Outlines of rectangles and ovals are drawn as solid lines > whenever the width is greater than or equal to the gap. > > The fix of (4) is bound to change the behaviour of existing > programs using this form of dash specifications. If this must > be avoided, the documentation would have to be rewritten. > > Affected files: pTk/tkCanvUtil.c, pTk/tkRectOval.c, pod/Canvas.pod > > > > Documenting and checking a restriction on canvas bitmaps > -------------------------------------------------------- > > This patch does two things: > > First it documents the restriction that a set of canvas bitmaps > specified as the normal, active and disabled bitmap must have > identical dimensions. > > Second, it adds a check, resulting in an error if this is rule > violated. > > Trying to use bitmaps of various x- and/or y-sizes results in > the active or disabled bitmap to appear in wrong positions > with respect to the anchor. Fixing this (e.g. by computing the > minimum-maximum rectangle across all bitmaps) doesn't help > because drawing a bitmap is still restricted to the bitmap's > own rectangle. Even if this were fixed, it'd still not be > satisfactory. Consider the case where the cursor hits the > 'normal' bitmap in an area that is not covered by the 'active' > bitmap. This would then result in the 'active' bitmap replacing > the 'normal' one - but then the cursor won't be on the bitmap > any more, so that the 'normal' one would return, and so on. > > Affected files: pTk/tkCanvBmap.c, pod/Canvas.pod >
Can you check if this is still an issue in the development version of Tk (see http://search.cpan.org/~srezic/Tk-804.027_501/), and if so, can you resend the patches, as they are in an unusable format (rich text files). Regards, Slaven
Subject: Re: [rt.cpan.org #11083] Tk::Canvas: -dash, Bitmap
Date: Wed, 07 Nov 2007 12:31:50 +0100
To: bug-Tk [...] rt.cpan.org
From: Wolfgang Laun <Wolfgang.Laun [...] thalesgroup.com>
(5) was fixed but all the rest is still in Tk-804.027_501. The patch is against this version; I have retested it on Linux. Kind regards Wolfgang Slaven_Rezic via RT wrote: Show quoted text
><URL: http://rt.cpan.org/Ticket/Display.html?id=11083 > > >On Wed Jan 19 08:09:43 2005, guest wrote: > >
>>Here are some patches against bugs in Tk-804.027. I've >>tested them on Linux only. Some of the fixes may have to >>go into the original Tk code and documentation. >> >> >> >>Correcting the handling of the -dash option for canvas items >>------------------------------------------------------------ >> >>The problems addressed by this patch are: >> >>(1) For all canvas items supporting the option -dash, any pattern >>specified as a list of exactly two identical integers, e.g. >> -dash => [ 4, 4 ] >>is ignored, and a solid line is drawn. >> >>(2) With a list consisting of a single integer, or a scalar integer, >>e.g. >> -dash => [ 4 ] >> -dash => 4 >>no error is reported. >> >>(3) Error reporting is broken in some cases (producing weird >>messages about bad utf8 encoding), e.g. >> -dash => ',;' >> -dash => [ 'x', 4 ] >> >>(4) The feature of specifying dash patterns by a string consisting >>of [.,-_ ] isn't implemented according to the documentation: >>(a) The '.' should produce a "dot", but results in a 2x1-rectangle. >> Since all other values are longer, there is no way to produces >> "dots". >>(b) According to the examples, a defult gap has the same width as a >> dash resulting from a ",". An additional space, however, >> increments the preceding gap by the -width value plus 1, which >> is surprising and, moreover, doesn't scale well with increased >> width. >> >>(5) If some dash or gap length resulting from a string specification >> exceeds the capacity of a char (UCHAR_MAX), the result is >> silently taken modulo 256. Using UCHAR_MAX appears to be closer >> to the real value. (Perhaps raising a fatal error would be >> even better.) >> >>(6) Outlines of rectangles and ovals are drawn as solid lines >> whenever the width is greater than or equal to the gap. >> >>The fix of (4) is bound to change the behaviour of existing >>programs using this form of dash specifications. If this must >>be avoided, the documentation would have to be rewritten. >> >>Affected files: pTk/tkCanvUtil.c, pTk/tkRectOval.c, pod/Canvas.pod >> >> >> >>Documenting and checking a restriction on canvas bitmaps >>-------------------------------------------------------- >> >>This patch does two things: >> >>First it documents the restriction that a set of canvas bitmaps >>specified as the normal, active and disabled bitmap must have >>identical dimensions. >> >>Second, it adds a check, resulting in an error if this is rule >>violated. >> >>Trying to use bitmaps of various x- and/or y-sizes results in >>the active or disabled bitmap to appear in wrong positions >>with respect to the anchor. Fixing this (e.g. by computing the >>minimum-maximum rectangle across all bitmaps) doesn't help >>because drawing a bitmap is still restricted to the bitmap's >>own rectangle. Even if this were fixed, it'd still not be >>satisfactory. Consider the case where the cursor hits the >>'normal' bitmap in an area that is not covered by the 'active' >>bitmap. This would then result in the 'active' bitmap replacing >>the 'normal' one - but then the cursor won't be on the bitmap >>any more, so that the 'normal' one would return, and so on. >> >>Affected files: pTk/tkCanvBmap.c, pod/Canvas.pod >> >> >>
> > >Can you check if this is still an issue in the development version of Tk >(see http://search.cpan.org/~srezic/Tk-804.027_501/), and if so, can you >resend the patches, as they are in an unusable format (rich text files). > >Regards, > Slaven > > >
--- pTk/mTk/generic/tkCanvUtil.c.old 2007-02-10 12:29:06.000000000 +0100 +++ pTk/mTk/generic/tkCanvUtil.c 2007-11-07 09:57:15.000000000 +0100 @@ -798,9 +798,7 @@ if ((*value == '.') || (*value == ',') || (*value == '-') || (*value == '_')) { i = DashConvert((char *) NULL, value, -1, 0.0); - if (i>0) { - i = strlen(value); - } else { + if (i<0) { goto badDashList; } if (i > (int) sizeof(char *)) { @@ -812,7 +810,8 @@ dash->number = -i; return TCL_OK; } - if (Tcl_ListObjGetElements(interp, ovalue, &argc, &objv) != TCL_OK) { + if (Tcl_ListObjGetElements(interp, ovalue, &argc, &objv) != TCL_OK || + argc <= 1) { Tcl_ResetResult(interp); badDashList: Tcl_AppendResult(interp, "bad dash list \"", value, @@ -841,7 +840,7 @@ i < 1 || i>255) { Tcl_ResetResult(interp); Tcl_AppendResult(interp, "expected integer in the range 1..255 but got \"", - *largv, "\"", (char *) NULL); + Tcl_GetString(*largv), "\"", (char *) NULL); goto syntaxError; } *pt++ = i; @@ -1054,8 +1053,6 @@ gcValues->dash_offset = outline->offset; if (dash->number >= 2) { gcValues->dashes = 4; - } else if (dash->number > 0) { - gcValues->dashes = dash->pattern.array[0]; } else { gcValues->dashes = (char) (4 * width); } @@ -1141,7 +1138,7 @@ return 0; } - if ((dash->number<-1) || ((dash->number == -1) && (dash->pattern.array[1]!=','))) { + if (dash->number<=-2) { char *q; int i = -dash->number; @@ -1151,8 +1148,7 @@ XSetDashes(((TkCanvas *)canvas)->display, outline->gc, outline->offset, q, i); values.line_style = LineOnOffDash; ckfree(q); - } else if ( dash->number>2 || (dash->number==2 && - (dash->pattern.array[0]!=dash->pattern.array[1]))) { + } else if ( dash->number>=2 ) { p = (char *) (dash->number > (int) sizeof(char *)) ? dash->pattern.pt : dash->pattern.array; XSetDashes(((TkCanvas *)canvas)->display, outline->gc, outline->offset, p, dash->number); values.line_style = LineOnOffDash; @@ -1262,13 +1258,9 @@ return 0; } - if ((dash->number > 2) || (dash->number < -1) || (dash->number==2 && - (dash->pattern.array[0] != dash->pattern.array[1])) || - ((dash->number == -1) && (dash->pattern.array[1] != ','))) { + if ( (dash->number >= 2) || (dash->number <= -2) ) { if (dash->number < 0) { dashList = (int) (4 * width + 0.5); - } else if (dash->number<3) { - dashList = dash->pattern.array[0]; } else { dashList = 4; } @@ -1463,7 +1455,7 @@ case ' ': if (result) { if (l) { - l[-1] += intWidth + 1; + l[-1] += intWidth; } continue; } else { @@ -1471,23 +1463,23 @@ } break; case '_': - size = 8; + size = 4; break; case '-': - size = 6; + size = 3; break; case ',': - size = 4; + size = 2; break; case '.': - size = 2; + size = 1; break; default: return -1; } if (l) { *l++ = size * intWidth; - *l++ = 4 * intWidth; + *l++ = 2 * intWidth; } result += 2; } --- pTk/mTk/generic/tkRectOval.c.old 2007-02-10 12:29:06.000000000 +0100 +++ pTk/mTk/generic/tkRectOval.c 2007-11-07 10:11:20.000000000 +0100 @@ -476,8 +476,6 @@ if (mask && \ rectOvalPtr->outline.width != 0 && \ rectOvalPtr->outline.color != NULL) { - gcValues.cap_style = CapProjecting; - mask |= GCCapStyle; newGC = Tk_GetGC(tkwin, mask, &gcValues); } else { newGC = None; --- pTk/mTk/generic/tkCanvBmap.c.old 2007-02-10 12:29:06.000000000 +0100 +++ pTk/mTk/generic/tkCanvBmap.c 2007-11-07 12:12:47.000000000 +0100 @@ -331,6 +331,8 @@ XColor *bgColor; Pixmap bitmap; Tk_State state; + int width, height; + int width1, height1; tkwin = Tk_CanvasTkwin(canvas); if (TCL_OK != Tk_ConfigureWidget(interp, tkwin, configSpecs, objc, @@ -353,6 +355,31 @@ itemPtr->redraw_flags &= ~TK_ITEM_STATE_DEPENDANT; } + /* Check that bitmaps have same width and height. This avoids problems + due to wrong position relative to the anchor point, displaying only + part of one of the bitmaps, etc. + */ + Tk_SizeOfBitmap(Tk_Display(Tk_CanvasTkwin(canvas)), bmapPtr->bitmap, + &width, &height); + if (bmapPtr->activeBitmap!=None) { + Tk_SizeOfBitmap(Tk_Display(Tk_CanvasTkwin(canvas)), + bmapPtr->activeBitmap, + &width1, &height1); + if (width != width1 || height != height1) { + Tcl_SetResult(interp, "active bitmap dimensions differ", TCL_STATIC); + return TCL_ERROR; + } + } + if (bmapPtr->disabledBitmap!=None) { + Tk_SizeOfBitmap(Tk_Display(Tk_CanvasTkwin(canvas)), + bmapPtr->disabledBitmap, + &width1, &height1); + if (width != width1 || height != height1) { + Tcl_SetResult(interp, "disabled bitmap dimensions differ", TCL_STATIC); + return TCL_ERROR; + } + } + if (state==TK_STATE_HIDDEN) { ComputeBitmapBbox(canvas, bmapPtr); return TCL_OK; @@ -382,7 +409,7 @@ } } - if (state==TK_STATE_DISABLED || bitmap == None) { + if (bitmap == None) { ComputeBitmapBbox(canvas, bmapPtr); return TCL_OK; } --- pod/Canvas.pod.old 2007-02-10 12:28:59.000000000 +0100 +++ pod/Canvas.pod 2007-11-07 12:21:23.000000000 +0100 @@ -346,29 +346,32 @@ The first possible syntax is a list of integers. Each element represents the number of pixels of a line segment. Only the odd segments are drawn using the "outline" color. The other segments -are drawn transparant. +are drawn transparent. The second possible syntax is a character list containing only -5 possible characters B<[.,-_ ]>. The space can be used -to enlarge the space between other line elements, and can not -occur as the first position in the string. Some examples: +5 possible characters B<[.,-_ ]>, with the first 4 characters +producing a segment of length 1 to 4, respectively, followed +by a transparent segment of length 2. The space can be used +repeatedly to enlarge the space between other line elements +by 1, and can not occur as the first position in the string. +The main difference of this syntax with the previous one is +that it it shape-conserving. This means that all values in the dash +list will be multiplied by the line width before display. This +assures that "." will always be displayed as a dot and "-" +always as a dash regardless of the line width. + +Some examples, for a line width of 2: -dash . = -dash [2,4] -dash - = -dash [6,4] -dash -. = -dash [6,4,2,4] -dash -.. = -dash [6,4,2,4,2,4] - -dash '. ' = -dash [2,8] + -dash '. ' = -dash [2,8] -dash ',' = -dash [4,4] -The main difference of this syntax with the previous is that it -it shape-conserving. This means that all values in the dash -list will be multiplied by the line width before display. This -assures that "." will always be displayed as a dot and "-" -always as a dash regardless of the line width. - -On systems where only a limited set of dash patterns, the dash -pattern will be displayed as the most close dash pattern that -is available. For example, on Windows only the first 4 of the +On systems where only a limited set of dash patterns is available, +the dash pattern will be displayed as the closest available dash +pattern. For example, on Windows only the first 4 of the above examples are available. The last 2 examples will be displayed identically as the first one. @@ -1355,14 +1358,14 @@ =item B<-disabledbitmap> =E<gt> I<bitmap> Specifies the bitmaps to display in the item in its normal, active and -disabled states. +disabled states. All bitmaps must have the same width and height. I<Bitmap> may have any of the forms accepted by B<Tk_GetBitmap>. =item B<-foreground> =E<gt> I<color> -=item B<-activeforeground> =E<gt> I<bitmap> +=item B<-activeforeground> =E<gt> I<color> -=item B<-disabledforeground> =E<gt> I<bitmap> +=item B<-disabledforeground> =E<gt> I<color> Specifies the color to use for each of the bitmap's '1' valued pixels in its normal, active and disabled states.
On Wed Nov 07 06:32:51 2007, Wolfgang.Laun@thalesgroup.com wrote: Show quoted text
> (5) was fixed but all the rest is still in Tk-804.027_501. > The patch is against this version; I have retested it on Linux. > Kind regards > Wolfgang >
Thanks. There are still two issues with this patch: - -dash '. ' = -dash [2,8] still does not produce the same output - I was able to get a segfault using -dash => '.,-_.,-_.,-_.,-_' Can you look into these two? Future versions of Tk will have a new Canvas test file t/canvas2.t, see here: http://svn.perl.org/modules/Tk/trunk/t/canvas2.t This file should contain all the error and special cases you mentioned in this bug report. If you want to peek at current Tk development, you can use the SVN repository http://svn.perl.org/modules/Tk/trunk . Your patch will be integrated once the issues are solved. Regards, Slaven
Subject: Re: [rt.cpan.org #11083] Tk::Canvas: -dash, Bitmap
Date: Fri, 09 Nov 2007 14:58:05 +0100
To: bug-Tk [...] rt.cpan.org
From: Wolfgang Laun <Wolfgang.Laun [...] thalesgroup.com>
I'm working on it. The string dash spec handling is somewhat, uh, contorted. Wolfgang Slaven_Rezic via RT wrote Show quoted text
>Thanks. There are still two issues with this patch: >- -dash '. ' = -dash [2,8] still does not produce the same output >- I was able to get a segfault using -dash => '.,-_.,-_.,-_.,-_' > >Can you look into these two? > >Future versions of Tk will have a new Canvas test file t/canvas2.t, see >here: http://svn.perl.org/modules/Tk/trunk/t/canvas2.t >This file should contain all the error and special cases you mentioned >in this bug report. > >If you want to peek at current Tk development, you can use the SVN >repository http://svn.perl.org/modules/Tk/trunk . Your patch will be >integrated once the issues are solved. > >Regards, > Slaven > > >
Subject: Re: [rt.cpan.org #11083] Tk::Canvas: -dash, Bitmap
Date: Wed, 14 Nov 2007 18:58:40 +0100
To: bug-Tk [...] rt.cpan.org
From: "Wolfgang Laun" <wolfgang.laun [...] gmail.com>
I have run the changed code against canvas2.t and it looks good to me. The patch is against the original code. The code is somewhat more lucid now, but it is still tricky especially in combination with the dash definition using .,-_ Kind regards Wolfgang --- pTk/mTk/generic/tkCanvUtil.c.old 2007-02-10 12:29:06.000000000 +0100 +++ pTk/mTk/generic/tkCanvUtil.c 2007-11-10 19:04:26.000000000 +0100 @@ -798,21 +798,16 @@ if ((*value == '.') || (*value == ',') || (*value == '-') || (*value == '_')) { i = DashConvert((char *) NULL, value, -1, 0.0); - if (i>0) { - i = strlen(value); - } else { + if (i<0) { goto badDashList; } - if (i > (int) sizeof(char *)) { - dash->pattern.pt = pt = (char *) ckalloc(strlen(value)); - } else { - pt = dash->pattern.array; - } - memcpy(pt,value, (unsigned int) i); + dash->pattern.pt = pt = (char *) ckalloc(strlen(value)+1); + strcpy( pt, value ); dash->number = -i; return TCL_OK; } - if (Tcl_ListObjGetElements(interp, ovalue, &argc, &objv) != TCL_OK) { + if (Tcl_ListObjGetElements(interp, ovalue, &argc, &objv) != TCL_OK || + argc <= 1) { Tcl_ResetResult(interp); badDashList: Tcl_AppendResult(interp, "bad dash list \"", value, @@ -841,7 +836,7 @@ i < 1 || i>255) { Tcl_ResetResult(interp); Tcl_AppendResult(interp, "expected integer in the range 1..255 but got \"", - *largv, "\"", (char *) NULL); + Tcl_GetString(*largv), "\"", (char *) NULL); goto syntaxError; } *pt++ = i; @@ -1054,8 +1049,6 @@ gcValues->dash_offset = outline->offset; if (dash->number >= 2) { gcValues->dashes = 4; - } else if (dash->number > 0) { - gcValues->dashes = dash->pattern.array[0]; } else { gcValues->dashes = (char) (4 * width); } @@ -1141,18 +1134,17 @@ return 0; } - if ((dash->number<-1) || ((dash->number == -1) && (dash->pattern.array[1]!=','))) { + if (dash->number<=-2) { char *q; int i = -dash->number; - p = (i > (int) sizeof(char *)) ? dash->pattern.pt : dash->pattern.array ; + p = dash->pattern.pt; q = (char *) ckalloc(2*(unsigned int)i); i = DashConvert(q, p, i, width); XSetDashes(((TkCanvas *)canvas)->display, outline->gc, outline->offset, q, i); values.line_style = LineOnOffDash; ckfree(q); - } else if ( dash->number>2 || (dash->number==2 && - (dash->pattern.array[0]!=dash->pattern.array[1]))) { + } else if ( dash->number>=2 ) { p = (char *) (dash->number > (int) sizeof(char *)) ? dash->pattern.pt : dash->pattern.array; XSetDashes(((TkCanvas *)canvas)->display, outline->gc, outline->offset, p, dash->number); values.line_style = LineOnOffDash; @@ -1262,13 +1254,9 @@ return 0; } - if ((dash->number > 2) || (dash->number < -1) || (dash->number==2 && - (dash->pattern.array[0] != dash->pattern.array[1])) || - ((dash->number == -1) && (dash->pattern.array[1] != ','))) { + if ( (dash->number >= 2) || (dash->number <= -2) ) { if (dash->number < 0) { dashList = (int) (4 * width + 0.5); - } else if (dash->number<3) { - dashList = dash->pattern.array[0]; } else { dashList = 4; } @@ -1365,8 +1353,8 @@ str = (char *)ckalloc((unsigned int) (1 - 8*dash->number)); lptr = (char *)ckalloc((unsigned int) (1 - 2*dash->number)); } - ptr = (char *) ((ABS(dash->number) > sizeof(char *)) ) ? - dash->pattern.pt : dash->pattern.array; + ptr = (char *) ( dash->number > sizeof(char *)) ? dash->pattern.pt : + ( dash->number < 0 ) ? dash->pattern.pt : dash-> pattern.array; if (dash->number > 0) { char *ptr0 = ptr; sprintf(str, "[%d", *ptr++ & 0xff); @@ -1427,7 +1415,7 @@ * * Converts a character-like dash-list (e.g. "-..") * into an X11-style. l must point to a string that - * holds room to at least 2*n characters. if + * holds room to at least 2*n characters. If * l == NULL, this function can be used for * syntax checking only. * @@ -1463,7 +1451,7 @@ case ' ': if (result) { if (l) { - l[-1] += intWidth + 1; + l[-1] += 2 * intWidth; } continue; } else { @@ -1471,23 +1459,23 @@ } break; case '_': - size = 8; + size = 4; break; case '-': - size = 6; + size = 3; break; case ',': - size = 4; + size = 2; break; case '.': - size = 2; + size = 1; break; default: return -1; } if (l) { *l++ = size * intWidth; - *l++ = 4 * intWidth; + *l++ = 2 * intWidth; } result += 2; } --- pTk/mTk/generic/tkRectOval.c.old 2007-02-10 12:29:06.000000000 +0100 +++ pTk/mTk/generic/tkRectOval.c 2007-11-07 10:11:20.000000000 +0100 @@ -476,8 +476,6 @@ if (mask && \ rectOvalPtr->outline.width != 0 && \ rectOvalPtr->outline.color != NULL) { - gcValues.cap_style = CapProjecting; - mask |= GCCapStyle; newGC = Tk_GetGC(tkwin, mask, &gcValues); } else { newGC = None; --- pTk/mTk/generic/tkCanvBmap.c.old 2007-02-10 12:29:06.000000000 +0100 +++ pTk/mTk/generic/tkCanvBmap.c 2007-11-07 12:12:47.000000000 +0100 @@ -331,6 +331,8 @@ XColor *bgColor; Pixmap bitmap; Tk_State state; + int width, height; + int width1, height1; tkwin = Tk_CanvasTkwin(canvas); if (TCL_OK != Tk_ConfigureWidget(interp, tkwin, configSpecs, objc, @@ -353,6 +355,31 @@ itemPtr->redraw_flags &= ~TK_ITEM_STATE_DEPENDANT; } + /* Check that bitmaps have same width and height. This avoids problems + due to wrong position relative to the anchor point, displaying only + part of one of the bitmaps, etc. + */ + Tk_SizeOfBitmap(Tk_Display(Tk_CanvasTkwin(canvas)), bmapPtr->bitmap, + &width, &height); + if (bmapPtr->activeBitmap!=None) { + Tk_SizeOfBitmap(Tk_Display(Tk_CanvasTkwin(canvas)), + bmapPtr->activeBitmap, + &width1, &height1); + if (width != width1 || height != height1) { + Tcl_SetResult(interp, "active bitmap dimensions differ", TCL_STATIC); + return TCL_ERROR; + } + } + if (bmapPtr->disabledBitmap!=None) { + Tk_SizeOfBitmap(Tk_Display(Tk_CanvasTkwin(canvas)), + bmapPtr->disabledBitmap, + &width1, &height1); + if (width != width1 || height != height1) { + Tcl_SetResult(interp, "disabled bitmap dimensions differ", TCL_STATIC); + return TCL_ERROR; + } + } + if (state==TK_STATE_HIDDEN) { ComputeBitmapBbox(canvas, bmapPtr); return TCL_OK; @@ -382,7 +409,7 @@ } } - if (state==TK_STATE_DISABLED || bitmap == None) { + if (bitmap == None) { ComputeBitmapBbox(canvas, bmapPtr); return TCL_OK; } --- pod/Canvas.pod.old 2007-02-10 12:28:59.000000000 +0100 +++ pod/Canvas.pod 2007-11-09 09:16:32.000000000 +0100 @@ -346,29 +346,32 @@ The first possible syntax is a list of integers. Each element represents the number of pixels of a line segment. Only the odd segments are drawn using the "outline" color. The other segments -are drawn transparant. +are drawn transparent. The second possible syntax is a character list containing only -5 possible characters B<[.,-_ ]>. The space can be used -to enlarge the space between other line elements, and can not -occur as the first position in the string. Some examples: +5 possible characters B<[.,-_ ]>, with the first 4 characters +producing a segment of length 1 to 4, respectively, followed +by a transparent segment of length 2. The space can be used +repeatedly to enlarge the space between other line elements +by 1, and can not occur as the first position in the string. +The main difference of this syntax with the previous one is +that it it shape-conserving. This means that all values in the dash +list will be multiplied by the line width before display. This +assures that "." will always be displayed as a dot and "-" +always as a dash regardless of the line width. + +Some examples, for a line width of 2: -dash . = -dash [2,4] -dash - = -dash [6,4] -dash -. = -dash [6,4,2,4] -dash -.. = -dash [6,4,2,4,2,4] - -dash '. ' = -dash [2,8] + -dash '. ' = -dash [2,8] -dash ',' = -dash [4,4] -The main difference of this syntax with the previous is that it -it shape-conserving. This means that all values in the dash -list will be multiplied by the line width before display. This -assures that "." will always be displayed as a dot and "-" -always as a dash regardless of the line width. - -On systems where only a limited set of dash patterns, the dash -pattern will be displayed as the most close dash pattern that -is available. For example, on Windows only the first 4 of the +On systems where only a limited set of dash patterns is available, +the dash pattern will be displayed as the closest available dash +pattern. For example, on Windows only the first 4 of the above examples are available. The last 2 examples will be displayed identically as the first one. @@ -1355,14 +1358,14 @@ =item B<-disabledbitmap> =E<gt> I<bitmap> Specifies the bitmaps to display in the item in its normal, active and -disabled states. +disabled states. All bitmaps must have the same width and height. I<Bitmap> may have any of the forms accepted by B<Tk_GetBitmap>. =item B<-foreground> =E<gt> I<color> -=item B<-activeforeground> =E<gt> I<bitmap> +=item B<-activeforeground> =E<gt> I<color> -=item B<-disabledforeground> =E<gt> I<bitmap> +=item B<-disabledforeground> =E<gt> I<color> Specifies the color to use for each of the bitmap's '1' valued pixels in its normal, active and disabled states.

Message body is not shown because it is too large.

Subject: Re: [rt.cpan.org #11083] Tk::Canvas: -dash, Bitmap
Date: 15 Nov 2007 22:56:46 +0100
To: bug-Tk [...] rt.cpan.org
From: Slaven Rezic <slaven [...] rezic.de>
"Wolfgang Laun via RT" <bug-Tk@rt.cpan.org> writes: Show quoted text
> Queue: Tk > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=11083 > > > I have run the changed code against canvas2.t and it looks good to me. > The patch is against the original code. The code is somewhat more lucid > now, but it is still tricky especially in combination with the dash > definition using .,-_ >
Can you attach the patch? There seem to be problems with additional line breaks and probably whitespace... Regards, Slaven -- Slaven Rezic - slaven <at> rezic <dot> de BBBike - route planner for cyclists in Berlin WWW version: http://www.bbbike.de Perl/Tk version for Unix and Windows: http://bbbike.sourceforge.net
Thanks, I applied the patch you sent by email to the subversion repository (change 10267). Regards, Slaven