// // helper methods // #region protected virtual void BuildPath(PDFGraphicsPath path, PDFPoint[] points, PDFStyle style, bool end) /// <summary> /// Adds a series of lines to the path based on the points. Moving to the first in the array, adding lines after, and optionally closing and ending the path. /// </summary> /// <param name="path">The path to build the lines in</param> /// <param name="points">The points to add lines between</param> /// <param name="close">Closes the path (adds an extra line back to the starting point</param> /// <param name="end">If true then ends the path so no more points can be added to it</param> protected virtual void BuildPath(PDFGraphicsPath path, PDFPoint[] points, Style style, bool end) { if (path.HasCurrentPath == false) { path.BeginPath(); } for (int i = 0; i < points.Length; i++) { if (i == 0) { path.MoveTo(points[i]); } else { path.LineTo(points[i]); } } bool closed = style.GetValue(StyleKeys.ShapeClosedKey, true); if (closed) { path.ClosePath(end); } else if (end) { path.EndPath(); } }
public void BeginPath_Test() { PDFGraphicsPath target = new PDFGraphicsPath(); Assert.IsTrue(target.Paths.Count == 1); Assert.IsTrue(target.HasCurrentPath); target.BeginPath(); Assert.IsTrue(target.HasCurrentPath); Assert.IsTrue(target.Paths.Count == 2); Assert.AreEqual(target.CurrentPath.Count, 0); }
protected virtual void BuildPolygramPath(PDFGraphicsPath path, PDFPoint[] points, int step, bool closed, bool end) { if (points.Length < 5) { throw new PDFException(Errors.CannotCreatePolygramWithLessThan5Sides, null); } if (step >= points.Length) { throw new PDFException(Errors.StepCountCannotBeGreaterThanVertexCount); } bool[] visited = new bool[points.Length]; int loopcount = 0; int firstFree = 0; //checks the integer array of see if everyone has been covered Func <bool> visitedAll = delegate() { for (int i = 0; i < visited.Length; i++) { if (visited[i] == false) { firstFree = i; return(false); } } return(true); }; while (!visitedAll() && loopcount < 10) { if (path.HasCurrentPath == false) { path.BeginPath(); } int index = firstFree; //firstFree is set from the visitedAll method PDFPoint first = points[index]; PDFPoint current = first; path.MoveTo(current); do { index += step; if (index >= points.Length) { index -= points.Length; } current = points[index]; visited[index] = true; //mark the point as visited. if (current == first) { if (closed) { path.ClosePath(end); } else if (end) { path.EndPath(); } } else { path.LineTo(current); } } while (current != first); path.EndPath(); loopcount++; } }