Browse Source
fix(Geometries): Relative line drawing (#14013)
* test: Add invalid draw test
* fix: Geometry parsing
* test: Refactoring the test for address `h` and `v` command
* fix: Parser of `h` command
* fix: parser `v` command
* test: Add case `M50,50z l -5,-5`
* test: Add PathMarkupParserTests
* test: Removed render tests
pull/14243/head
workgroupengineering
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
28 additions and
6 deletions
-
src/Avalonia.Base/Media/PathMarkupParser.cs
-
tests/Avalonia.Base.UnitTests/Media/PathMarkupParserTests.cs
|
|
|
@ -259,7 +259,7 @@ namespace Avalonia.Media |
|
|
|
{ |
|
|
|
ThrowIfDisposed(); |
|
|
|
|
|
|
|
_currentPoint = relative |
|
|
|
var next = relative |
|
|
|
? ReadRelativePoint(ref span, _currentPoint) |
|
|
|
: ReadPoint(ref span); |
|
|
|
|
|
|
|
@ -268,14 +268,15 @@ namespace Avalonia.Media |
|
|
|
CreateFigure(); |
|
|
|
} |
|
|
|
|
|
|
|
_geometryContext.LineTo(_currentPoint); |
|
|
|
_geometryContext.LineTo(next); |
|
|
|
_currentPoint = next; |
|
|
|
} |
|
|
|
|
|
|
|
private void AddHorizontalLine(ref ReadOnlySpan<char> 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 @@ namespace Avalonia.Media |
|
|
|
CreateFigure(); |
|
|
|
} |
|
|
|
|
|
|
|
_geometryContext.LineTo(_currentPoint); |
|
|
|
_geometryContext.LineTo(next); |
|
|
|
_currentPoint = next; |
|
|
|
} |
|
|
|
|
|
|
|
private void AddVerticalLine(ref ReadOnlySpan<char> 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 @@ namespace Avalonia.Media |
|
|
|
CreateFigure(); |
|
|
|
} |
|
|
|
|
|
|
|
_geometryContext.LineTo(_currentPoint); |
|
|
|
_geometryContext.LineTo(next); |
|
|
|
_currentPoint = next; |
|
|
|
} |
|
|
|
|
|
|
|
private void AddCubicBezierCurve(ref ReadOnlySpan<char> span, bool relative) |
|
|
|
|
|
|
|
@ -319,5 +319,24 @@ namespace Avalonia.Base.UnitTests.Media |
|
|
|
Assert.IsType<ArcSegment>(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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|