Page 1 of 1

stroke-dasharray misbehaviour with long strokes

Posted: 2012-05-25T07:46:03-07:00
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.

Re: stroke-dasharray misbehaviour with long strokes

Posted: 2012-05-25T08:03:12-07:00
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.

Re: stroke-dasharray misbehaviour with long strokes

Posted: 2012-05-27T10:24:13-07:00
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!

Re: stroke-dasharray misbehaviour with long strokes

Posted: 2012-05-27T12:59:08-07:00
by magick
Thanks for the patch. We'll apply it to the ImageMagick Subversion trunk by sometime tomorrow.