diff --git a/src/Perspex.Controls/Shapes/Shape.cs b/src/Perspex.Controls/Shapes/Shape.cs index 58dc24a738..6e7934b0e7 100644 --- a/src/Perspex.Controls/Shapes/Shape.cs +++ b/src/Perspex.Controls/Shapes/Shape.cs @@ -90,13 +90,20 @@ namespace Perspex.Controls.Shapes set { SetValue(StrokeThicknessProperty, value); } } + public PenLineCap StrokeDashCap { get; set; } = PenLineCap.Flat; + + public PenLineCap StrokeStartLineCap { get; set; } = PenLineCap.Flat; + + public PenLineCap StrokeEndLineCap { get; set; } = PenLineCap.Flat; + public override void Render(DrawingContext context) { var geometry = RenderedGeometry; if (geometry != null) { - var pen = new Pen(Stroke, StrokeThickness, new DashStyle(StrokeDashArray)); + var pen = new Pen(Stroke, StrokeThickness, new DashStyle(StrokeDashArray), + StrokeDashCap, StrokeStartLineCap, StrokeEndLineCap); context.DrawGeometry(Fill, pen, geometry); } } diff --git a/src/Perspex.SceneGraph/Media/Pen.cs b/src/Perspex.SceneGraph/Media/Pen.cs index cc14ae29d6..489860a87a 100644 --- a/src/Perspex.SceneGraph/Media/Pen.cs +++ b/src/Perspex.SceneGraph/Media/Pen.cs @@ -31,12 +31,12 @@ namespace Perspex.Media { Brush = brush; Thickness = thickness; + DashCap = dashCap; StartLineCap = startLineCap; EndLineCap = endLineCap; LineJoin = lineJoin; MiterLimit = miterLimit; DashStyle = dashStyle; - DashCap = dashCap; } /// diff --git a/src/Windows/Perspex.Direct2D1/PrimitiveExtensions.cs b/src/Windows/Perspex.Direct2D1/PrimitiveExtensions.cs index fac270dd7c..65d3ce2dad 100644 --- a/src/Windows/Perspex.Direct2D1/PrimitiveExtensions.cs +++ b/src/Windows/Perspex.Direct2D1/PrimitiveExtensions.cs @@ -71,26 +71,23 @@ namespace Perspex.Direct2D1 /// The Direct2D brush. public static StrokeStyle ToDirect2DStrokeStyle(this Perspex.Media.Pen pen, SharpDX.Direct2D1.RenderTarget target) { - if (pen.DashStyle != null) + var properties = new StrokeStyleProperties { - if (pen.DashStyle.Dashes != null && pen.DashStyle.Dashes.Count > 0) - { - var properties = new StrokeStyleProperties - { - DashStyle = DashStyle.Custom, - DashOffset = (float)pen.DashStyle.Offset, - MiterLimit = (float)pen.MiterLimit, - LineJoin = pen.LineJoin.ToDirect2D(), - StartCap = pen.StartLineCap.ToDirect2D(), - EndCap = pen.EndLineCap.ToDirect2D(), - DashCap = pen.DashCap.ToDirect2D() - }; - - return new StrokeStyle(target.Factory, properties, pen.DashStyle?.Dashes.Select(x => (float)x).ToArray()); - } + DashStyle = DashStyle.Solid, + MiterLimit = (float)pen.MiterLimit, + LineJoin = pen.LineJoin.ToDirect2D(), + StartCap = pen.StartLineCap.ToDirect2D(), + EndCap = pen.EndLineCap.ToDirect2D(), + DashCap = pen.DashCap.ToDirect2D() + }; + var dashes = new float[0]; + if (pen.DashStyle?.Dashes != null && pen.DashStyle.Dashes.Count > 0) + { + properties.DashStyle = DashStyle.Custom; + properties.DashOffset = (float)pen.DashStyle.Offset; + dashes = pen.DashStyle?.Dashes.Select(x => (float)x).ToArray(); } - - return null; + return new StrokeStyle(target.Factory, properties, dashes); } /// diff --git a/tests/Perspex.RenderTests/Shapes/PathTests.cs b/tests/Perspex.RenderTests/Shapes/PathTests.cs index 54cdf7e1cf..68b5956234 100644 Binary files a/tests/Perspex.RenderTests/Shapes/PathTests.cs and b/tests/Perspex.RenderTests/Shapes/PathTests.cs differ diff --git a/tests/TestFiles/Direct2D1/Shapes/Path/Path_With_PenLineCap.expected.png b/tests/TestFiles/Direct2D1/Shapes/Path/Path_With_PenLineCap.expected.png new file mode 100644 index 0000000000..d33068d62c Binary files /dev/null and b/tests/TestFiles/Direct2D1/Shapes/Path/Path_With_PenLineCap.expected.png differ