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:
PolyTree
toPath
Point
toPoint.LongPoint
Point.LongPoint
toPoint
-
Field Summary
Modifier and TypeFieldDescriptionstatic double
Since 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 iTextSubpath
s of the iTextPath
to theClipperOffset
object with one note: it doesn't add degenerate subpaths.static void
addPath
(IClipper clipper, Path path, IClipper.PolyType polyType) 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) IClipper
instance, treating the path as a closed polygon.static boolean
addPolylineSubjectToClipper
(IClipper clipper, Point[] lineVertices) Adds polyline path based on array ofPoint
(internally converting them byconvertToLongPoints(java.util.List
) and adds this path to) IClipper
instance, treating the path as a polyline (an open path in terms of clipper library).convertToFloatPoints
(List<Point.LongPoint> points) Converts list ofPoint.LongPoint
objects into list ofPoint
objects.static List<Point.LongPoint>
convertToLongPoints
(List<Point> points) Converts list ofPoint
objects into list ofPoint.LongPoint
objects.static Path
convertToPath
(PolyTree result) static IClipper.EndType
getEndType
(int lineCapStyle) Converts iText line cap style constant into the corresponding constant of the Clipper library.static IClipper.PolyFillType
getFillType
(int fillingRule) Converts iText filling rule constant into the corresponding constant of the Clipper library.static IClipper.JoinType
getJoinType
(int lineJoinStyle) Converts iText line join style constant into the corresponding constant of the Clipper library.static float
Calculates the height of the rectangle represented by theLongRect
object.static float
Calculates the width of the rectangle represented by theLongRect
object.
-
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
- TheIClipper
object. -
path
- ThePath
object 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 iTextSubpath
s of the iTextPath
to theClipperOffset
object with one note: it doesn't add degenerate subpaths.- Parameters:
-
offset
- theClipperOffset
object to add all iTextSubpath
s that are not degenerated. -
path
-Path
object, containing the requiredSubpath
s -
joinType
-IClipper
join type. The value could beIClipper.JoinType.BEVEL
,IClipper.JoinType.ROUND
,IClipper.JoinType.MITER
-
endType
-IClipper
end 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:
-
List
consisting of all degenerate iTextSubpath
s of the path.
-
convertToFloatPoints
Converts list ofPoint.LongPoint
objects into list ofPoint
objects.- Parameters:
-
points
- the list ofPoint.LongPoint
objects to convert - Returns:
-
the resultant list of
Point
objects.
-
convertToLongPoints
Converts list ofPoint
objects into list ofPoint.LongPoint
objects.- Parameters:
-
points
- the list ofPoint
objects to convert - Returns:
-
the resultant list of
Point.LongPoint
objects.
-
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_WINDING
orPdfCanvasConstants.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) IClipper
instance, 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
-IClipper
instance to which the created polygon path will be added. -
polyVertices
- an array ofPoint
which will be internally converted to clipper path and added to the clipper instance. -
polyType
- eitherIClipper.PolyType.SUBJECT
orIClipper.PolyType.CLIP
denoting 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) IClipper
instance, 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
Calculates the width of the rectangle represented by theLongRect
object.- Parameters:
-
rect
- theLongRect
object representing the rectangle. - Returns:
- the width of the rectangle.
-
longRectCalculateHeight
Calculates the height of the rectangle represented by theLongRect
object.- Parameters:
-
rect
- theLongRect
object representing the rectangle. - Returns:
- the height of the rectangle.
-