/// <summary>Return true if two given rectangles (specified by an array of points) intersect</summary> /// <param name="rect1">the first rectangle</param> /// <param name="rect2">the second rectangle</param> /// <returns>true if the rectangles intersect, false otherwise</returns> private bool CheckIfRectanglesIntersect(Point[] rect1, Point[] rect2) { Clipper clipper = new Clipper(); ClipperBridge.AddRectToClipper(clipper, rect1, PolyType.SUBJECT); ClipperBridge.AddRectToClipper(clipper, rect2, PolyType.CLIP); Paths paths = new Paths(); clipper.Execute(ClipType.INTERSECTION, paths, PolyFillType.NON_ZERO, PolyFillType.NON_ZERO); return(!paths.IsEmpty()); }
/// <summary>Intersects the current clipping path with the given path.</summary> /// <remarks> /// Intersects the current clipping path with the given path. /// <strong>Note:</strong> Coordinates of the given path should be in /// the transformed user space. /// </remarks> /// <param name="path">The path to be intersected with the current clipping path.</param> /// <param name="fillingRule"> /// The filling rule which should be applied to the given path. /// It should be either /// <see cref="iText.Kernel.Pdf.Canvas.PdfCanvasConstants.FillingRule.EVEN_ODD"/> /// or /// <see cref="iText.Kernel.Pdf.Canvas.PdfCanvasConstants.FillingRule.NONZERO_WINDING"/> /// </param> public virtual void Clip(Path path, int fillingRule) { if (clippingPath == null || clippingPath.IsEmpty()) { return; } Path pathCopy = new Path(path); pathCopy.CloseAllSubpaths(); Clipper clipper = new Clipper(); ClipperBridge.AddPath(clipper, clippingPath, PolyType.SUBJECT); ClipperBridge.AddPath(clipper, pathCopy, PolyType.CLIP); PolyTree resultTree = new PolyTree(); clipper.Execute(ClipType.INTERSECTION, resultTree, PolyFillType.NON_ZERO, ClipperBridge.GetFillType(fillingRule )); clippingPath = ClipperBridge.ConvertToPath(resultTree); }
private Path FilterStrokePath(Path sourcePath, Matrix ctm, float lineWidth, int lineCapStyle, int lineJoinStyle , float miterLimit, LineDashPattern lineDashPattern) { Path path = sourcePath; JoinType joinType = ClipperBridge.GetJoinType(lineJoinStyle); EndType endType = ClipperBridge.GetEndType(lineCapStyle); if (lineDashPattern != null) { if (!lineDashPattern.IsSolid()) { path = LineDashPattern.ApplyDashPattern(path, lineDashPattern); } } ClipperOffset offset = new ClipperOffset(miterLimit, PdfCleanUpTool.arcTolerance * PdfCleanUpTool.floatMultiplier ); IList <Subpath> degenerateSubpaths = ClipperBridge.AddPath(offset, path, joinType, endType); PolyTree resultTree = new PolyTree(); offset.Execute(ref resultTree, lineWidth * PdfCleanUpTool.floatMultiplier / 2); Path offsetedPath = ClipperBridge.ConvertToPath(resultTree); if (degenerateSubpaths.Count > 0) { if (endType == EndType.OPEN_ROUND) { IList <Subpath> circles = ConvertToCircles(degenerateSubpaths, lineWidth / 2); offsetedPath.AddSubpaths(circles); } else { if (endType == EndType.OPEN_SQUARE && lineDashPattern != null) { IList <Subpath> squares = ConvertToSquares(degenerateSubpaths, lineWidth, sourcePath); offsetedPath.AddSubpaths(squares); } } } return(FilterFillPath(offsetedPath, ctm, PdfCanvasConstants.FillingRule.NONZERO_WINDING)); }
/// <summary>Note: this method will close all unclosed subpaths of the passed path.</summary> /// <param name="fillingRule">If the subpath is contour, pass any value.</param> protected internal virtual Path FilterFillPath(Path path, Matrix ctm, int fillingRule) { path.CloseAllSubpaths(); Clipper clipper = new Clipper(); ClipperBridge.AddPath(clipper, path, PolyType.SUBJECT); foreach (Rectangle rectangle in regions) { Point[] transfRectVertices = TransformPoints(ctm, true, GetRectangleVertices(rectangle)); ClipperBridge.AddRectToClipper(clipper, transfRectVertices, PolyType.CLIP); } PolyFillType fillType = PolyFillType.NON_ZERO; if (fillingRule == PdfCanvasConstants.FillingRule.EVEN_ODD) { fillType = PolyFillType.EVEN_ODD; } PolyTree resultTree = new PolyTree(); clipper.Execute(ClipType.DIFFERENCE, resultTree, fillType, PolyFillType.NON_ZERO); return(ClipperBridge.ConvertToPath(resultTree)); }