public void MoveTo_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.MoveTo(pos); Assert.AreEqual(target.Cursor, pos); Assert.AreEqual(target.Paths[0].Operations.Count, 1); Assert.IsInstanceOfType(target.Paths[0].Operations[0], typeof(PathMoveData)); PathMoveData data = (PathMoveData)target.Paths[0].Operations[0]; Assert.AreEqual(data.MoveTo, pos); pos = new PDFPoint(40, 40); target.MoveTo(pos); Assert.AreEqual(target.Cursor, pos); Assert.AreEqual(target.Paths[0].Operations.Count, 2); Assert.IsInstanceOfType(target.Paths[0].Operations[1], typeof(PathMoveData)); data = (PathMoveData)target.Paths[0].Operations[1]; Assert.AreEqual(data.MoveTo, pos); }
private void ParseSVGMoveCommand(PDFGraphicsPath path, char cmd, bool absolute, string[] args) { int index = 0; PDFUnit x, y; 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) && AssertParseUnit(args, ref index, cmd, out y)) { if (absolute) { path.MoveTo(new PDFPoint(x, y)); } else { path.MoveBy(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); }
public void Bounds_Test() { PDFGraphicsPath target = new PDFGraphicsPath(); Assert.IsTrue(target.Paths.Count == 1); Assert.IsTrue(target.HasCurrentPath); PDFPoint pos = new PDFPoint(10, 10); target.MoveTo(pos); PDFPoint end = new PDFPoint(100, 100); PDFPoint handleStart = new PDFPoint(0, 50); PDFPoint handleEnd = new PDFPoint(50, 100); target.CubicCurveForWithHandleEnd(end, handleEnd); end = end.Offset(pos); handleEnd = handleEnd.Offset(pos); handleStart = handleStart.Offset(pos); PDFRect bounds = target.Bounds; Assert.AreEqual(bounds.X, PDFUnit.Zero); Assert.AreEqual(bounds.Y, PDFUnit.Zero); Assert.AreEqual(bounds.Width, end.X); Assert.AreEqual(bounds.Height, end.Y); }
public void CubicForWithHandleEnd_Test() { PDFGraphicsPath target = new PDFGraphicsPath(); Assert.IsTrue(target.Paths.Count == 1); Assert.IsTrue(target.HasCurrentPath); PDFPoint pos = new PDFPoint(10, 10); target.MoveTo(pos); Assert.AreEqual(target.Cursor, pos); PDFPoint end = new PDFPoint(100, 100); PDFPoint handleStart = new PDFPoint(0, 50); PDFPoint handleEnd = new PDFPoint(50, 100); target.CubicCurveForWithHandleEnd(end, handleEnd); end = end.Offset(pos); handleEnd = handleEnd.Offset(pos); handleStart = handleStart.Offset(pos); Assert.AreEqual(target.Cursor, end); Assert.AreEqual(target.Paths[0].Operations.Count, 2); Assert.IsInstanceOfType(target.Paths[0].Operations[1], typeof(PathBezierCurveData)); PathBezierCurveData data = (PathBezierCurveData)target.Paths[0].Operations[1]; Assert.AreEqual(data.Points.Length, 3); Assert.IsFalse(data.HasStartHandle); Assert.IsTrue(data.HasEndHandle); Assert.AreEqual(data.EndPoint, end); Assert.AreEqual(data.StartHandle, PDFPoint.Empty); Assert.AreEqual(data.EndHandle, handleEnd); }
// // 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); }
public static void BuildElipse(PDFGraphicsPath path, PDFRect rect, bool closed, double angle) { double width = rect.Width.PointsValue; double height = rect.Height.PointsValue; if (width <= 0 || height <= 0) { return; } // build the ellipse around the origin // rotate each by the required amount // then translate into position. double centerX = rect.Width.PointsValue / 2.0; double centerY = rect.Height.PointsValue / 2.0; double radX = width / 2.0; double radY = height / 2.0; double lengthX = (double)((width * CircularityFactor) / 2.0); double lengthY = (double)((height * CircularityFactor) / 2.0); double rotation = angle * InRadians; //start at left, middle PDFPoint start = Rotate(new PDFPoint(-radX, 0), rotation); //4 curve definitions with 3 points each. PDFPoint[,] curves = new PDFPoint[4, 3]; //arc to center, top curves[0, 0] = Rotate(new PDFPoint(0, -radY), rotation); curves[0, 1] = Rotate(new PDFPoint(-radX, -lengthY), rotation); curves[0, 2] = Rotate(new PDFPoint(-lengthX, -radY), rotation); //arc to right, middle curves[1, 0] = Rotate(new PDFPoint(radX, 0), rotation); curves[1, 1] = Rotate(new PDFPoint(lengthX, -radY), rotation); curves[1, 2] = Rotate(new PDFPoint(radX, -lengthY), rotation); //arc to center, bottom curves[2, 0] = Rotate(new PDFPoint(0, radY), rotation); curves[2, 1] = Rotate(new PDFPoint(radX, lengthY), rotation); curves[2, 2] = Rotate(new PDFPoint(lengthX, radY), rotation); //arc to left middle curves[3, 0] = Rotate(new PDFPoint(-radX, 0), rotation); curves[3, 1] = Rotate(new PDFPoint(-lengthX, radY), rotation); curves[3, 2] = Rotate(new PDFPoint(-radX, lengthY), rotation); //get the minimun x and y values PDFUnit minx = start.X; PDFUnit miny = start.Y; for (int i = 0; i < 4; i++) { for (int j = 0; j < 3; j++) { PDFPoint pt = curves[i, j]; minx = PDFUnit.Min(minx, pt.X); miny = PDFUnit.Min(miny, pt.Y); } } PDFUnit offsetx = 0 - minx; PDFUnit offsety = 0 - miny; //translate the point by the minimum values so the topleft is always 0,0 in the boundary rect. start = Translate(start, offsetx, offsety); for (int i = 0; i < 4; i++) { for (int j = 0; j < 3; j++) { PDFPoint pt = curves[i, j]; pt = Translate(pt, offsetx, offsety); curves[i, j] = pt; } } path.MoveTo(start); path.CubicCurveTo(curves[0, 0], curves[0, 1], curves[0, 2]); path.CubicCurveTo(curves[1, 0], curves[1, 1], curves[1, 2]); path.CubicCurveTo(curves[2, 0], curves[2, 1], curves[2, 2]); path.CubicCurveTo(curves[3, 0], curves[3, 1], curves[3, 2]); //close if (closed) { path.ClosePath(true); } else { path.EndPath(); } }
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++; } }