diff --git a/Source/Basic Shapes/SvgVisualElement.cs b/Source/Basic Shapes/SvgVisualElement.cs index 4d8c32a29eda56dfea69c9059e2f85c6d8567aa5..54c788453327947b0a3c1b9fdfde1cb71c4966d5 100644 --- a/Source/Basic Shapes/SvgVisualElement.cs +++ b/Source/Basic Shapes/SvgVisualElement.cs @@ -256,10 +256,27 @@ namespace Svg // handle odd dash arrays by repeating them once this.StrokeDashArray.AddRange(this.StrokeDashArray); } + /* divide by stroke width - GDI behaviour that I don't quite understand yet.*/ pen.DashPattern = this.StrokeDashArray.ConvertAll(u => ((u.ToDeviceValue(renderer, UnitRenderingType.Other, this) <= 0) ? 1 : u.ToDeviceValue(renderer, UnitRenderingType.Other, this)) / ((strokeWidth <= 0) ? 1 : strokeWidth)).ToArray(); + if (this.StrokeLineCap == SvgStrokeLineCap.Round) + { + // to handle round caps, we have to adapt the dash pattern + // by increasing the dash length by the stroke width - GDI draws the rounded + // edge inside the dash line, SVG draws it outside the line + var pattern = new float[pen.DashPattern.Length]; + int offset = 1; // the values are already normalized to dash width + for ( int i = 0; i < pen.DashPattern.Length; i++) + { + pattern[i] = pen.DashPattern[i] + offset; + offset *= -1; // increase dash length, decrease spaces + } + pen.DashPattern = pattern; + pen.DashCap = DashCap.Round; + } + if (this.StrokeDashOffset != null && this.StrokeDashOffset.Value != 0) { pen.DashOffset = ((this.StrokeDashOffset.ToDeviceValue(renderer, UnitRenderingType.Other, this) <= 0) ? 1 : this.StrokeDashOffset.ToDeviceValue(renderer, UnitRenderingType.Other, this)) / diff --git a/Tests/Svg.UnitTests/PassingTests.csv b/Tests/Svg.UnitTests/PassingTests.csv index 15ea685f5825eb9e72a9394a7a9905c7e4741a25..7930fff6490fb8c7562b3b1d8db8320a9f7b6fdc 100644 --- a/Tests/Svg.UnitTests/PassingTests.csv +++ b/Tests/Svg.UnitTests/PassingTests.csv @@ -174,6 +174,7 @@ __issue-109-01 __issue-116-01 __issue-123-01 __issue-143-01 +__issue-191-01 __issue-202-01 __issue-214-01 __issue-227-01