stroke-dasharray misbehaviour with long strokes

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
mnz2000
Posts: 5
Joined: 2010-09-16T14:17:31-07:00
Authentication code: 8675308

stroke-dasharray misbehaviour with long strokes

Post by mnz2000 »

Hello!

The following command produces an invalid dasharray:

Code: Select all

convert -size 100x100 xc:white -stroke black -fill none +antialias -draw "stroke-dasharray 40,10 path 'M 10,10 30,10 30,70 10,70 10,10'" test.png
Image

The first dash is OK (20 pixels at top and 20 pixels at right), but the second dash is 30+20+30 = 80 pixels long. After that there is a 20-pixel wide empty space.

The empty space becomes really annoying when I use very short spaces:

Code: Select all

convert -size 100x100 xc:white -stroke black -fill none +antialias -draw "stroke-dasharray 40,2 path 'M 10,10 30,10 30,70 10,70 10,10'" test.png
Image

This makes the result look nothing like a rectangle.

I am using ImageMagick 6.7.7-0 2012-05-17 Q16 on Windows.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: stroke-dasharray misbehaviour with long strokes

Post by magick »

We're swamped right now with ImageMagick 7 development. It may be months before we can trace this problem. In the mean-time, ImageMagick is open-source. You are welcome to take a look at the source module @ ImageMagick-7.0.0-0/magick/draw.c and see if you can identify and resolve the bug.
mnz2000
Posts: 5
Joined: 2010-09-16T14:17:31-07:00
Authentication code: 8675308

Re: stroke-dasharray misbehaviour with long strokes

Post by mnz2000 »

I did as suggested and fixed these two problems with the following changes to magick/draw.c:

Code: Select all

1581c1581
<     for (total_length=0.0; (total_length+length) < maximum_length; )
---
>     for (total_length=0.0; (total_length+length) <= maximum_length; )
1620c1620
<   if ((total_length < maximum_length) && ((n & 0x01) == 0) && (j > 1))
---
>   if ((total_length <= maximum_length) && ((n & 0x01) == 0) && (j > 1))
The first change fixes the missing "off" segment when it ends exactly at the end of a vertex. The second change fixes the missing "on" segment at the end of the path. For some reason, there were "null vertices" between every real vertex. This made total_length and maximum_length zeros after the last such "null vertice".

If this isn't the proper place to submit patches, please let me know what is. I'd rather not get commit access to SVN, though, because I don't expect to be making many more patches.

Thank you for the great software!
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: stroke-dasharray misbehaviour with long strokes

Post by magick »

Thanks for the patch. We'll apply it to the ImageMagick Subversion trunk by sometime tomorrow.
Post Reply