Example usage for com.itextpdf.text.pdf.parser Path getCurrentPoint

List of usage examples for com.itextpdf.text.pdf.parser Path getCurrentPoint

Introduction

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

Prototype

public Point2D getCurrentPoint() 

Source Link

Document

The current point is the trailing endpoint of the segment most recently added to the current path.

Usage

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

License:Open Source License

private static Path applyDashPattern(Path path, LineDashPattern lineDashPattern) {
    Set<Integer> modifiedSubpaths = new HashSet<Integer>(path.replaceCloseWithLine());
    Path dashedPath = new Path();
    int currentSubpath = 0;

    for (Subpath subpath : path.getSubpaths()) {
        List<Point2D> subpathApprox = subpath.getPiecewiseLinearApproximation();

        if (subpathApprox.size() > 1) {
            dashedPath.moveTo((float) subpathApprox.get(0).getX(), (float) subpathApprox.get(0).getY());
            float remainingDist = 0;
            boolean remainingIsGap = false;

            for (int i = 1; i < subpathApprox.size(); ++i) {
                Point2D nextPoint = null;

                if (remainingDist != 0) {
                    nextPoint = getNextPoint(subpathApprox.get(i - 1), subpathApprox.get(i), remainingDist);
                    remainingDist = applyDash(dashedPath, subpathApprox.get(i - 1), subpathApprox.get(i),
                            nextPoint, remainingIsGap);
                }//from  w  w w.  j a v  a2s  . co m

                while (Float.compare(remainingDist, 0) == 0
                        && !dashedPath.getCurrentPoint().equals(subpathApprox.get(i))) {
                    LineDashPattern.DashArrayElem currentElem = lineDashPattern.next();
                    nextPoint = getNextPoint(nextPoint != null ? nextPoint : subpathApprox.get(i - 1),
                            subpathApprox.get(i), currentElem.getVal());
                    remainingDist = applyDash(dashedPath, subpathApprox.get(i - 1), subpathApprox.get(i),
                            nextPoint, currentElem.isGap());
                    remainingIsGap = currentElem.isGap();
                }
            }

            // If true, then the line closing the subpath was explicitly added (see Path.ReplaceCloseWithLine).
            // This causes a loss of a visual effect of line join style parameter, so in this clause
            // we simply add overlapping dash (or gap, no matter), which continues the last dash and equals to
            // the first dash (or gap) of the path.
            if (modifiedSubpaths.contains(currentSubpath)) {
                lineDashPattern.reset();
                LineDashPattern.DashArrayElem currentElem = lineDashPattern.next();
                Point2D nextPoint = getNextPoint(subpathApprox.get(0), subpathApprox.get(1),
                        currentElem.getVal());
                applyDash(dashedPath, subpathApprox.get(0), subpathApprox.get(1), nextPoint,
                        currentElem.isGap());
            }
        }

        // According to PDF spec. line dash pattern should be restarted for each new subpath.
        lineDashPattern.reset();
        ++currentSubpath;
    }

    return dashedPath;
}