public void LineTo_Test() { PDFGraphicsPath target = new PDFGraphicsPath(); Assert.IsTrue(target.Paths.Count == 1); Assert.IsTrue(target.HasCurrentPath); Assert.AreEqual(target.Cursor, PDFPoint.Empty); PDFPoint pos = new PDFPoint(10, 10); target.LineTo(pos); Assert.AreEqual(target.Cursor, pos); Assert.AreEqual(target.Paths[0].Operations.Count, 1); Assert.IsInstanceOfType(target.Paths[0].Operations[0], typeof(PathLineData)); PathLineData data = (PathLineData)target.Paths[0].Operations[0]; Assert.AreEqual(data.LineTo, pos); PDFPoint pos2 = new PDFPoint(40, 40); target.LineTo(pos2); Assert.AreEqual(target.Cursor, pos2); Assert.AreEqual(target.Paths[0].Operations.Count, 2); Assert.IsInstanceOfType(target.Paths[0].Operations[1], typeof(PathLineData)); data = (PathLineData)target.Paths[0].Operations[1]; Assert.AreEqual(data.LineTo, pos2); }
private void ParseSVGLineCommand(PDFGraphicsPath path, char cmd, bool absolute, string[] args) { PDFUnit x, y; int index = 0; while (index < args.Length) { //must be at least an x and y, but can optionally be more x and y's if (index == 0 || !string.IsNullOrEmpty(args[index])) { if (!AssertParseUnit(args, ref index, cmd, out x)) { return; } if (!AssertParseUnit(args, ref index, cmd, out y)) { return; } if (absolute) { path.LineTo(new PDFPoint(x, y)); } else { path.LineFor(new PDFPoint(x, y)); } } else if (string.IsNullOrEmpty(args[index])) { index++; } } }
protected override PDFGraphicsPath CreatePath(PDFSize available, Style fullstyle) { var bounds = this.GetBounds(); var xoffset = bounds.X.PointsValue; var yoffset = bounds.Y.PointsValue; PDFGraphicsPath path = new PDFGraphicsPath(); if (null != this.Points) { for (int i = 0; i < this.Points.Count; i++) { var pt = this.Points[i]; pt = pt.Offset(-xoffset, -yoffset); if (i == 0) { path.MoveTo(pt); } else { path.LineTo(pt); } } } return(path); }
// // 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(); } }
protected override PDFGraphicsPath CreatePath(PDFSize available, Style fullstyle) { //We use top left zero based moving and line var bounds = this.GetBounds(); var x1 = this.X1 - bounds.X; var x2 = this.X2 - bounds.X; var y1 = this.Y1 - bounds.Y; var y2 = this.Y2 - bounds.Y; var path = new PDFGraphicsPath(); path.MoveTo(new PDFPoint(x1, y1)); path.LineTo(new PDFPoint(x2, y2)); return(path); }
protected override PDFGraphicsPath CreatePath(PDFSize available, Style fullstyle) { PDFPositionOptions pos = fullstyle.CreatePostionOptions(); PDFPoint start = PDFPoint.Empty; PDFPoint end = new PDFPoint(available.Width, start.Y); if (pos.X.HasValue) { start.X = pos.X.Value; } if (pos.Y.HasValue) { start.Y = pos.Y.Value; end.Y = pos.Y.Value; } if (pos.Width.HasValue) { end.X = pos.Width.Value + start.X; if (pos.Height.HasValue) { end.Y = pos.Height.Value - start.Y; } else // no hight so this is a horizontal line { end.Y = start.Y; } } else if (pos.FillWidth) { end.X = available.Width - start.X; if (pos.Height.HasValue) { end.Y = pos.Height.Value - start.Y; } else // no hight so this is a horizontal line { end.Y = start.Y; } } //no width so if we have a height this is a vertical line else if (pos.Height.HasValue) { end.Y = pos.Height.Value + start.Y; end.X = start.X; } else //default is a horizontal line { end.X = available.Width - start.X; end.Y = start.Y; } PDFGraphicsPath path = new PDFGraphicsPath(); path.MoveTo(start); path.LineTo(end); return(path); }
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++; } }