Class ClipperBridge


  • public final class ClipperBridge
    extends java.lang.Object
    This class contains a variety of methods allowing the conversion of iText abstractions into abstractions of the Clipper library, and vice versa.

    For example:

    • Field Detail

      • 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 new ClipperBridge instance 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 floatMultiplier is specified, it will be used for all ClipperBridge instances and default value will be ignored.

      • ClipperBridge

        public ClipperBridge​(Path... paths)
        Creates new ClipperBridge instance 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 floatMultiplier is 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 new ClipperBridge instance 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 floatMultiplier is 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

      • convertToPath

        public Path convertToPath​(PolyTree result)
        Converts Clipper library PolyTree abstraction into iText Path object.
        Parameters:
        result - PolyTree object to convert
        Returns:
        resultant Path object
      • convertToFloatPoints

        public java.util.List<Point> convertToFloatPoints​(java.util.List<Point.LongPoint> points)
        Converts list of Point.LongPoint objects into list of Point objects.
        Parameters:
        points - the list of Point.LongPoint objects to convert
        Returns:
        the resultant list of Point objects.
      • 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. See PdfCanvasConstants
        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. See PdfCanvasConstants
        Returns:
        Clipper line cap (end type) style constant.
      • addPolygonToClipper

        public boolean addPolygonToClipper​(IClipper clipper,
                                           Point[] polyVertices,
                                           IClipper.PolyType polyType)
        Adds polygon path based on array of Point (internally converting them by convertToLongPoints(java.util.List<com.itextpdf.kernel.geom.Point>)) 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 of Point which will be internally converted to clipper path and added to the clipper instance.
        polyType - either IClipper.PolyType.SUBJECT or IClipper.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

        public boolean addPolylineSubjectToClipper​(IClipper clipper,
                                                   Point[] lineVertices)
        Adds polyline path based on array of Point (internally converting them by convertToLongPoints(java.util.List<com.itextpdf.kernel.geom.Point>)) 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;
        Parameters:
        clipper - IClipper instance to which the created polyline path will be added.
        lineVertices - an array of Point which will be internally converted to clipper path and added to the clipper instance.
        Returns:
        true if polyline path was successfully added, false otherwise.
      • longRectCalculateWidth

        public float longRectCalculateWidth​(LongRect rect)
        Calculates the width of the rectangle represented by the LongRect object.
        Parameters:
        rect - the LongRect object representing the rectangle.
        Returns:
        the width of the rectangle.
      • longRectCalculateHeight

        public float longRectCalculateHeight​(LongRect rect)
        Calculates the height of the rectangle represented by the LongRect object.
        Parameters:
        rect - the LongRect object 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)