diff --git a/src/Avalonia.Base/Media/PathMarkupParser.cs b/src/Avalonia.Base/Media/PathMarkupParser.cs index 7b9fdf9330d..fa790c17c00 100644 --- a/src/Avalonia.Base/Media/PathMarkupParser.cs +++ b/src/Avalonia.Base/Media/PathMarkupParser.cs @@ -259,7 +259,7 @@ private void AddLine(ref ReadOnlySpan span, bool relative) { ThrowIfDisposed(); - _currentPoint = relative + var next = relative ? ReadRelativePoint(ref span, _currentPoint) : ReadPoint(ref span); @@ -268,14 +268,15 @@ private void AddLine(ref ReadOnlySpan span, bool relative) CreateFigure(); } - _geometryContext.LineTo(_currentPoint); + _geometryContext.LineTo(next); + _currentPoint = next; } private void AddHorizontalLine(ref ReadOnlySpan span, bool relative) { ThrowIfDisposed(); - _currentPoint = relative + var next = relative ? new Point(_currentPoint.X + ReadDouble(ref span), _currentPoint.Y) : _currentPoint.WithX(ReadDouble(ref span)); @@ -284,14 +285,15 @@ private void AddHorizontalLine(ref ReadOnlySpan span, bool relative) CreateFigure(); } - _geometryContext.LineTo(_currentPoint); + _geometryContext.LineTo(next); + _currentPoint = next; } private void AddVerticalLine(ref ReadOnlySpan span, bool relative) { ThrowIfDisposed(); - _currentPoint = relative + var next = relative ? new Point(_currentPoint.X, _currentPoint.Y + ReadDouble(ref span)) : _currentPoint.WithY(ReadDouble(ref span)); @@ -300,7 +302,8 @@ private void AddVerticalLine(ref ReadOnlySpan span, bool relative) CreateFigure(); } - _geometryContext.LineTo(_currentPoint); + _geometryContext.LineTo(next); + _currentPoint = next; } private void AddCubicBezierCurve(ref ReadOnlySpan span, bool relative) diff --git a/tests/Avalonia.Base.UnitTests/Media/PathMarkupParserTests.cs b/tests/Avalonia.Base.UnitTests/Media/PathMarkupParserTests.cs index c829690eb4a..755ab7ff25a 100644 --- a/tests/Avalonia.Base.UnitTests/Media/PathMarkupParserTests.cs +++ b/tests/Avalonia.Base.UnitTests/Media/PathMarkupParserTests.cs @@ -319,5 +319,24 @@ public void Should_Parse_Flags_Without_Separator() Assert.IsType(arcSegment); } } + + [Fact] + public void Should_Handle_StartPoint_After_Empty_Figure() + { + var pathGeometry = new PathGeometry(); + using var context = new PathGeometryContext(pathGeometry); + using var parser = new PathMarkupParser(context); + parser.Parse("M50,50z l -5,-5"); + + Assert.Equal(2, pathGeometry.Figures.Count); + + var firstFigure = pathGeometry.Figures[0]; + + Assert.Equal(new Point(50, 50), firstFigure.StartPoint); + + var secondFigure = pathGeometry.Figures[1]; + + Assert.Equal(new Point(50, 50), secondFigure.StartPoint); + } } }