Search in sources :

Example 1 with NoninvertibleTransformException

use of com.itextpdf.kernel.geom.NoninvertibleTransformException in project i7j-pdfsweep by itext.

the class PdfCleanUpFilter method filterFillPath.

/**
 * Note: this method will close all unclosed subpaths of the passed path.
 *
 * @param path        the PathRenderInfo object to be filtered.
 * @param ctm         a {@link com.itextpdf.kernel.geom.Path} transformation matrix.
 * @param fillingRule If the subpath is contour, pass any value.
 * @return a filtered {@link com.itextpdf.kernel.geom.Path} object.
 */
private com.itextpdf.kernel.geom.Path filterFillPath(com.itextpdf.kernel.geom.Path path, Matrix ctm, int fillingRule) {
    path.closeAllSubpaths();
    IClipper clipper = new DefaultClipper();
    ClipperBridge.addPath(clipper, path, PolyType.SUBJECT);
    for (Rectangle rectangle : regions) {
        try {
            Point[] transfRectVertices = transformPoints(ctm, true, getRectangleVertices(rectangle));
            ClipperBridge.addPolygonToClipper(clipper, transfRectVertices, PolyType.CLIP);
        } catch (PdfException e) {
            if (!(e.getCause() instanceof NoninvertibleTransformException)) {
                throw e;
            } else {
                logger.error(MessageFormatUtil.format(CleanUpLogMessageConstant.FAILED_TO_PROCESS_A_TRANSFORMATION_MATRIX));
            }
        }
    }
    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);
}
Also used : NoninvertibleTransformException(com.itextpdf.kernel.geom.NoninvertibleTransformException) PdfException(com.itextpdf.kernel.exceptions.PdfException) PolyTree(com.itextpdf.kernel.pdf.canvas.parser.clipper.PolyTree) DefaultClipper(com.itextpdf.kernel.pdf.canvas.parser.clipper.DefaultClipper) Rectangle(com.itextpdf.kernel.geom.Rectangle) IClipper(com.itextpdf.kernel.pdf.canvas.parser.clipper.IClipper) Point(com.itextpdf.kernel.geom.Point) PolyFillType(com.itextpdf.kernel.pdf.canvas.parser.clipper.IClipper.PolyFillType)

Example 2 with NoninvertibleTransformException

use of com.itextpdf.kernel.geom.NoninvertibleTransformException in project i7j-pdfsweep by itext.

the class PdfCleanUpFilter method transformPoints.

private static Point[] transformPoints(Matrix transformationMatrix, boolean inverse, Point... points) {
    AffineTransform t = new AffineTransform(transformationMatrix.get(Matrix.I11), transformationMatrix.get(Matrix.I12), transformationMatrix.get(Matrix.I21), transformationMatrix.get(Matrix.I22), transformationMatrix.get(Matrix.I31), transformationMatrix.get(Matrix.I32));
    Point[] transformed = new Point[points.length];
    if (inverse) {
        try {
            t = t.createInverse();
        } catch (NoninvertibleTransformException e) {
            throw new PdfException(CleanupExceptionMessageConstant.NONINVERTIBLE_MATRIX_CANNOT_BE_PROCESSED, e);
        }
    }
    t.transform(points, 0, transformed, 0, points.length);
    return transformed;
}
Also used : NoninvertibleTransformException(com.itextpdf.kernel.geom.NoninvertibleTransformException) PdfException(com.itextpdf.kernel.exceptions.PdfException) AffineTransform(com.itextpdf.kernel.geom.AffineTransform) Point(com.itextpdf.kernel.geom.Point)

Aggregations

PdfException (com.itextpdf.kernel.exceptions.PdfException)2 NoninvertibleTransformException (com.itextpdf.kernel.geom.NoninvertibleTransformException)2 Point (com.itextpdf.kernel.geom.Point)2 AffineTransform (com.itextpdf.kernel.geom.AffineTransform)1 Rectangle (com.itextpdf.kernel.geom.Rectangle)1 DefaultClipper (com.itextpdf.kernel.pdf.canvas.parser.clipper.DefaultClipper)1 IClipper (com.itextpdf.kernel.pdf.canvas.parser.clipper.IClipper)1 PolyFillType (com.itextpdf.kernel.pdf.canvas.parser.clipper.IClipper.PolyFillType)1 PolyTree (com.itextpdf.kernel.pdf.canvas.parser.clipper.PolyTree)1