Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with Round cap and dash-strokearray #508

Closed
MichaelBjerregaard opened this issue Jul 8, 2019 · 5 comments
Closed

Problem with Round cap and dash-strokearray #508

MichaelBjerregaard opened this issue Jul 8, 2019 · 5 comments
Labels

Comments

@MichaelBjerregaard
Copy link

Description

In the attached SVG the dasharray (1.40 , 1.00) first becomes (0.56, 0.40) in SVGVisualElement line 291.
When adjusting for round cap, it becomes (1.56, -0.59) which is invalid.

Changing line 303 to
pattern[i] = Math.Abs(pen.DashPattern[i] + offset);
will avoid the exception, but will probably not paint a correct dash.

Example data

SVG1155.svg.txt

DashArrayTests.cs.txt

Used Versions

master branch

@mrbean-bremen
Copy link
Member

mrbean-bremen commented Jul 8, 2019

Hm, I see the problem - this basically happens if the caps overlap. Using Abs may not be the best solution, as that would widen the gap more with a larger overlap. As GDI is not able to draw an overlapped dashed line (at least not directly), we either have to decompose the dash and draw each part separately (cumbersome and probably not worth it, given that overlapping dashes are not exactly a widely used feature), setting the gap size to a very small value (this would make the gaps wider to not have overlap), or not use a dash at all in this case. Any thoughts?

@MichaelBjerregaard
Copy link
Author

I can see in #191 what you wanted to achieve, and in my opinion there is no need to make a lot of work out of it.
It seems that a large stroke-width combined with relatively small dash/gap values can create the negative values. In my case a stroke-width of 2.5 and a dash/gap of 1.4/1, which will turn into a solid line if properly adjusted for round caps.
I will suggest that if the average width of dash + gap is less than 2 * stroke-width then ignore round caps.

@mrbean-bremen
Copy link
Member

mrbean-bremen commented Jul 9, 2019

Agreed - thanks. I will see if can do this tonight later tomorrow.

mrbean-bremen added a commit to mrbean-bremen/SVG that referenced this issue Jul 10, 2019
- overlapping cups led to a crash - see svg-net#508
- workaround to avoid the crash and not deviate too much from correct drawing
mrbean-bremen added a commit to mrbean-bremen/SVG that referenced this issue Jul 10, 2019
- overlapping cups led to a crash - see svg-net#508
- workaround to avoid the crash and not deviate too much from correct drawing
@mrbean-bremen
Copy link
Member

@MichaelBjerregaard - you can have a look at the PR. I added your test to make sure your example doesn't crash, and a simpler example (shown in the PR) to check the functionality.

@MichaelBjerregaard
Copy link
Author

MichaelBjerregaard commented Jul 11, 2019 via email

mrbean-bremen added a commit to mrbean-bremen/SVG that referenced this issue Jul 11, 2019
- overlapping cups led to a crash - fixes svg-net#508
- workaround to avoid the crash and not deviate too much from correct drawing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants