public void HorizontalLineFor_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); PDFUnit h = 40; target.HorizontalLineFor(h); pos = new PDFPoint(pos.X + h, pos.Y); Assert.AreEqual(target.Cursor, pos); 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, pos); }
public void LineFor_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.LineFor(pos2); PDFPoint total = new PDFPoint(pos.X + pos2.X, pos.Y + pos2.Y); Assert.AreEqual(target.Cursor, total); 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, total); }
public void SVGParser_Test() { var pathData = @"M-84.1487,-15.8513h168.2974 V10.053 H-2Z"; PDFSVGPathDataParser parser = new PDFSVGPathDataParser(true, null); PDFGraphicsPath path = new PDFGraphicsPath(); parser.ParseSVG(path, pathData); Assert.AreEqual(path.Paths.Count, 1); Assert.AreEqual(path.Paths[0].Operations.Count, 5); //M-84.1487,-15.8513 Assert.IsInstanceOfType(path.Paths[0].Operations[0], typeof(PathMoveData)); PathMoveData move = (PathMoveData)path.Paths[0].Operations[0]; Assert.AreEqual(move.MoveTo.X.PointsValue, -84.1487); Assert.AreEqual(move.MoveTo.Y.PointsValue, -15.8513); //h168.2974 Assert.IsInstanceOfType(path.Paths[0].Operations[1], typeof(PathLineData)); PathLineData line = (PathLineData)path.Paths[0].Operations[1]; Assert.AreEqual(line.LineTo.X.PointsValue, -84.1487 + 168.2974); Assert.AreEqual(line.LineTo.Y.PointsValue, -15.8513); //V10.053 Assert.IsInstanceOfType(path.Paths[0].Operations[2], typeof(PathLineData)); line = (PathLineData)path.Paths[0].Operations[2]; Assert.AreEqual(line.LineTo.X.PointsValue, -84.1487 + 168.2974); Assert.AreEqual(line.LineTo.Y.PointsValue, 10.053); //H-2 Assert.IsInstanceOfType(path.Paths[0].Operations[3], typeof(PathLineData)); line = (PathLineData)path.Paths[0].Operations[3]; Assert.AreEqual(line.LineTo.X.PointsValue, -2.0); Assert.AreEqual(line.LineTo.Y.PointsValue, 10.053); //Z close Assert.IsInstanceOfType(path.Paths[0].Operations[path.Paths[0].Operations.Count - 1], typeof(PathCloseData)); }
public void SVGParserFull_Test() { var pathData = @"M-84.1487,-15.8513h168.2974 V10.053 H-2a22.4171,22.4171 0 1 0 0,31.7026 h168.2974 A22.4171,22.4171 0 1 0 0,-31.7026 M70.491,50.826c-2.232,1.152-6.913,2.304-12.817,2.304c-13.682,0-23.906-8.641-23.906-24.626 c0-15.266,10.297-25.49,25.346-25.49c5.977,0,9.865,1.296,11.521,2.16L-1.584,5.112C66.747,9.134,63.363,8.27,59.33,8.27 c-11.377,0-18.938,7.272-18.938,20.018c0,11.953,6.841,19.514,18.578,19.514c3.888,0,7.777-0.792,10.297-2.016L70.491,50.826z"; PDFSVGPathDataParser parser = new PDFSVGPathDataParser(true, null); PDFGraphicsPath path = new PDFGraphicsPath(); parser.ParseSVG(path, pathData); Assert.AreEqual(path.Paths.Count, 1); //Check the operation count Assert.AreEqual(path.Paths[0].Operations.Count, 19); //M-84.1487,-15.8513 Assert.IsInstanceOfType(path.Paths[0].Operations[0], typeof(PathMoveData), "Operation 6 Invalid"); PathMoveData move = (PathMoveData)path.Paths[0].Operations[0]; Assert.AreEqual(move.MoveTo.X.PointsValue, -84.1487); Assert.AreEqual(move.MoveTo.Y.PointsValue, -15.8513); //h168.2974 Assert.IsInstanceOfType(path.Paths[0].Operations[1], typeof(PathLineData), "Operation 1 Invalid"); PathLineData line = (PathLineData)path.Paths[0].Operations[1]; Assert.AreEqual(line.LineTo.X.PointsValue, -84.1487 + 168.2974); Assert.AreEqual(line.LineTo.Y.PointsValue, -15.8513); //V10.053 Assert.IsInstanceOfType(path.Paths[0].Operations[2], typeof(PathLineData), "Operation 2 Invalid"); line = (PathLineData)path.Paths[0].Operations[2]; Assert.AreEqual(line.LineTo.X.PointsValue, -84.1487 + 168.2974); Assert.AreEqual(line.LineTo.Y.PointsValue, 10.053); //H-2 Assert.IsInstanceOfType(path.Paths[0].Operations[3], typeof(PathLineData), "Operation 3 Invalid"); line = (PathLineData)path.Paths[0].Operations[3]; Assert.AreEqual(line.LineTo.X.PointsValue, -2.0); Assert.AreEqual(line.LineTo.Y.PointsValue, 10.053); //a22.4171,22.4171 0 1 0 0,31.7026 Assert.IsInstanceOfType(path.Paths[0].Operations[4], typeof(PathArcData), "Operation 4 Invalid"); //h168.2974 Assert.IsInstanceOfType(path.Paths[0].Operations[5], typeof(PathLineData), "Operation 5 Invalid"); //A22.4171,22.4171 0 1 0 0,-31.7026 Assert.IsInstanceOfType(path.Paths[0].Operations[6], typeof(PathArcData), "Operation 6 Invalid"); PathArcData arc = (PathArcData)path.Paths[0].Operations[6]; Assert.AreEqual(22.4171, arc.RadiusX, "Operation 6 Invalid - Radius X"); Assert.AreEqual(22.4171, arc.RadiusY, "Operation 6 Invalid - Radius Y"); Assert.AreEqual(0, arc.XAxisRotation, "Operation 6 Invalid - Rotation"); Assert.AreEqual(1, (int)arc.ArcSize, "Operation 6 Invalid - Large Arc"); Assert.AreEqual(0, (int)arc.ArcSweep, "Operation 6 Invalid - Sweep"); Assert.AreEqual(0.0, arc.EndPoint.X, "Operation 6 Invalid - Endpoint X"); Assert.AreEqual(-31.7026, arc.EndPoint.Y, "Operation 6 Invalid - EndPoint Y"); //M70.491,50.826 Assert.IsInstanceOfType(path.Paths[0].Operations[7], typeof(PathMoveData), "Operation 7 Invalid"); //c-2.232,1.152-6.913,2.304-12.817,2.304 Assert.IsInstanceOfType(path.Paths[0].Operations[8], typeof(PathBezierCurveData), "Operation 8 Invalid"); //c-13.682,0-23.906-8.641-23.906-24.626 Assert.IsInstanceOfType(path.Paths[0].Operations[9], typeof(PathBezierCurveData), "Operation 9 Invalid"); //c0-15.266,10.297-25.49,25.346-25.49 Assert.IsInstanceOfType(path.Paths[0].Operations[10], typeof(PathBezierCurveData), "Operation 10 Invalid"); //c5.977,0,9.865,1.296,11.521,2.16 Assert.IsInstanceOfType(path.Paths[0].Operations[11], typeof(PathBezierCurveData), "Operation 11 Invalid"); //L-1.584,5.112 Assert.IsInstanceOfType(path.Paths[0].Operations[12], typeof(PathLineData), "Operation 12 Invalid"); line = (PathLineData)path.Paths[0].Operations[12]; Assert.AreEqual(-1.584, line.LineTo.X); Assert.AreEqual(5.112, line.LineTo.Y); //C66.747,9.134,63.363,8.27,59.33,8.27 Assert.IsInstanceOfType(path.Paths[0].Operations[13], typeof(PathBezierCurveData), "Operation 13 Invalid"); PathBezierCurveData curve = (PathBezierCurveData)path.Paths[0].Operations[13]; Assert.AreEqual(66.747, curve.StartHandle.X); Assert.AreEqual(9.134, curve.StartHandle.Y); Assert.AreEqual(63.363, curve.EndHandle.X); Assert.AreEqual(8.27, curve.EndHandle.Y); Assert.AreEqual(59.33, curve.EndPoint.X); Assert.AreEqual(8.27, curve.EndPoint.Y); //c-11.377,0-18.938,7.272-18.938,20.018 Assert.IsInstanceOfType(path.Paths[0].Operations[14], typeof(PathBezierCurveData), "Operation 14 Invalid"); //c0,11.953,6.841,19.514,18.578,19.514 Assert.IsInstanceOfType(path.Paths[0].Operations[15], typeof(PathBezierCurveData), "Operation 15 Invalid"); //c3.888,0,7.777-0.792,10.297-2.016 Assert.IsInstanceOfType(path.Paths[0].Operations[16], typeof(PathBezierCurveData), "Operation 16 Invalid"); //L70.491,50.826 Assert.IsInstanceOfType(path.Paths[0].Operations[17], typeof(PathLineData), "Operation 17 Invalid"); //Z close Assert.IsInstanceOfType(path.Paths[0].Operations[18], typeof(PathCloseData), "Operation 18 Invalid"); }