Example usage for com.itextpdf.text.pdf.parser.clipper PolyTree PolyTree

List of usage examples for com.itextpdf.text.pdf.parser.clipper PolyTree PolyTree

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf.parser.clipper PolyTree PolyTree.

Prototype

PolyTree

Source Link

Usage

From source file:mkl.testarea.itext5.pdfcleanup.PdfCleanUpRegionFilter.java

License:Open Source License

protected Path filterStrokePath(Path sourcePath, Matrix ctm, float lineWidth, int lineCapStyle,
        int lineJoinStyle, float miterLimit, LineDashPattern lineDashPattern) {
    Path path = sourcePath;//from  w ww  .  j  a va 2s  .  co m
    JoinType joinType = getJoinType(lineJoinStyle);
    EndType endType = getEndType(lineCapStyle);

    if (lineDashPattern != null) {
        if (!lineDashPattern.isSolid()) {
            path = applyDashPattern(path, lineDashPattern);
        }
    }

    ClipperOffset offset = new ClipperOffset(miterLimit,
            StrictPdfCleanUpProcessor.arcTolerance * StrictPdfCleanUpProcessor.floatMultiplier);
    List<Subpath> degenerateSubpaths = addPath(offset, path, joinType, endType);

    PolyTree resultTree = new PolyTree();
    offset.execute(resultTree, lineWidth * StrictPdfCleanUpProcessor.floatMultiplier / 2);
    Path offsetedPath = convertToPath(resultTree);

    if (degenerateSubpaths.size() > 0) {
        if (endType == EndType.OPEN_ROUND) {
            List<Subpath> circles = convertToCircles(degenerateSubpaths, lineWidth / 2);
            offsetedPath.addSubpaths(circles);
        } else if (endType == EndType.OPEN_SQUARE && lineDashPattern != null) {
            List<Subpath> squares = convertToSquares(degenerateSubpaths, lineWidth, sourcePath);
            offsetedPath.addSubpaths(squares);
        }
    }

    return filterFillPath(offsetedPath, ctm, PathPaintingRenderInfo.NONZERO_WINDING_RULE);
}

From source file:mkl.testarea.itext5.pdfcleanup.PdfCleanUpRegionFilter.java

License:Open Source License

/**
 * Note: this method will close all unclosed subpaths of the passed path.
 *
 * @param fillingRule If the subpath is contour, pass any value.
 *//* ww w.j  a va 2s .c  o  m*/
protected Path filterFillPath(Path path, Matrix ctm, int fillingRule) {
    path.closeAllSubpaths();

    Clipper clipper = new DefaultClipper();
    addPath(clipper, path);

    for (Rectangle rectangle : rectangles) {
        Point2D[] transfRectVertices = transformPoints(ctm, true, getVertices(rectangle));
        addRect(clipper, transfRectVertices, PolyType.CLIP);
    }

    PolyFillType fillType = PolyFillType.NON_ZERO;

    if (fillingRule == PathPaintingRenderInfo.EVEN_ODD_RULE) {
        fillType = PolyFillType.EVEN_ODD;
    }

    PolyTree resultTree = new PolyTree();
    clipper.execute(ClipType.DIFFERENCE, resultTree, fillType, PolyFillType.NON_ZERO);

    return convertToPath(resultTree);
}