internal StandardLine(Point p1, Point p2) { // Constants from the standard line representation: Ax+By+C A = (float)(p2.GetY() - p1.GetY()); B = (float)(p1.GetX() - p2.GetX()); C = (float)(p1.GetY() * (-B) - p1.GetX() * A); }
private static Point[] GetRotatedSquareVertices(Point[] orthogonalSquareVertices, double angle, Point squareCenter ) { Point[] rotatedSquareVertices = new Point[orthogonalSquareVertices.Length]; AffineTransform.GetRotateInstance((float)angle).Transform(orthogonalSquareVertices, 0, rotatedSquareVertices , 0, rotatedSquareVertices.Length); AffineTransform.GetTranslateInstance((float)squareCenter.GetX(), (float)squareCenter.GetY()).Transform(rotatedSquareVertices , 0, rotatedSquareVertices, 0, orthogonalSquareVertices.Length); return(rotatedSquareVertices); }
protected ShapePoint ConvertPoint(Point p, Matrix ctm) { Vector vector = new Vector((float)p.x, (float)p.y, 1); vector = vector.Cross(ctm); return(new ShapePoint { X = vector.Get(Vector.I1), Y = pageContext.PageHeight - vector.Get(Vector.I2) }); }
/// <summary>Convert 4 Point objects into a Rectangle</summary> /// <param name="p1">first Point</param> /// <param name="p2">second Point</param> /// <param name="p3">third Point</param> /// <param name="p4">fourth Point</param> private Rectangle GetAsRectangle(Point p1, Point p2, Point p3, Point p4) { IList <double> xs = JavaUtil.ArraysAsList(p1.GetX(), p2.GetX(), p3.GetX(), p4.GetX()); IList <double> ys = JavaUtil.ArraysAsList(p1.GetY(), p2.GetY(), p3.GetY(), p4.GetY()); double left = Enumerable.Min(xs); double bottom = Enumerable.Min(ys); double right = Enumerable.Max(xs); double top = Enumerable.Max(ys); return(new Rectangle((float)left, (float)bottom, (float)(right - left), (float)(top - bottom))); }
private static Subpath ConstructSquare(Point squareCenter, double widthHalf, double rotationAngle) { // Orthogonal square is the square with sides parallel to one of the axes. Point[] ortogonalSquareVertices = new Point[] { new Point(-widthHalf, -widthHalf), new Point(-widthHalf, widthHalf ), new Point(widthHalf, widthHalf), new Point(widthHalf, -widthHalf) }; Point[] rotatedSquareVertices = GetRotatedSquareVertices(ortogonalSquareVertices, rotationAngle, squareCenter ); Subpath square = new Subpath(); square.AddSegment(new Line(rotatedSquareVertices[0], rotatedSquareVertices[1])); square.AddSegment(new Line(rotatedSquareVertices[1], rotatedSquareVertices[2])); square.AddSegment(new Line(rotatedSquareVertices[2], rotatedSquareVertices[3])); square.AddSegment(new Line(rotatedSquareVertices[3], rotatedSquareVertices[0])); return(square); }
/// <summary>Converts specified degenerate subpaths to squares.</summary> /// <remarks> /// Converts specified degenerate subpaths to squares. /// Note: the list of degenerate subpaths should contain at least 2 elements. Otherwise /// we can't determine the direction which the rotation of each square depends on. /// </remarks> /// <param name="squareWidth">Width of each constructed square.</param> /// <param name="sourcePath">The path which dash pattern applied to. Needed to calc rotation angle of each square. /// </param> /// <returns> /// /// <see cref="System.Collections.IList{E}"/> /// consisting of squares constructed on given degenerated subpaths. /// </returns> private static IList <Subpath> ConvertToSquares(IList <Subpath> degenerateSubpaths, double squareWidth, Path sourcePath) { IList <Point> pathApprox = GetPathApproximation(sourcePath); if (pathApprox.Count < 2) { return(JavaCollectionsUtil.EmptyList <Subpath>()); } IEnumerator <Point> approxIter = pathApprox.GetEnumerator(); approxIter.MoveNext(); Point approxPt1 = approxIter.Current; approxIter.MoveNext(); Point approxPt2 = approxIter.Current; PdfCleanUpFilter.StandardLine line = new PdfCleanUpFilter.StandardLine(approxPt1, approxPt2); IList <Subpath> squares = new List <Subpath>(degenerateSubpaths.Count); float widthHalf = (float)squareWidth / 2; foreach (Subpath subpath in degenerateSubpaths) { Point point = subpath.GetStartPoint(); while (!line.Contains(point)) { approxPt1 = approxPt2; approxIter.MoveNext(); approxPt2 = approxIter.Current; line = new PdfCleanUpFilter.StandardLine(approxPt1, approxPt2); } double slope = line.GetSlope(); double angle; if (!double.IsPositiveInfinity(slope)) { angle = Math.Atan(slope); } else { angle = Math.PI / 2; } squares.Add(ConstructSquare(point, widthHalf, angle)); } return(squares); }
private Point[] TransformPoints(Matrix transformationMatrix, bool inverse, params Point[] points) { AffineTransform t = new AffineTransform(transformationMatrix.Get(Matrix.I11), transformationMatrix.Get(Matrix .I12), transformationMatrix.Get(Matrix.I21), transformationMatrix.Get(Matrix.I22), transformationMatrix .Get(Matrix.I31), transformationMatrix.Get(Matrix.I32)); Point[] transformed = new Point[points.Length]; if (inverse) { try { t = t.CreateInverse(); } catch (NoninvertibleTransformException e) { throw new Exception(e.Message); } } t.Transform(points, 0, transformed, 0, points.Length); return(transformed); }
/// <summary>Approximate a circle with 4 Bezier curves (one for each 90 degrees sector)</summary> /// <param name="center">center of the circle</param> /// <param name="radius">radius of the circle</param> private static BezierCurve[] ApproximateCircle(Point center, double radius) { // The circle is split into 4 sectors. Arc of each sector // is approximated with bezier curve separately. BezierCurve[] approximation = new BezierCurve[4]; double x = center.GetX(); double y = center.GetY(); approximation[0] = new BezierCurve(JavaUtil.ArraysAsList(new Point(x, y + radius), new Point(x + radius * CIRCLE_APPROXIMATION_CONST, y + radius), new Point(x + radius, y + radius * CIRCLE_APPROXIMATION_CONST ), new Point(x + radius, y))); approximation[1] = new BezierCurve(JavaUtil.ArraysAsList(new Point(x + radius, y), new Point(x + radius, y - radius * CIRCLE_APPROXIMATION_CONST), new Point(x + radius * CIRCLE_APPROXIMATION_CONST, y - radius ), new Point(x, y - radius))); approximation[2] = new BezierCurve(JavaUtil.ArraysAsList(new Point(x, y - radius), new Point(x - radius * CIRCLE_APPROXIMATION_CONST, y - radius), new Point(x - radius, y - radius * CIRCLE_APPROXIMATION_CONST ), new Point(x - radius, y))); approximation[3] = new BezierCurve(JavaUtil.ArraysAsList(new Point(x - radius, y), new Point(x - radius, y + radius * CIRCLE_APPROXIMATION_CONST), new Point(x - radius * CIRCLE_APPROXIMATION_CONST, y + radius ), new Point(x, y + radius))); return(approximation); }
protected override void DrawBars(PdfCanvas canvas, PdfPage page) { //int columnCount = _data.Columns.Count; //float totalColumnWidth = (_axisWidth / columnCount); //float barMargin = (totalColumnWidth - _barWidth) / 2; if (_svgRender) { float x = _originX; foreach (Column column in _data.Columns) { float y = _originY; Value value = column.Values[0]; x += _linePointSpace; } } else { float x = _originX; int i = 0; int k = 0; double yOffset = 0; if (_yAxisMin < 0) { yOffset = _yAxisMin * -1.0 * _yScale; } if (_lineCurved) { int j = 0; double lastX = 0.0; double lastY = 0.0; bool lastValueDuplicate = false; for (j = 0; j < _data.Legends.Count; j++) { Legend legend = _data.Legends[j]; // Make a list of control points List <iText.Kernel.Geom.Point> control1 = new List <iText.Kernel.Geom.Point>(); List <iText.Kernel.Geom.Point> control2 = new List <iText.Kernel.Geom.Point>(); List <iText.Kernel.Geom.Point> points = new List <iText.Kernel.Geom.Point>(); x = _originX; // ----------------------- for (i = 0; i < _data.Columns.Count; i++) { Column column = _data.Columns[i]; Value value = column.Values[j]; double y = _originY + value.Data * _yScale + yOffset; lastX = x; if (_skipDuplicates) { if (lastY != y) { lastY = y; points.Add(new iText.Kernel.Geom.Point(x, y)); lastValueDuplicate = false; } else { lastValueDuplicate = true; } } else { lastY = y; points.Add(new iText.Kernel.Geom.Point(x, y)); } //Debug.WriteLine("X:" + x.ToString() + " Y:" + y.ToString()); x += _linePointSpace; } if (lastValueDuplicate) { if (j < _data.Legends.Count - 1) { double nextY = _originY + _data.Columns[0].Values[j + 1].Data * _yScale + yOffset; // Make sure the last value is added as a point if it was a duplicate points.Add(new iText.Kernel.Geom.Point(lastX, nextY)); lastY = nextY; } lastValueDuplicate = false; Debug.WriteLine("Add last Duplicate X:" + lastX.ToString() + " Y:" + lastY.ToString()); } // Add a fake first control point so that the indexes are the same control1.Add(new iText.Kernel.Geom.Point(0, 0)); control2.Add(new iText.Kernel.Geom.Point(0, 0)); for (i = 1; i < points.Count - 1; i++) // from the second point to the second to last point { iText.Kernel.Geom.Point point = points[i]; double x0 = points[i - 1].x; double x2 = points[i + 1].x; double y0 = points[i - 1].y; double y2 = points[i + 1].y; double dirx = x2 - x0; double diry = y2 - y0; double distance = Math.Sqrt(Math.Pow(dirx, 2) + Math.Pow(diry, 2)); double unitx = dirx / distance; double unity = diry / distance; double angle1 = Math.Atan2(unitx, -unity) + Math.PI / 2; double angle2 = Math.Atan2(-unitx, unity) + Math.PI / 2; double control1x = points[i].x + Math.Cos(angle1) * (distance / 5); double control1y = points[i].y + Math.Sin(angle1) * (distance / 5); double control2x = points[i].x + Math.Cos(angle2) * (distance / 5); double control2y = points[i].y + Math.Sin(angle2) * (distance / 5); control1.Add(new iText.Kernel.Geom.Point(control1x, control1y)); control2.Add(new iText.Kernel.Geom.Point(control2x, control2y)); } // Add the last control point so that the indexes are the same control1.Add(new iText.Kernel.Geom.Point(control2[control2.Count - 1].x, control2[control2.Count - 1].y)); control2.Add(new iText.Kernel.Geom.Point(0, 0)); canvas.SetLineWidth(_lineWidth); canvas.SetStrokeColor(legend.Colour); double startX = points[0].x; double startY = _originY + yOffset;; for (i = 0; i < points.Count; i++) { if (i == 0) { canvas.MoveTo(points[i].x, points[i].y); canvas.CurveTo(control1[i + 1].x, control1[i + 1].y, points[i + 1].x, points[i + 1].y); } else if (i == (points.Count - 1)) { } else { canvas.CurveTo(control2[i].x, control2[i].y, control1[i + 1].x, control1[i + 1].y, points[i + 1].x, points[i + 1].y); } } canvas.Stroke(); } } } // SVG Render }
/// <summary>Adds the subpath to this path.</summary> /// <param name="subpath">The subpath to be added to this path.</param> public virtual void AddSubpath(Subpath subpath) { subpaths.Add(subpath); currentPoint = subpath.GetLastPoint(); }
protected override void DrawBars(PdfCanvas canvas, PdfPage page) { //int columnCount = _data.Columns.Count; //float totalColumnWidth = (_axisWidth / columnCount); //float barMargin = (totalColumnWidth - _barWidth) / 2; //SetAxisDimensions(); if (_svgRender) { float x = _originX; foreach (Column column in _data.Columns) { float y = _originY; Value value = column.Values[0]; x += _linePointSpace; } } else { float x = _originX; int i = 0; int k = 0; double yOffset = 0; if (_yAxisMin < 0) { yOffset = _yAxisMin * -1.0 * _yScale; } //double lastValue = double.MaxValue; if (_lineCurved) { int j = 0; double lastX = 0.0; double lastY = 0.0; bool lastValueDuplicate = false; for (j = 0; j < _data.Legends.Count; j++) { Legend legend = _data.Legends[j]; List <iText.Kernel.Geom.Point> control1 = new List <iText.Kernel.Geom.Point>(); List <iText.Kernel.Geom.Point> control2 = new List <iText.Kernel.Geom.Point>(); List <iText.Kernel.Geom.Point> points = new List <iText.Kernel.Geom.Point>(); if (j != 0) { // Add the last point in the previous legend as the first point in this legend // so that they are joined together points.Add(new iText.Kernel.Geom.Point(lastX, lastY)); } for (i = 0; i < _data.Columns.Count; i++) { Column column = _data.Columns[i]; for (k = 0; k < column.Values.Count; k++) { Value value = column.Values[k]; if (value.Legend == legend) { double y = _originY + value.Data * _yScale + yOffset; lastX = x; if (_skipDuplicates) { if (lastY != y) { lastY = y; points.Add(new iText.Kernel.Geom.Point(x, y)); lastValueDuplicate = false; } else { lastValueDuplicate = true; } } else { lastY = y; points.Add(new iText.Kernel.Geom.Point(x, y)); } Debug.WriteLine("X:" + x.ToString() + " Y:" + y.ToString()); x += _linePointSpace; } } } if (lastValueDuplicate) { if (j < _data.Legends.Count - 1) { double nextY = _originY + _data.Columns[0].Values[j + 1].Data * _yScale + yOffset; // Make sure the last value is added as a point if it was a duplicate points.Add(new iText.Kernel.Geom.Point(lastX, nextY)); lastY = nextY; } lastValueDuplicate = false; Debug.WriteLine("Add last Duplicate X:" + lastX.ToString() + " Y:" + lastY.ToString()); } // Add a fake first control point so that the indexes are the same control1.Add(new iText.Kernel.Geom.Point(0, 0)); control2.Add(new iText.Kernel.Geom.Point(0, 0)); for (i = 1; i < points.Count - 1; i++) // from the second point to the second to last point { iText.Kernel.Geom.Point point = points[i]; double x0 = points[i - 1].x; double x2 = points[i + 1].x; double y0 = points[i - 1].y; double y2 = points[i + 1].y; double dirx = x2 - x0; double diry = y2 - y0; double distance = Math.Sqrt(Math.Pow(dirx, 2) + Math.Pow(diry, 2)); double unitx = dirx / distance; double unity = diry / distance; double angle1 = Math.Atan2(unitx, -unity) + Math.PI / 2; double angle2 = Math.Atan2(-unitx, unity) + Math.PI / 2; double control1x = points[i].x + Math.Cos(angle1) * (distance / 5); double control1y = points[i].y + Math.Sin(angle1) * (distance / 5); double control2x = points[i].x + Math.Cos(angle2) * (distance / 5); double control2y = points[i].y + Math.Sin(angle2) * (distance / 5); control1.Add(new iText.Kernel.Geom.Point(control1x, control1y)); control2.Add(new iText.Kernel.Geom.Point(control2x, control2y)); } // Add the last control point so that the indexes are the same control1.Add(new iText.Kernel.Geom.Point(control2[control2.Count - 1].x, control2[control2.Count - 1].y)); control2.Add(new iText.Kernel.Geom.Point(0, 0)); canvas.SetLineWidth(_lineWidth); canvas.SetStrokeColor(legend.Colour); canvas.SetFillColor(legend.Colour); double startX = points[0].x; double startY = _originY + yOffset;; for (i = 0; i < points.Count; i++) { if (i == 0) { canvas.MoveTo(startX, startY); canvas.LineTo(points[i].x, points[i].y); canvas.CurveTo(control1[i + 1].x, control1[i + 1].y, points[i + 1].x, points[i + 1].y); } else if (i == (points.Count - 1)) { //canvas.CurveTo(control1[i].x, control1[i].y, (double)x, (double)y); canvas.LineTo(points[i].x, startY); } else { canvas.CurveTo(control2[i].x, control2[i].y, control1[i + 1].x, control1[i + 1].y, points[i + 1].x, points[i + 1].y); } } canvas.ClosePath(); canvas.Fill(); canvas.Stroke(); /* * // Draw Control point and normals * canvas.SetLineWidth(0.25f); * canvas.SetStrokeColor(iText.Kernel.Colors.ColorConstants.BLACK); * * for (i = 0; i < points.Count - 1; i++) * { * if (i == 0) * { * //canvas.MoveTo((float)points[i].x, (float)points[i].y); * canvas.SetFillColor(iText.Kernel.Colors.ColorConstants.BLUE); * canvas.Circle((float)points[i].x, (float)points[i].y, 2.0f); * canvas.Fill(); * } * else if (i == (_data.Columns.Count - 1)) * { * * } * else * { * //canvas.CurveTo(control1[i].x, control1[i].y, control2[i].x, control2[i].y, (double)x, (double)y); * * canvas.SetFillColor(iText.Kernel.Colors.ColorConstants.BLUE); * canvas.Circle((float)points[i].x, (float)points[i].y, 2.0f); * canvas.Fill(); * * //canvas.SetFillColor(iText.Kernel.Colors.ColorConstants.RED); * //canvas.Circle(control1[i].x, control1[i].y, 2.0f); * //canvas.Fill(); * //canvas.SetFillColor(iText.Kernel.Colors.ColorConstants.YELLOW); * //canvas.Circle(control2[i].x, control2[i].y, 2.0f); * //canvas.Fill(); * * canvas.MoveTo(control1[i].x, control1[i].y); * canvas.LineTo(control2[i].x, control2[i].y); * canvas.Stroke(); * } * } */ } } else { /* * for (i = 0; i < _data.Columns.Count; i++) * { * Column column = _data.Columns[i]; * Value value = column.Values[0]; * float y = _originY + value.Data * _yScale; * * * if (i == 0) * { * canvas.MoveTo(x, y); * } * else * { * canvas.LineTo(x, y); * } * * x += _linePointSpace; * } * canvas.Stroke(); */ } } // SVG Render }
internal virtual bool Contains(Point point) { return(JavaUtil.FloatCompare(Math.Abs(A * (float)point.GetX() + B * (float)point.GetY() + C), 0.1f) < 0); }
/// <summary>Convert a Rectangle object into 4 Points</summary> /// <param name="rect">input Rectangle</param> private Point[] GetRectangleVertices(Rectangle rect) { Point[] points = new Point[] { new Point(rect.GetLeft(), rect.GetBottom()), new Point(rect.GetRight(), rect .GetBottom()), new Point(rect.GetRight(), rect.GetTop()), new Point(rect.GetLeft(), rect.GetTop()) }; return(points); }