public void CubicTo_Test() { PDFGraphicsPath target = new PDFGraphicsPath(); Assert.IsTrue(target.Paths.Count == 1); Assert.IsTrue(target.HasCurrentPath); Assert.AreEqual(target.Cursor, PDFPoint.Empty); PDFPoint end = new PDFPoint(100, 100); PDFPoint handleStart = new PDFPoint(0, 50); PDFPoint handleEnd = new PDFPoint(50, 100); target.CubicCurveTo(end, handleStart, handleEnd); Assert.AreEqual(target.Cursor, end); Assert.AreEqual(target.Paths[0].Operations.Count, 1); Assert.IsInstanceOfType(target.Paths[0].Operations[0], typeof(PathBezierCurveData)); PathBezierCurveData data = (PathBezierCurveData)target.Paths[0].Operations[0]; Assert.AreEqual(data.Points.Length, 3); Assert.IsTrue(data.HasStartHandle); Assert.IsTrue(data.HasEndHandle); Assert.AreEqual(data.EndPoint, end); Assert.AreEqual(data.StartHandle, handleStart); Assert.AreEqual(data.EndHandle, handleEnd); }
private void ParseSVGCubicCommand(PDFGraphicsPath path, char cmd, bool absolute, string[] args) { PDFUnit startHandleX, startHandleY, endHandleX, endHandleY, endPtX, endPtY; int index = 0; while (index < args.Length) { if (index == 0 || !string.IsNullOrEmpty(args[index])) { if (!AssertParseUnit(args, ref index, cmd, out startHandleX)) { return; } if (!AssertParseUnit(args, ref index, cmd, out startHandleY)) { return; } if (!AssertParseUnit(args, ref index, cmd, out endHandleX)) { return; } if (!AssertParseUnit(args, ref index, cmd, out endHandleY)) { return; } if (!AssertParseUnit(args, ref index, cmd, out endPtX)) { return; } if (!AssertParseUnit(args, ref index, cmd, out endPtY)) { return; } if (absolute) { path.CubicCurveTo(new PDFPoint(endPtX, endPtY), new PDFPoint(startHandleX, startHandleY), new PDFPoint(endHandleX, endHandleY)); } else { path.CubicCurveFor(new PDFPoint(endPtX, endPtY), new PDFPoint(startHandleX, startHandleY), new PDFPoint(endHandleX, endHandleY)); } } else if (string.IsNullOrEmpty(args[index])) { index++; } } }
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(); } }