Class ClipperBridge
- java.lang.Object
-
- com.itextpdf.kernel.pdf.canvas.parser.clipper.ClipperBridge
-
public final class ClipperBridge extends java.lang.ObjectThis class contains a variety of methods allowing the conversion of iText abstractions into abstractions of the Clipper library, and vice versa.For example:
PolyTreetoPathPointtoPoint.LongPointPoint.LongPointtoPoint
-
-
Field Summary
Fields Modifier and Type Field Description private doubleapproximatedFloatMultiplierstatic java.lang.DoublefloatMultiplierSince the clipper library uses integer coordinates, we should convert our floating point numbers into fixed point numbers by multiplying by this coefficient.private static longMAX_ALLOWED_VALUE
-
Constructor Summary
Constructors Constructor Description ClipperBridge()Creates newClipperBridgeinstance with default float multiplier value which is 10^14.ClipperBridge(Path... paths)Creates newClipperBridgeinstance with adjusted float multiplier value.ClipperBridge(Point[]... points)Creates newClipperBridgeinstance with adjusted float multiplier value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidaddContour(Path path, java.util.List<Point.LongPoint> contour, boolean close)java.util.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.voidaddPath(IClipper clipper, Path path, IClipper.PolyType polyType)booleanaddPolygonToClipper(IClipper clipper, Point[] polyVertices, IClipper.PolyType polyType)Adds polygon path based on array ofPoint(internally converting them byconvertToLongPoints(java.util.List<com.itextpdf.kernel.geom.Point>)) and adds this path toIClipperinstance, treating the path as a closed polygon.booleanaddPolylineSubjectToClipper(IClipper clipper, Point[] lineVertices)Adds polyline path based on array ofPoint(internally converting them byconvertToLongPoints(java.util.List<com.itextpdf.kernel.geom.Point>)) and adds this path toIClipperinstance, treating the path as a polyline (an open path in terms of clipper library).private voidcalculateFloatMultiplier(Point[]... points)java.util.List<Point>convertToFloatPoints(java.util.List<Point.LongPoint> points)Converts list ofPoint.LongPointobjects into list ofPointobjects.java.util.List<Point.LongPoint>convertToLongPoints(java.util.List<Point> points)Converts list ofPointobjects into list ofPoint.LongPointobjects.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.doublegetFloatMultiplier()Gets multiplier coefficient for converting our floating point numbers into fixed point numbers.static IClipper.JoinTypegetJoinType(int lineJoinStyle)Converts iText line join style constant into the corresponding constant of the Clipper library.floatlongRectCalculateHeight(LongRect rect)Calculates the height of the rectangle represented by theLongRectobject.floatlongRectCalculateWidth(LongRect rect)Calculates the width of the rectangle represented by theLongRectobject.
-
-
-
Field Detail
-
MAX_ALLOWED_VALUE
private static final long MAX_ALLOWED_VALUE
- See Also:
- Constant Field Values
-
floatMultiplier
public static java.lang.Double floatMultiplier
Since 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.Note that if this value is specified, it will be used for all ClipperBridge instances and dynamic float multiplier calculation will be disabled.
-
approximatedFloatMultiplier
private double approximatedFloatMultiplier
-
-
Constructor Detail
-
ClipperBridge
public ClipperBridge()
Creates newClipperBridgeinstance with default float multiplier value which is 10^14.Since the clipper library uses integer coordinates, we should convert our floating point numbers into fixed point numbers by multiplying by float multiplier coefficient. It is possible to vary it to adjust the preciseness of the calculations: if static
floatMultiplieris specified, it will be used for all ClipperBridge instances and default value will be ignored.
-
ClipperBridge
public ClipperBridge(Path... paths)
Creates newClipperBridgeinstance with adjusted float multiplier value. This instance will work correctly with the provided paths only.Since the clipper library uses integer coordinates, we should convert our floating point numbers into fixed point numbers by multiplying by float multiplier coefficient. It is calculated automatically, however it is possible to vary it to adjust the preciseness of the calculations: if static
floatMultiplieris specified, it will be used for all ClipperBridge instances and automatic calculation won't work.- Parameters:
paths- paths to calculate multiplier coefficient to convert floating point numbers into fixed point numbers
-
ClipperBridge
public ClipperBridge(Point[]... points)
Creates newClipperBridgeinstance with adjusted float multiplier value. This instance will work correctly with the provided point only.Since the clipper library uses integer coordinates, we should convert our floating point numbers into fixed point numbers by multiplying by float multiplier coefficient. It is calculated automatically, however it is possible to vary it to adjust the preciseness of the calculations: if static
floatMultiplieris specified, it will be used for all ClipperBridge instances and automatic calculation won't work.- Parameters:
points- points to calculate multiplier coefficient to convert floating point numbers into fixed point numbers
-
-
Method Detail
-
addPath
public void addPath(IClipper clipper, Path path, IClipper.PolyType polyType)
- Parameters:
clipper- TheIClipperobject.path- ThePathobject to be added to theIClipper.polyType- SeeIClipper.PolyType.
-
addPath
public java.util.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 requiredSubpathsjoinType-IClipperjoin type. The value could beIClipper.JoinType.BEVEL,IClipper.JoinType.ROUND,IClipper.JoinType.MITERendType-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
public java.util.List<Point> convertToFloatPoints(java.util.List<Point.LongPoint> points)
Converts list ofPoint.LongPointobjects into list ofPointobjects.- Parameters:
points- the list ofPoint.LongPointobjects to convert- Returns:
- the resultant list of
Pointobjects.
-
convertToLongPoints
public java.util.List<Point.LongPoint> convertToLongPoints(java.util.List<Point> points)
Converts list ofPointobjects into list ofPoint.LongPointobjects.- Parameters:
points- the list ofPointobjects to convert- Returns:
- the resultant list of
Point.LongPointobjects.
-
getJoinType
public static IClipper.JoinType getJoinType(int lineJoinStyle)
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
public static IClipper.EndType getEndType(int lineCapStyle)
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
public static IClipper.PolyFillType getFillType(int fillingRule)
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 boolean addPolygonToClipper(IClipper clipper, Point[] polyVertices, IClipper.PolyType polyType)
Adds polygon path based on array ofPoint(internally converting them byconvertToLongPoints(java.util.List<com.itextpdf.kernel.geom.Point>)) and adds this path toIClipperinstance, 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
public boolean addPolylineSubjectToClipper(IClipper clipper, Point[] lineVertices)
Adds polyline path based on array ofPoint(internally converting them byconvertToLongPoints(java.util.List<com.itextpdf.kernel.geom.Point>)) and adds this path toIClipperinstance, 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;
-
longRectCalculateWidth
public float longRectCalculateWidth(LongRect rect)
Calculates the width of the rectangle represented by theLongRectobject.- Parameters:
rect- theLongRectobject representing the rectangle.- Returns:
- the width of the rectangle.
-
longRectCalculateHeight
public float longRectCalculateHeight(LongRect rect)
Calculates the height of the rectangle represented by theLongRectobject.- Parameters:
rect- theLongRectobject representing the rectangle.- Returns:
- the height of the rectangle.
-
getFloatMultiplier
public double getFloatMultiplier()
Gets multiplier coefficient for converting our floating point numbers into fixed point numbers.- Returns:
- multiplier coefficient for converting our floating point numbers into fixed point numbers
-
addContour
void addContour(Path path, java.util.List<Point.LongPoint> contour, boolean close)
-
calculateFloatMultiplier
private void calculateFloatMultiplier(Point[]... points)
-
-