Skip to content

Commit

Permalink
Fix intellisense docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBobSquarePants committed Apr 15, 2022
1 parent a31cb87 commit bc53f7d
Showing 1 changed file with 49 additions and 43 deletions.
92 changes: 49 additions & 43 deletions src/ImageSharp.Drawing/Shapes/Path.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,27 @@ SegmentInfo IPathInternals.PointAlongPath(float distance)
IReadOnlyList<InternalPath> IInternalPathOwner.GetRingsAsInternalPath() => new[] { this.InnerPath };

/// <summary>
/// Converts an svg path into a Path
/// Converts an SVG path string into an <see cref="IPath"/>.
/// </summary>
/// <param name="data">data</param>
/// <param name="value">path</param>
/// <returns>true if successful</returns>
public static bool TryParseSvgPath(string data, out IPath value)
=> TryParseSvgPath(data.AsSpan(), out value);
/// <param name="svgPath">The string containing the SVG path data.</param>
/// <param name="value">
/// When this method returns, contains the logic path converted from the given SVG path string; otherwise, <see langword="null"/>.
/// This parameter is passed uninitialized.
/// </param>
/// <returns><see langword="true"/> if the input value can be parsed and converted; otherwise, <see langword="false"/>.</returns>
public static bool TryParseSvgPath(string svgPath, out IPath value)
=> TryParseSvgPath(svgPath.AsSpan(), out value);

/// <summary>
/// Converts an svg path into a Path
/// Converts an SVG path string into an <see cref="IPath"/>.
/// </summary>
/// <param name="data">data</param>
/// <param name="value">path</param>
/// <returns>true if successful</returns>
public static bool TryParseSvgPath(ReadOnlySpan<char> data, out IPath value)
/// <param name="svgPath">The string containing the SVG path data.</param>
/// <param name="value">
/// When this method returns, contains the logic path converted from the given SVG path string; otherwise, <see langword="null"/>.
/// This parameter is passed uninitialized.
/// </param>
/// <returns><see langword="true"/> if the input value can be parsed and converted; otherwise, <see langword="false"/>.</returns>
public static bool TryParseSvgPath(ReadOnlySpan<char> svgPath, out IPath value)
{
value = null;

Expand All @@ -150,24 +156,24 @@ public static bool TryParseSvgPath(ReadOnlySpan<char> data, out IPath value)
bool relative = false;
while (true)
{
data = data.TrimStart();
if (data.Length == 0)
svgPath = svgPath.TrimStart();
if (svgPath.Length == 0)
{
break;
}

char ch = data[0];
char ch = svgPath[0];
if (char.IsDigit(ch) || ch == '-' || ch == '+' || ch == '.')
{
// Are we are the end of the string or we are at the end of the path?
if (data.Length == 0 || op == 'Z')
if (svgPath.Length == 0 || op == 'Z')
{
return false;
}
}
else if (IsSeparator(ch))
{
data = TrimSeparator(data);
svgPath = TrimSeparator(svgPath);
}
else
{
Expand All @@ -179,25 +185,25 @@ public static bool TryParseSvgPath(ReadOnlySpan<char> data, out IPath value)
relative = true;
}

data = TrimSeparator(data.Slice(1));
svgPath = TrimSeparator(svgPath.Slice(1));
}

switch (op)
{
case 'M':
data = FindPoint(data, out point1, relative, c);
svgPath = FindPoint(svgPath, out point1, relative, c);
builder.MoveTo(point1);
previousOp = '\0';
op = 'L';
c = point1;
break;
case 'L':
data = FindPoint(data, out point1, relative, c);
svgPath = FindPoint(svgPath, out point1, relative, c);
builder.LineTo(point1);
c = point1;
break;
case 'H':
data = FindScaler(data, out float x);
svgPath = FindScaler(svgPath, out float x);
if (relative)
{
x += c.X;
Expand All @@ -207,7 +213,7 @@ public static bool TryParseSvgPath(ReadOnlySpan<char> data, out IPath value)
c.X = x;
break;
case 'V':
data = FindScaler(data, out float y);
svgPath = FindScaler(svgPath, out float y);
if (relative)
{
y += c.Y;
Expand All @@ -217,16 +223,16 @@ public static bool TryParseSvgPath(ReadOnlySpan<char> data, out IPath value)
c.Y = y;
break;
case 'C':
data = FindPoint(data, out point1, relative, c);
data = FindPoint(data, out point2, relative, c);
data = FindPoint(data, out point3, relative, c);
svgPath = FindPoint(svgPath, out point1, relative, c);
svgPath = FindPoint(svgPath, out point2, relative, c);
svgPath = FindPoint(svgPath, out point3, relative, c);
builder.CubicBezierTo(point1, point2, point3);
lastc = point2;
c = point3;
break;
case 'S':
data = FindPoint(data, out point2, relative, c);
data = FindPoint(data, out point3, relative, c);
svgPath = FindPoint(svgPath, out point2, relative, c);
svgPath = FindPoint(svgPath, out point3, relative, c);
point1 = c;
if (previousOp is 'C' or 'S')
{
Expand All @@ -239,14 +245,14 @@ public static bool TryParseSvgPath(ReadOnlySpan<char> data, out IPath value)
c = point3;
break;
case 'Q': // Quadratic Bezier Curve
data = FindPoint(data, out point1, relative, c);
data = FindPoint(data, out point2, relative, c);
svgPath = FindPoint(svgPath, out point1, relative, c);
svgPath = FindPoint(svgPath, out point2, relative, c);
builder.QuadraticBezierTo(point1, point2);
lastc = point1;
c = point2;
break;
case 'T':
data = FindPoint(data, out point2, relative, c);
svgPath = FindPoint(svgPath, out point2, relative, c);
point1 = c;
if (previousOp is 'Q' or 'T')
{
Expand All @@ -259,18 +265,18 @@ public static bool TryParseSvgPath(ReadOnlySpan<char> data, out IPath value)
c = point2;
break;
case 'A':
data = FindScaler(data, out float radiiX);
data = TrimSeparator(data);
data = FindScaler(data, out float radiiY);
data = TrimSeparator(data);
data = FindScaler(data, out float angle);
data = TrimSeparator(data);
data = FindScaler(data, out float largeArc);
data = TrimSeparator(data);
data = FindScaler(data, out float sweep);

data = FindPoint(data, out PointF point, relative, c);
if (data.Length > 0)
svgPath = FindScaler(svgPath, out float radiiX);
svgPath = TrimSeparator(svgPath);
svgPath = FindScaler(svgPath, out float radiiY);
svgPath = TrimSeparator(svgPath);
svgPath = FindScaler(svgPath, out float angle);
svgPath = TrimSeparator(svgPath);
svgPath = FindScaler(svgPath, out float largeArc);
svgPath = TrimSeparator(svgPath);
svgPath = FindScaler(svgPath, out float sweep);

svgPath = FindPoint(svgPath, out PointF point, relative, c);
if (svgPath.Length > 0)
{
builder.ArcTo(radiiX, radiiY, angle, largeArc == 1, sweep == 1, point);
c = point;
Expand All @@ -282,8 +288,8 @@ public static bool TryParseSvgPath(ReadOnlySpan<char> data, out IPath value)
c = first;
break;
case '~':
data = FindPoint(data, out point1, relative, c);
data = FindPoint(data, out point2, relative, c);
svgPath = FindPoint(svgPath, out point1, relative, c);
svgPath = FindPoint(svgPath, out point2, relative, c);
builder.MoveTo(point1);
builder.LineTo(point2);
break;
Expand Down

0 comments on commit bc53f7d

Please sign in to comment.