Updated 2014-06-07 20:44:00 by dkf

HJG On Linux, it works correctly: the drawings left and right are drawn with dashed lines. On Windows, the dash-pattern is ignored when the width is 2 or more.
#!/bin/bash
# the next line restarts using wish \
   exec /usr/bin/wish "$0" "[email protected]"

#: WinDash.tcl - HaJo Gurt - 2005-07-13
#: Bug-Demo: On Windows, dash-patterns only work with width 1


package require Tk

grid [canvas .c -width 300 -height 325]

# Dash-patterns: {2 4}  {2 8}  {6 4}  {6 4 2 4}  {6 4 2 4 2 4}

.c create oval  25  25  125 125  -width 1 -dash {2 4}  -fill grey60
.c create oval 175  25  275 125  -width 2 -dash .  

.c create line  20 150  130 150  -fill grey30  -width 1  -dash {6 4 2 4 2 4} 
.c create line 170 150  280 150                -width 2  -dash {6 4 2 4} 

for {set y 170} {$y<=180} {incr y} {   # crude workaround for thick dashed line:
    .c create line  20 $y  280 $y  -fill grey30  -width 1  -dash {2 4 6 4}  ;# -dash .-
}

.c create rect  25 200  125 300  -fill grey70  -width 1  -dash {6 4}
.c create rect 175 200  275 300                -width 2  -dash -

The tcl-help text says "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."

But on Windows, it looks like the dash-pattern is ignored when the width is 2 or more.

bch I am running into this same problem. I develop a map application on an X11 system (FreeBSD) and deploy it on Windows. As you say, the dashed lines are drawn as specified on a non-Windows platform, but Windows won't do it "right." Unfortunately, the end-users of my application won't be moving to a non-Windows platform, thus I'm stuck trying to figure out how to get around this problem.

I did some quick perusing of the Tk code, and I will summarize what I found below. (Note that I'm not a Tcl/Tk developer which means I could be missing some nuances and details.)

The Windows dash support can be found in the file tk/win/tkWinDraw.c [1].

The code of interest is in the SetUpGraphicsPort function starting on line 1182. I couldn't see any reason why this function would cause the problems we are seeing.

Then I did some other searching and found this site [2] (MSDN). It has this to say:

"CreatePen returns a pen with the specified width bit with the PS_SOLID style if you specify a width greater than one for the following styles: PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT."

This is corroborated a little more clearly at this site [3] where it says:

"This means that, if you specify the style as PS_DASH, PS_DOT, PS_DASHDOT, or PS_DASHDOTDOT but set a width higher than 1, the line would be drawn as PS_SOLID."

The bottom line appears to be this: This is a Windows-specific problem, and overcoming that using the current methodology is probably not an option. I suppose one could write their own line drawing routines, etc. (ouch)

HE 21.02.2007 All the following dashed items works like expected (8.4.7 and 8.4.14 on w2000):
grid [canvas .c -width 1025 -height 345]
.c create oval  25  25  125 125  -width 1 -dash .  -fill grey60 
.c create oval 150  25  250 125  -width 2 -dash .  -fill grey60
.c create oval 275  25  375 125  -width 1 -dash -  -fill grey60 
.c create oval 400  25  500 125  -width 2 -dash -  -fill grey60
.c create oval 525  25  625 125  -width 1 -dash ,  -fill grey60
.c create oval 650  25  750 125  -width 2 -dash ,  -fill grey60
.c create oval 775  25  875 125  -width 1 -dash _  -fill grey60
.c create oval 900  25 1000 125  -width 2 -dash _  -fill grey60


.c create rect 25  130  125 230  -width 1 -dash .  -fill grey60 
.c create rect 150  130  250 230  -width 2 -dash .  -fill grey60
.c create rect 275  130  375 230  -width 1 -dash -  -fill grey60 
.c create rect 400  130  500 230  -width 2 -dash -  -fill grey60
.c create rect 525 130  625 230  -width 1 -dash ,  -fill grey60
.c create rect 650 130  750 230  -width 2 -dash ,  -fill grey60
.c create rect 775  130  875 230  -width 1 -dash _  -fill grey60
.c create rect 900  130  1000 230  -width 2 -dash _  -fill grey60


.c create rect 25  235  125 335  -width 1 -dash .-  -fill grey60 
.c create rect 150  235  250 335  -width 2 -dash .-  -fill grey60
.c create rect 275  235  375 335  -width 1 -dash -.  -fill grey60 
.c create rect 400  235  500 335  -width 2 -dash -.  -fill grey60

AM I can confirm this under Windows XP, using 8.4.1 even and up to absurd widths like -width 20. I think it was mainly a problem under Windows 95. Still, the dot/dash patterns can not be as general as for Linux/UNIX.

bch Verified on XP for me. I have to admit I hadn't tested it on anything newer than win98 (which is the minimum configuration I support). Thanks to HE and AM for the comments.