Removed logger from CanvasPathGeometry. Using ICanvasPathReceiver in SampleApp instead.

This commit is contained in:
Ratish Philip 2021-01-21 18:22:27 -08:00
Родитель 693ddf75d1
Коммит 30a5040d6f
25 изменённых файлов: 170 добавлений и 197 удалений

Просмотреть файл

@ -508,6 +508,7 @@
<Compile Include="SamplePages\AutoFocusBehavior\AutoFocusBehaviorPage.xaml.cs">
<DependentUpon>AutoFocusBehaviorPage.xaml</DependentUpon>
</Compile>
<Compile Include="SamplePages\CanvasPathGeometry\GeometryStreamReader.cs" />
<Compile Include="SamplePages\ColorPicker\ColorPickerButtonPage.xaml.cs">
<DependentUpon>ColorPickerButtonPage.xaml</DependentUpon>
</Compile>

Просмотреть файл

@ -83,12 +83,14 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
private bool _isParsing = false;
private CanvasGeometry _errorGeometry;
private GeometryStreamReader _reader;
public string InputText { get; set; }
public CanvasPathGeometryPage()
{
this.InitializeComponent();
_reader = new GeometryStreamReader();
_logger = new StringBuilder();
_colors = new List<Color>()
{
@ -171,7 +173,10 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
_logger?.AppendLine("// The following commands represent the CanvasPathBuilder command(s) needed");
_logger?.AppendLine("// to create the CanvasGeometry from the specified Win2d Path Mini Language.");
var geometry = CanvasPathGeometry.CreateGeometry(sender, _data, _logger);
var geometry = CanvasPathGeometry.CreateGeometry(sender, _data);
_reader.StartLogging();
geometry.SendPathTo(_reader);
_logger?.AppendLine(_reader.EndLogging());
CommandsList.Text = _logger?.ToString() ?? string.Empty;
args.DrawingSession.FillGeometry(geometry, _fillColor);

Просмотреть файл

@ -0,0 +1,127 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Numerics;
using System.Text;
using Microsoft.Graphics.Canvas.Geometry;
namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
/// <summary>
/// Class to read the <see cref="CanvasGeometry"/> path data.
/// </summary>
internal class GeometryStreamReader : ICanvasPathReceiver
{
private readonly StringBuilder _cmdBuilder;
/// <summary>
/// Initializes a new instance of the <see cref="GeometryStreamReader"/> class.
/// </summary>
public GeometryStreamReader()
{
_cmdBuilder = new StringBuilder();
}
/// <summary>
/// Starts logging the data for the sample app
/// </summary>
public void StartLogging()
{
_cmdBuilder.Clear();
_cmdBuilder.AppendLine($"using (var pathBuilder = new CanvasPathBuilder(null))");
_cmdBuilder.AppendLine("{\n");
}
/// <summary>
/// Finishes reading the geometry path data and returns the data as formatted string.
/// </summary>
/// <returns><see cref="CanvasPathBuilder"/> commands to create the CanvasGeometry</returns>
public string EndLogging()
{
_cmdBuilder.AppendLine("}");
return _cmdBuilder.ToString();
}
/// <summary>
/// Starts a new figure at the specified point, with the specified figure fill option.
/// </summary>
/// <param name="point">Start point</param>
/// <param name="fill"><see cref="CanvasFigureFill"/></param>
public void BeginFigure(Vector2 point, CanvasFigureFill fill)
{
_cmdBuilder.AppendLine($"\n pathBuilder.BeginFigure(new Vector2({point.X}, {point.Y}));");
}
/// <summary>
/// Adds a single arc to the path, specified by start and end points through which an ellipse will be fitted.
/// </summary>
/// <param name="point">Start Point</param>
/// <param name="x">radiusX</param>
/// <param name="y">radiusY</param>
/// <param name="z">rotationAngle</param>
/// <param name="sweepDirection"><see cref="CanvasSweepDirection"/></param>
/// <param name="arcSize"><see cref="CanvasArcSize"/></param>
public void AddArc(Vector2 point, float x, float y, float z, CanvasSweepDirection sweepDirection, CanvasArcSize arcSize)
{
_cmdBuilder.AppendLine($" pathBuilder.AddArc(new Vector2({point.X}, {point.Y}), {x}, {y}, {z}, {sweepDirection}, {arcSize});");
}
/// <summary>
/// Adds a cubic bezier to the path. The bezier starts where the path left off, and has the specified control points and end point.
/// </summary>
/// <param name="controlPoint1">First ControlPoint</param>
/// <param name="controlPoint2">Second Control Point</param>
/// <param name="endPoint">EndPoint</param>
public void AddCubicBezier(Vector2 controlPoint1, Vector2 controlPoint2, Vector2 endPoint)
{
_cmdBuilder.AppendLine($" pathBuilder.AddCubicBezier(new Vector2({controlPoint1.X}, {controlPoint1.Y}), new Vector2({controlPoint2.X}, {controlPoint2.Y}), new Vector2({endPoint.X}, {endPoint.Y}));");
}
/// <summary>
/// Adds a line segment to the path, with the specified end point.
/// </summary>
/// <param name="endPoint">EndPoint</param>
public void AddLine(Vector2 endPoint)
{
_cmdBuilder.AppendLine($" pathBuilder.AddLine(new Vector2({endPoint.X}, {endPoint.Y}));");
}
/// <summary>
/// Adds a quadratic bezier to the path. The bezier starts where the path left off, and has the specified control point and end point.
/// </summary>
/// <param name="controlPoint">Control Point</param>
/// <param name="endPoint">EndPoint</param>
public void AddQuadraticBezier(Vector2 controlPoint, Vector2 endPoint)
{
_cmdBuilder.AppendLine($" pathBuilder.AddQuadraticBezier(new Vector2({controlPoint.X}, {controlPoint.Y}), new Vector2({endPoint.X}, {endPoint.Y}));");
}
/// <summary>
/// Specifies the method used to determine which points are inside the geometry described by this path builder, and which points are outside.
/// </summary>
/// <param name="filledRegionDetermination"><see cref="CanvasFilledRegionDetermination"/></param>
public void SetFilledRegionDetermination(CanvasFilledRegionDetermination filledRegionDetermination)
{
_cmdBuilder.AppendLine($" pathBuilder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.{filledRegionDetermination});");
}
/// <summary>
/// Specifies stroke and join options to be applied to new segments added to the path builder.
/// </summary>
/// <param name="figureSegmentOptions"><see cref="CanvasFigureSegmentOptions"/></param>
public void SetSegmentOptions(CanvasFigureSegmentOptions figureSegmentOptions)
{
// Do nothing
}
/// <summary>
/// >Ends the current figure; optionally, closes it.
/// </summary>
/// <param name="figureLoop"><see cref="CanvasFigureLoop"/></param>
public void EndFigure(CanvasFigureLoop figureLoop)
{
_cmdBuilder.AppendLine($" pathBuilder.EndFigure({(figureLoop == CanvasFigureLoop.Closed ? "CanvasFigureLoop.Closed" : "CanvasFigureLoop.Open")});");
}
}
}

Просмотреть файл

@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Brushes;
@ -17,17 +18,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry
/// </summary>
public static class CanvasPathGeometry
{
/// <summary>
/// Parses the Path data string and converts it to CanvasGeometry.
/// </summary>
/// <param name="resourceCreator">ICanvasResourceCreator</param>
/// <param name="pathData">Path data</param>
/// <returns><see cref="CanvasGeometry"/></returns>
public static CanvasGeometry CreateGeometry(ICanvasResourceCreator resourceCreator, string pathData)
{
return CreateGeometry(resourceCreator, pathData, null);
}
/// <summary>
/// Parses the Path data string and converts it to CanvasGeometry.
/// </summary>
@ -35,47 +25,21 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry
/// <returns><see cref="CanvasGeometry"/></returns>
public static CanvasGeometry CreateGeometry(string pathData)
{
return CreateGeometry(null, pathData, null);
return CreateGeometry(null, pathData);
}
/// <summary>
/// Parses the Path data string and converts it to CanvasGeometry.
/// </summary>
/// <param name="resourceCreator"><see cref="ICanvasResourceCreator"/></param>
/// <param name="pathData">Path data</param>
/// <param name="logger">(Optional) For logging purpose. To log the set of
/// CanvasPathBuilder commands, used for creating the CanvasGeometry, in
/// string format.</param>
/// <returns><see cref="CanvasGeometry"/></returns>
public static CanvasGeometry CreateGeometry(string pathData, StringBuilder logger)
{
return CreateGeometry(null, pathData, logger);
}
/// <summary>
/// Parses the Path data string and converts it to CanvasGeometry.
/// </summary>
/// <param name="resourceCreator">ICanvasResourceCreator</param>
/// <param name="pathData">Path data</param>
/// <param name="logger">(Optional) For logging purpose. To log the set of
/// CanvasPathBuilder commands, used for creating the CanvasGeometry, in
/// string format.</param>
/// <returns><see cref="CanvasGeometry"/></returns>
public static CanvasGeometry CreateGeometry(ICanvasResourceCreator resourceCreator, string pathData, StringBuilder logger)
public static CanvasGeometry CreateGeometry(ICanvasResourceCreator resourceCreator, string pathData)
{
using (new CultureShield("en-US"))
{
// Log command
var resourceStr = resourceCreator == null ? "null" : "resourceCreator";
logger?.AppendLine($"using (var pathBuilder = new CanvasPathBuilder({resourceStr}))");
logger?.AppendLine("{");
// Get the CanvasGeometry from the path data
var geometry = CanvasGeometryParser.Parse(resourceCreator, pathData, logger);
// Log command
logger?.AppendLine("}");
return geometry;
return CanvasGeometryParser.Parse(resourceCreator, pathData);
}
}

Просмотреть файл

@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Graphics.Canvas.Geometry;
using Microsoft.Toolkit.Uwp.UI.Media.Geometry.Core;
@ -15,10 +14,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
/// </summary>
internal abstract class AbstractPathElement : ICanvasPathElement
{
#pragma warning disable SA1401 // Fields should be private
protected readonly string Indent = new string(' ', 4);
#pragma warning restore SA1401 // Fields should be private
/// <summary>
/// Gets or sets index of the Path Element in the Path Data
/// </summary>
@ -94,10 +89,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
/// <param name="currentPoint">The last active location in the Path before adding
/// the Path Element</param>
/// <param name="lastElement">The previous PathElement in the Path.</param>
/// <param name="logger">For logging purpose. To log the set of CanvasPathBuilder
/// commands, used for creating the CanvasGeometry, in string format.</param>
/// <returns>The latest location in the Path after adding the Path Element</returns>
public abstract Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement, StringBuilder logger);
public abstract Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement);
/// <summary>
/// Get the Regex for extracting Path Element Attributes

Просмотреть файл

@ -4,7 +4,6 @@
using System;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Graphics.Canvas.Geometry;
using Microsoft.Toolkit.Uwp.UI.Media.Geometry.Core;
@ -43,10 +42,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
/// <param name="currentPoint">The last active location in the Path before adding
/// the Path Element</param>
/// <param name="lastElement">The previous PathElement in the Path.</param>
/// <param name="logger">For logging purpose. To log the set of CanvasPathBuilder
/// commands, used for creating the CanvasGeometry, in string format.</param>
/// <returns>The latest location in the Path after adding the Path Element</returns>
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement, StringBuilder logger)
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement)
{
// Calculate coordinates
var point = new Vector2(_x, _y);
@ -58,10 +55,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
// Execute command
pathBuilder.AddArc(point, _radiusX, _radiusY, _angle, _sweepDirection, _arcSize);
// Log command
logger?.Append($"{Indent}pathBuilder.AddArc(new Vector2({point.X}, {point.Y}), ");
logger?.AppendLine($"{_radiusX}, {_radiusY}, {_angle}, {_sweepDirection}, {_arcSize});");
// Set Last Element
lastElement = this;

Просмотреть файл

@ -4,7 +4,6 @@
using System;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Graphics.Canvas.Geometry;
using Microsoft.Toolkit.Uwp.UI.Media.Geometry.Core;
@ -36,10 +35,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
/// <param name="currentPoint">The last active location in the Path before adding
/// the EllipseFigure</param>
/// <param name="lastElement">The previous PathElement in the Path.</param>
/// <param name="logger">For logging purpose. To log the set of CanvasPathBuilder
/// commands, used for creating the CanvasGeometry, in string format.</param>
/// <returns>The latest location in the Path after adding the EllipseFigure</returns>
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement, StringBuilder logger)
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement)
{
// Calculate coordinates
var center = new Vector2(_x, _y);
@ -51,10 +48,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
// Execute command
pathBuilder.AddEllipseFigure(center.X, center.Y, _radiusX, _radiusY);
// Log command
logger?.AppendLine();
logger?.AppendLine($"{Indent}pathBuilder.AddEllipseFigure({center.X}, {center.Y}, {_radiusX}, {_radiusY});");
// No need to update the lastElement or currentPoint here as we are creating
// a separate closed figure here. So current point will not change.
return currentPoint;

Просмотреть файл

@ -6,7 +6,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Graphics.Canvas.Geometry;
using Microsoft.Toolkit.Uwp.UI.Media.Geometry.Core;
@ -105,17 +104,12 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
/// <param name="currentPoint">The last active location in the Path before adding
/// the Path Element</param>
/// <param name="lastElement">The previous PathElement in the Path.</param>
/// <param name="logger">For logging purpose. To log the set of CanvasPathBuilder
/// commands, used for creating the CanvasGeometry, in string format.</param>
/// <returns>The latest location in the Path after adding the Path Element</returns>
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement, StringBuilder logger)
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement)
{
// Log command
logger?.AppendLine();
foreach (var pathElement in _elements)
{
currentPoint = pathElement.CreatePath(pathBuilder, currentPoint, ref lastElement, logger);
currentPoint = pathElement.CreatePath(pathBuilder, currentPoint, ref lastElement);
}
return currentPoint;

Просмотреть файл

@ -4,7 +4,6 @@
using System;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Graphics.Canvas.Geometry;
using Microsoft.Toolkit.Uwp.UI.Media.Geometry.Core;
@ -34,10 +33,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
/// <param name="currentPoint">The last active location in the Path before adding
/// the PolygonFigure</param>
/// <param name="lastElement">The previous PathElement in the Path.</param>
/// <param name="logger">For logging purpose. To log the set of CanvasPathBuilder
/// commands, used for creating the CanvasGeometry, in string format.</param>
/// <returns>The latest location in the Path after adding the PolygonFigure</returns>
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement, StringBuilder logger)
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement)
{
// Calculate coordinates
var center = new Vector2(_x, _y);
@ -49,10 +46,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
// Execute command
pathBuilder.AddPolygonFigure(_numSides, center.X, center.Y, _radius);
// Log command
logger?.AppendLine();
logger?.AppendLine($"{Indent}pathBuilder.AddPolygonFigure({_numSides}, {center.X}, {center.Y}, {_radius});");
// No need to update the lastElement or currentPoint here as we are creating
// a separate closed figure here. So current point will not change.
return currentPoint;

Просмотреть файл

@ -4,7 +4,6 @@
using System;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Graphics.Canvas.Geometry;
using Microsoft.Toolkit.Uwp.UI.Media.Geometry.Core;
@ -36,10 +35,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
/// <param name="currentPoint">The last active location in the Path before adding
/// the PolygonFigure</param>
/// <param name="lastElement">The previous PathElement in the Path.</param>
/// <param name="logger">For logging purpose. To log the set of CanvasPathBuilder
/// commands, used for creating the CanvasGeometry, in string format.</param>
/// <returns>The latest location in the Path after adding the PolygonFigure</returns>
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement, StringBuilder logger)
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement)
{
// Calculate coordinates
var topLeft = new Vector2(_x, _y);
@ -51,10 +48,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
// Execute command
pathBuilder.AddRectangleFigure(topLeft.X, topLeft.Y, _width, _height);
// Log command
logger?.AppendLine();
logger?.AppendLine($"{Indent}pathBuilder.AddRectangleFigure({topLeft.X}, {topLeft.Y}, {_width}, {_height});");
// No need to update the lastElement or currentPoint here as we are creating
// a separate closed figure here.So current point will not change.
return currentPoint;

Просмотреть файл

@ -4,7 +4,6 @@
using System;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Graphics.Canvas.Geometry;
using Microsoft.Toolkit.Uwp.UI.Media.Geometry.Core;
@ -38,10 +37,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
/// <param name="currentPoint">The last active location in the Path before adding
/// the PolygonFigure</param>
/// <param name="lastElement">The previous PathElement in the Path.</param>
/// <param name="logger">For logging purpose. To log the set of CanvasPathBuilder
/// commands, used for creating the CanvasGeometry, in string format.</param>
/// <returns>The latest location in the Path after adding the PolygonFigure</returns>
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement, StringBuilder logger)
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement)
{
// Calculate coordinates
var topLeft = new Vector2(_x, _y);
@ -53,10 +50,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
// Execute command
pathBuilder.AddRoundedRectangleFigure(topLeft.X, topLeft.Y, _width, _height, _radiusX, _radiusY);
// Log command
logger?.AppendLine();
logger?.AppendLine($"{Indent}pathBuilder.AddRoundedRectangleFigure({topLeft.X}, {topLeft.Y}, {_width}, {_height}, {_radiusX}, {_radiusY});");
// No need to update the lastElement or currentPoint here as we are creating
// a separate closed figure here.So current point will not change.
return currentPoint;

Просмотреть файл

@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Graphics.Canvas.Geometry;
using Microsoft.Toolkit.Uwp.UI.Media.Geometry.Core;
@ -67,18 +66,12 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
/// <param name="currentPoint">The last active location in the Path before adding
/// the Path Element</param>
/// <param name="lastElement">The previous PathElement in the Path.</param>
/// <param name="logger">For logging purpose. To log the set of CanvasPathBuilder
/// commands, used for creating the CanvasGeometry, in string format.</param>
/// <returns>The latest location in the Path after adding the Path Element</returns>
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement, StringBuilder logger)
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement)
{
// Execute command
pathBuilder.EndFigure(_isFigureClosed ? CanvasFigureLoop.Closed : CanvasFigureLoop.Open);
// Log command
var cmd = _isFigureClosed ? "CanvasFigureLoop.Closed" : "CanvasFigureLoop.Open";
logger?.AppendLine($"{Indent}pathBuilder.EndFigure({cmd});");
// Set Last Element
lastElement = this;

Просмотреть файл

@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Graphics.Canvas.Geometry;
using Microsoft.Toolkit.Uwp.UI.Media.Geometry.Core;
@ -42,10 +41,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
/// <param name="currentPoint">The last active location in the Path before adding
/// the Path Element</param>
/// <param name="lastElement">The previous PathElement in the Path.</param>
/// <param name="logger">For logging purpose. To log the set of CanvasPathBuilder
/// commands, used for creating the CanvasGeometry, in string format.</param>
/// <returns>The latest location in the Path after adding the Path Element</returns>
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement, StringBuilder logger)
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement)
{
// Calculate coordinates
var controlPoint1 = new Vector2(_x1, _y1);
@ -66,11 +63,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
// Execute command
pathBuilder.AddCubicBezier(controlPoint1, controlPoint2, point);
// Log command
logger?.Append($"{Indent}pathBuilder.AddCubicBezier(new Vector2({controlPoint1.X}, {controlPoint1.Y})");
logger?.Append($", new Vector2({controlPoint2.X}, {controlPoint2.Y})");
logger?.AppendLine($", new Vector2({point.X}, {point.Y}));");
// Set Last Element
lastElement = this;

Просмотреть файл

@ -4,7 +4,6 @@
using System;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Graphics.Canvas.Geometry;
@ -44,17 +43,12 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
/// <param name="currentPoint">The last active location in the Path before adding
/// the Path Element</param>
/// <param name="lastElement">The previous PathElement in the Path.</param>
/// <param name="logger">For logging purpose. To log the set of CanvasPathBuilder
/// commands, used for creating the CanvasGeometry, in string format.</param>
/// <returns>The latest location in the Path after adding the Path Element</returns>
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement, StringBuilder logger)
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement)
{
// Execute command
pathBuilder.SetFilledRegionDetermination(_fillValue);
// Log command
logger?.AppendLine($"{Indent}pathBuilder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.{_fillValue});");
// Set Last Element
lastElement = this;

Просмотреть файл

@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Graphics.Canvas.Geometry;
using Microsoft.Toolkit.Uwp.UI.Media.Geometry.Core;
@ -32,10 +31,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
/// <param name="currentPoint">The last active location in the Path before adding
/// the Path Element</param>
/// <param name="lastElement">The previous PathElement in the Path.</param>
/// <param name="logger">For logging purpose. To log the set of CanvasPathBuilder
/// commands, used for creating the CanvasGeometry, in string format.</param>
/// <returns>The latest location in the Path after adding the Path Element</returns>
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement, StringBuilder logger)
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement)
{
// Calculate coordinates
var point = IsRelative ?
@ -44,9 +41,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
// Execute command
pathBuilder.AddLine(point);
// Log command
logger?.AppendLine($"{Indent}pathBuilder.AddLine(new Vector2({point.X}, {point.Y}));");
// Set Last Element
lastElement = this;

Просмотреть файл

@ -59,9 +59,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
/// <param name="pathBuilder">CanvasPathBuilder object</param>
/// <param name="currentPoint">The current point on the path before the path element is added</param>
/// <param name="lastElement">The previous PathElement in the Path.</param>
/// <param name="logger">For logging purpose. To log the set of CanvasPathBuilder
/// commands, used for creating the CanvasGeometry, in string format.</param>
/// <returns>The current point on the path after the path element is added</returns>
Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement, StringBuilder logger);
Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement);
}
}

Просмотреть файл

@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Graphics.Canvas.Geometry;
using Microsoft.Toolkit.Uwp.UI.Media.Geometry.Core;
@ -33,10 +32,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
/// <param name="currentPoint">The last active location in the Path before adding
/// the Path Element</param>
/// <param name="lastElement">The previous PathElement in the Path.</param>
/// <param name="logger">For logging purpose. To log the set of CanvasPathBuilder
/// commands, used for creating the CanvasGeometry, in string format.</param>
/// <returns>The latest location in the Path after adding the Path Element</returns>
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement, StringBuilder logger)
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement)
{
// Calculate coordinates
var point = new Vector2(_x, _y);
@ -48,9 +45,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
// Execute command
pathBuilder.AddLine(point);
// Log command
logger?.AppendLine($"{Indent}pathBuilder.AddLine(new Vector2({point.X}, {point.Y}));");
// Set Last Element
lastElement = this;

Просмотреть файл

@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Graphics.Canvas.Geometry;
using Microsoft.Toolkit.Uwp.UI.Media.Geometry.Core;
@ -46,10 +45,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
/// <param name="currentPoint">The last active location in the Path before adding
/// the Path Element</param>
/// <param name="lastElement">The previous PathElement in the Path.</param>
/// <param name="logger">For logging purpose. To log the set of CanvasPathBuilder
/// commands, used for creating the CanvasGeometry, in string format.</param>
/// <returns>The latest location in the Path after adding the Path Element</returns>
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement, StringBuilder logger)
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement)
{
// Calculate coordinates
var point = new Vector2(_x, _y);
@ -61,9 +58,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
// Execute command
pathBuilder.BeginFigure(point);
// Log command
logger?.AppendLine($"{Indent}pathBuilder.BeginFigure(new Vector2({point.X}, {point.Y}));");
// Set Last Element
lastElement = this;

Просмотреть файл

@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Graphics.Canvas.Geometry;
using Microsoft.Toolkit.Uwp.UI.Media.Geometry.Core;
@ -38,10 +37,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
/// <param name="currentPoint">The last active location in the Path before adding
/// the Path Element</param>
/// <param name="lastElement">The previous PathElement in the Path.</param>
/// <param name="logger">For logging purpose. To log the set of CanvasPathBuilder
/// commands, used for creating the CanvasGeometry, in string format.</param>
/// <returns>The latest location in the Path after adding the Path Element</returns>
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement, StringBuilder logger)
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement)
{
// Calculate coordinates
var controlPoint = new Vector2(_x1, _y1);
@ -60,10 +57,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
// Execute command
pathBuilder.AddQuadraticBezier(controlPoint, point);
// Log command
logger?.Append($"{Indent}pathBuilder.AddQuadraticBezier(new Vector2({controlPoint.X}, {controlPoint.Y})");
logger?.AppendLine($", new Vector2({point.X}, {point.Y}));");
// Set Last Element
lastElement = this;

Просмотреть файл

@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Graphics.Canvas.Geometry;
using Microsoft.Toolkit.Uwp.UI.Media.Geometry.Core;
@ -37,10 +36,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
/// <param name="currentPoint">The last active location in the Path before adding
/// the Path Element</param>
/// <param name="lastElement">The previous PathElement in the Path.</param>
/// <param name="logger">For logging purpose. To log the set of CanvasPathBuilder
/// commands, used for creating the CanvasGeometry, in string format.</param>
/// <returns>The latest location in the Path after adding the Path Element</returns>
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement, StringBuilder logger)
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement)
{
// Calculate coordinates
// Check if the last element was a Cubic Bezier
@ -80,11 +77,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
// Execute command
pathBuilder.AddCubicBezier(controlPoint1, controlPoint2, point);
// Log command
logger?.Append($"{Indent}pathBuilder.AddCubicBezier(new Vector2({controlPoint1.X}, {controlPoint1.Y})");
logger?.Append($", new Vector2({controlPoint2.X}, {controlPoint2.Y})");
logger?.AppendLine($", new Vector2({point.X}, {point.Y}));");
// Set Last Element
lastElement = this;

Просмотреть файл

@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Graphics.Canvas.Geometry;
using Microsoft.Toolkit.Uwp.UI.Media.Geometry.Core;
@ -35,10 +34,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
/// <param name="currentPoint">The last active location in the Path before adding
/// the Path Element</param>
/// <param name="lastElement">The previous PathElement in the Path.</param>
/// <param name="logger">For logging purpose. To log the set of CanvasPathBuilder
/// commands, used for creating the CanvasGeometry, in string format.</param>
/// <returns>The latest location in the Path after adding the Path Element</returns>
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement, StringBuilder logger)
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement)
{
// Calculate coordinates
// Check if the last element was a Quadratic Bezier
@ -71,10 +68,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
// Execute command
pathBuilder.AddQuadraticBezier(_absoluteControlPoint, point);
// Log command
logger?.Append($"{Indent}pathBuilder.AddQuadraticBezier(new Vector2({_absoluteControlPoint.X},");
logger?.AppendLine($" {_absoluteControlPoint.Y}), new Vector2({point.X}, {point.Y}));");
// Set Last Element
lastElement = this;

Просмотреть файл

@ -2,9 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Graphics.Canvas.Geometry;
using Microsoft.Toolkit.Uwp.UI.Media.Geometry.Core;
@ -33,10 +31,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
/// <param name="currentPoint">The last active location in the Path before adding
/// the Path Element</param>
/// <param name="lastElement">The previous PathElement in the Path.</param>
/// <param name="logger">For logging purpose. To log the set of CanvasPathBuilder
/// commands, used for creating the CanvasGeometry, in string format.</param>
/// <returns>The latest location in the Path after adding the Path Element</returns>
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement, StringBuilder logger)
public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement)
{
// Calculate coordinates
var point = IsRelative ?
@ -45,9 +41,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Elements.Path
// Execute command
pathBuilder.AddLine(point);
// Log command
logger?.AppendLine($"{Indent}pathBuilder.AddLine(new Vector2({point.X}, {point.Y}));");
// Set Last Element
lastElement = this;

Просмотреть файл

@ -6,7 +6,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Geometry;
@ -22,15 +21,12 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Parsers
internal static class CanvasGeometryParser
{
/// <summary>
/// Parses the Path data in string format and converts it to CanvasGeometry.
/// Parses the Path data in string format and converts it to <see cref="CanvasGeometry"/>.
/// </summary>
/// <param name="resourceCreator">ICanvasResourceCreator</param>
/// <param name="pathData">Path data</param>
/// <param name="logger">(Optional) For logging purpose. To log the set of
/// CanvasPathBuilder commands, used for creating the CanvasGeometry, in
/// string format.</param>
/// <returns>CanvasGeometry</returns>
public static CanvasGeometry Parse(ICanvasResourceCreator resourceCreator, string pathData, StringBuilder logger = null)
/// <returns><see cref="CanvasGeometry"/></returns>
internal static CanvasGeometry Parse(ICanvasResourceCreator resourceCreator, string pathData)
{
var pathFigures = new List<ICanvasPathElement>();
@ -41,10 +37,10 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Parsers
// If the match contains more than one captures, it means that there are multiple FillRuleElements present in the path data. There can be only one FillRuleElement in the path data (at the beginning).
Guard.IsFalse(matches.Count > 1, "(pathData matches.Count > 1)", "Multiple FillRule elements present in Path Data! " +
"There should be only one FillRule within the Path Data. " +
"You can either remove additional FillRule elements or split the Path Data " +
"into multiple Path Data and call the CanvasPathGeometry.CreateGeometry() method on each of them." +
$"\nPath Data: {pathData}");
"There should be only one FillRule within the Path Data. " +
"You can either remove additional FillRule elements or split the Path Data " +
"into multiple Path Data and call the CanvasPathGeometry.CreateGeometry() method on each of them." +
$"\nPath Data: {pathData}");
var figures = new List<ICanvasPathElement>();
@ -67,7 +63,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Parsers
// Process the 'Additional' Group which contains just the attributes
figures.AddRange(from Capture capture in figureMatch.Groups["Additional"].Captures
select PathElementFactory.CreateAdditionalPathFigure(type, capture, figureRootIndex + capture.Index, figure.IsRelative));
select PathElementFactory.CreateAdditionalPathFigure(type, capture, figureRootIndex + capture.Index, figure.IsRelative));
}
}
@ -102,7 +98,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Geometry.Parsers
using var pathBuilder = new CanvasPathBuilder(resourceCreator);
foreach (var pathFigure in pathFigures)
{
currentPoint = pathFigure.CreatePath(pathBuilder, currentPoint, ref lastElement, logger);
currentPoint = pathFigure.CreatePath(pathBuilder, currentPoint, ref lastElement);
}
return CanvasGeometry.CreatePath(pathBuilder);

Просмотреть файл

@ -35,6 +35,9 @@
- SurfaceLoader: A class that can load and draw images and other objects to Win2D surfaces and brushes.
PipelineBuilder: A class that allows to build custom effects pipelines and create CompositionBrush instances from them.
Geometry:
- CanvasPathGeometry: A class that parses Win2d Path Mini Language and converts it to CanvasGeometry, CanvasBrush, CanvasStroke, CanvasStrokeStyle or Color.
</Description>
<PackageTags>UWP Toolkit Windows UI XAML brushes blur</PackageTags>
</PropertyGroup>

Просмотреть файл

@ -4,7 +4,6 @@
using System;
using System.Numerics;
using System.Text;
using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Geometry;
using Microsoft.Toolkit.Uwp.UI.Media.Geometry;
@ -332,10 +331,6 @@ namespace UnitTests.UWP.Geometry
geometry = CanvasPathGeometry.CreateGeometry(sample);
Assert.IsNotNull(geometry, "Unable to create CanvasGeometry!");
var logger = new StringBuilder();
geometry = CanvasPathGeometry.CreateGeometry(sample, logger);
Assert.IsNotNull(geometry, "Unable to create CanvasGeometry!");
}
[TestCategory("CanvasPathGeometry - CanvasGeometry")]