Skip to content

Commit

Permalink
Added some documentation to implemented methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
allisterb committed Aug 28, 2017
1 parent 8d561a0 commit 0af673a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
3 changes: 2 additions & 1 deletion SvgGdiTest/SvgGdiTestForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions SvgGdiTest/SvgGdiTestForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,29 @@ private void Render(IGraphics ig)
myPath.AddRectangle(myRect);
myPath.SetMarkers();
myPath.AddEllipse(220, 220, 100, 100);
myPath.AddLine(new PointF(40, 20), new PointF(80, 120));
ig.DrawPath(new Pen(Color.Black), myPath);
LinearGradientBrush gbr2 = new LinearGradientBrush(new Point(0, 0), new Point(10, 20), Color.WhiteSmoke, Color.CornflowerBlue);
gbr2.WrapMode = WrapMode.TileFlipXY;
SolidBrush redBrush = new SolidBrush(Color.Red);
ig.FillPath(gbr2, myPath);
}
else if (s == "Path 2 (Slow)")
{
/* The following example GraphicsPath code comes from the MSDN docs on the GraphicsPathIterator class
* https://msdn.microsoft.com/en-us/library/79k451ts.aspx
*
*/
// Create a graphics path.
GraphicsPath myPath = new GraphicsPath();
myPath.AddString("String path", FontFamily.GenericMonospace, (int)FontStyle.Regular, 24,
new PointF(0, 0), StringFormat.GenericTypographic);
ig.DrawPath(new Pen(Color.Green), myPath);
GraphicsPath myPath2 = new GraphicsPath();
myPath2.AddString("String path filled", FontFamily.GenericMonospace, (int)FontStyle.Regular, 24,
new PointF(100, 50), StringFormat.GenericTypographic);
SolidBrush redBrush = new SolidBrush(Color.Red);
ig.DrawPath(new Pen(Color.Black), myPath2);
ig.FillPath(redBrush, myPath2);
}
else
{
throw new NotImplementedException();
Expand Down
29 changes: 20 additions & 9 deletions SvgNet/SVGGraphics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1967,20 +1967,25 @@ public void DrawLines(Pen pen, Point[] points)
}

/// <summary>
/// Implemented.
/// Implemented
/// </summary>
public void DrawPath(Pen pen, GraphicsPath path)
{
//Save the original pen dash style in case we need to change it
DashStyle originalPenDashStyle = pen.DashStyle;

GraphicsPathIterator subpaths = new GraphicsPathIterator(path);
GraphicsPath subpath = new GraphicsPath(path.FillMode);
subpaths.Rewind();

//Iterate through all the subpaths in the path. Each subpath will contain either
//lines or Bezier curves
for (int s = 0; s < subpaths.SubpathCount; s++)
{
bool isClosed;
if (subpaths.NextSubpath(subpath, out isClosed) == 0)
{
continue;
continue; //go to next subpath if this one has zero points.
}
PointF start = new PointF(0, 0);
PointF origin = subpath.PathPoints[0];
Expand All @@ -1989,22 +1994,27 @@ public void DrawPath(Pen pen, GraphicsPath path)
PointF[] bezierCurvePoints = new PointF[4];
for (int i = 0; i < subpath.PathPoints.Length; i++)
{
/* Each subpath point has a corresponding type which can be:
*The point starts the subpath
*The point is a line point
*The point is Bezier curve point
*/
switch ((PathPointType)subpath.PathTypes[i] & PathPointType.PathTypeMask)
{
case PathPointType.Start:
start = subpath.PathPoints[i];
bezierCurvePoints[0] = subpath.PathPoints[i];
bezierCurvePointsIndex = 1;
continue;
case PathPointType.Line:
DrawLine(pen, start, subpath.PathPoints[i]);
start = subpath.PathPoints[i];
bezierCurvePoints[0] = subpath.PathPoints[i];
case PathPointType.Line:
DrawLine(pen, start, subpath.PathPoints[i]); //Draw a line segment ftom start point
start = subpath.PathPoints[i]; //Move start point here
bezierCurvePoints[0] = subpath.PathPoints[i]; //A line point can also be the start of a Bezier curve
bezierCurvePointsIndex = 1;
continue;
case PathPointType.Bezier3:
bezierCurvePoints[bezierCurvePointsIndex++] = subpath.PathPoints[i];
if (bezierCurvePointsIndex == 4)
if (bezierCurvePointsIndex == 4) //If 4 points including start have been found then draw the Bezier curve
{
DrawBezier(pen, bezierCurvePoints[0], bezierCurvePoints[1], bezierCurvePoints[2], bezierCurvePoints[3]);
bezierCurvePoints = new PointF[4];
Expand All @@ -2023,11 +2033,12 @@ public void DrawPath(Pen pen, GraphicsPath path)
}
}
}
if (isClosed)
if (isClosed) //If the subpath is closed and it is a linear figure then draw the last connecting line segment
{
PathPointType originType = (PathPointType)subpath.PathTypes[0];
PathPointType lastType = (PathPointType) subpath.PathTypes[subpath.PathPoints.Length - 1];

if ((lastType & PathPointType.PathTypeMask) == PathPointType.Line)
if (((lastType & PathPointType.PathTypeMask) == PathPointType.Line) && ((originType & PathPointType.PathTypeMask) == PathPointType.Line))
{
DrawLine(pen, last, origin);
}
Expand Down
2 changes: 1 addition & 1 deletion SvgNet/svgnetdoc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0af673a

Please sign in to comment.