Class ClipperBridge
java.lang.Object
com.itextpdf.kernel.pdf.canvas.parser.clipper.ClipperBridge
This class contains variety of methods allowing to convert iText abstractions into the abstractions of the Clipper library and vise versa.
For example:
PolyTreetoPathPointtoPoint.LongPointPoint.LongPointtoPoint
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic doubleSince the clipper library uses integer coordinates, we should convert our floating point numbers into fixed point numbers by multiplying by this coefficient. -
Method Summary
Modifier and TypeMethodDescriptionaddPath(ClipperOffset offset, Path path, IClipper.JoinType joinType, IClipper.EndType endType) Adds all iTextSubpaths of the iTextPathto theClipperOffsetobject with one note: it doesn't add degenerate subpaths.static voidaddPath(IClipper clipper, Path path, IClipper.PolyType polyType) static booleanaddPolygonToClipper(IClipper clipper, Point[] polyVertices, IClipper.PolyType polyType) Adds polygon path based on array ofPoint(internally converting them byconvertToLongPoints(java.util.List) and adds this path to) IClipperinstance, treating the path as a closed polygon.static booleanaddPolylineSubjectToClipper(IClipper clipper, Point[] lineVertices) Adds polyline path based on array ofPoint(internally converting them byconvertToLongPoints(java.util.List) and adds this path to) IClipperinstance, treating the path as a polyline (an open path in terms of clipper library).convertToFloatPoints(List<Point.LongPoint> points) Converts list ofPoint.LongPointobjects into list ofPointobjects.static List<Point.LongPoint>convertToLongPoints(List<Point> points) Converts list ofPointobjects into list ofPoint.LongPointobjects.static PathconvertToPath(PolyTree result) static IClipper.EndTypegetEndType(int lineCapStyle) Converts iText line cap style constant into the corresponding constant of the Clipper library.static IClipper.PolyFillTypegetFillType(int fillingRule) Converts iText filling rule constant into the corresponding constant of the Clipper library.static IClipper.JoinTypegetJoinType(int lineJoinStyle) Converts iText line join style constant into the corresponding constant of the Clipper library.
-
Field Details
-
floatMultiplier
public static double floatMultiplierSince the clipper library uses integer coordinates, we should convert our floating point numbers into fixed point numbers by multiplying by this coefficient. Vary it to adjust the preciseness of the calculations.
-
-
Method Details
-
convertToPath
-
addPath
- Parameters:
-
clipper- TheIClipperobject. -
path- ThePathobject to be added to theIClipper. -
polyType- SeeIClipper.PolyType.
-
addPath
public static List<Subpath> addPath(ClipperOffset offset, Path path, IClipper.JoinType joinType, IClipper.EndType endType) Adds all iTextSubpaths of the iTextPathto theClipperOffsetobject with one note: it doesn't add degenerate subpaths.- Parameters:
-
offset- theClipperOffsetobject to add all iTextSubpaths that are not degenerated. -
path-Pathobject, containing the requiredSubpaths -
joinType-IClipperjoin type. The value could beIClipper.JoinType.BEVEL,IClipper.JoinType.ROUND,IClipper.JoinType.MITER -
endType-IClipperend type. The value could beIClipper.EndType.CLOSED_POLYGON,IClipper.EndType.CLOSED_LINE,IClipper.EndType.OPEN_BUTT,IClipper.EndType.OPEN_SQUARE,IClipper.EndType.OPEN_ROUND - Returns:
-
Listconsisting of all degenerate iTextSubpaths of the path.
-
convertToFloatPoints
Converts list ofPoint.LongPointobjects into list ofPointobjects.- Parameters:
-
points- the list ofPoint.LongPointobjects to convert - Returns:
-
the resultant list of
Pointobjects.
-
convertToLongPoints
Converts list ofPointobjects into list ofPoint.LongPointobjects.- Parameters:
-
points- the list ofPointobjects to convert - Returns:
-
the resultant list of
Point.LongPointobjects.
-
getJoinType
Converts iText line join style constant into the corresponding constant of the Clipper library.- Parameters:
-
lineJoinStyle- iText line join style constant. SeePdfCanvasConstants - Returns:
- Clipper line join style constant.
-
getEndType
Converts iText line cap style constant into the corresponding constant of the Clipper library.- Parameters:
-
lineCapStyle- iText line cap style constant. SeePdfCanvasConstants - Returns:
- Clipper line cap (end type) style constant.
-
getFillType
Converts iText filling rule constant into the corresponding constant of the Clipper library.- Parameters:
-
fillingRule- EitherPdfCanvasConstants.FillingRule.NONZERO_WINDINGorPdfCanvasConstants.FillingRule.EVEN_ODD. - Returns:
- Clipper fill type constant.
-
addPolygonToClipper
public static boolean addPolygonToClipper(IClipper clipper, Point[] polyVertices, IClipper.PolyType polyType) Adds polygon path based on array ofPoint(internally converting them byconvertToLongPoints(java.util.List) and adds this path to) IClipperinstance, treating the path as a closed polygon.The return value will be false if the path is invalid for clipping. A path is invalid for clipping when:
- it has less than 3 vertices;
- the vertices are all co-linear.
- Parameters:
-
clipper-IClipperinstance to which the created polygon path will be added. -
polyVertices- an array ofPointwhich will be internally converted to clipper path and added to the clipper instance. -
polyType- eitherIClipper.PolyType.SUBJECTorIClipper.PolyType.CLIPdenoting whether added path is a subject of clipping or a part of the clipping polygon. - Returns:
- true if polygon path was successfully added, false otherwise.
-
addPolylineSubjectToClipper
Adds polyline path based on array ofPoint(internally converting them byconvertToLongPoints(java.util.List) and adds this path to) IClipperinstance, treating the path as a polyline (an open path in terms of clipper library). This path is added to the subject of future clipping. Polylines cannot be part of clipping polygon.The return value will be false if the path is invalid for clipping. A path is invalid for clipping when:
- it has less than 2 vertices;
-