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);
}
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;
}
Aggregations