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

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

Introduction

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

Prototype

public void moveTo(final float x, final float y) 

Source Link

Document

Begins a new subpath by moving the current point to coordinates (x, y).

Usage

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

License:Open Source License

private void writePath(String operatorStr, PdfContentByte canvas, PdfName strokeColorSpace) throws IOException {
    if (nwFillOperators.contains(operatorStr)) {
        writePath(cleanUpStrategy.getCurrentFillPath(), f, canvas);
    } else if (eoFillOperators.contains(operatorStr)) {
        writePath(cleanUpStrategy.getCurrentFillPath(), eoF, canvas);
    }//from w w w.  jav  a  2  s.co m

    if (strokeOperators.contains(operatorStr)) {
        writeStroke(canvas, cleanUpStrategy.getCurrentStrokePath(), strokeColorSpace);
    }

    if (cleanUpStrategy.isClipped()) {
        if (!cleanUpStrategy.getNewClipPath().isEmpty()) {
            byte[] clippingOperator = (cleanUpStrategy
                    .getClippingRule() == PathPaintingRenderInfo.NONZERO_WINDING_RULE) ? W : eoW;
            writePath(cleanUpStrategy.getNewClipPath(), clippingOperator, canvas);
        } else {
            // If the clipping path from the source document is cleaned (it happens when reduction
            // area covers the path completely), then you should treat it as an empty set (no points
            // are included in the path). Then the current clipping path (which is the intersection
            // between previous clipping path and the new one) is also empty set, which means that
            // there is no visible content at all. But at the same time as we removed the clipping
            // path, the invisible content would become visible. So, to emulate the correct result,
            // we would simply put a degenerate clipping path which consists of a single point at (0, 0).
            Path degeneratePath = new Path();
            degeneratePath.moveTo(0, 0);
            writePath(degeneratePath, W, canvas);
        }
        canvas.getInternalBuffer().append(n);
        cleanUpStrategy.setClipped(false);
    }
}

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

License:Open Source License

private static void addContour(Path path, List<LongPoint> contour, Boolean close) {
    List<Point2D> floatContour = convertToFloatPoints(contour);
    Iterator<Point2D> iter = floatContour.iterator();

    Point2D point = iter.next();//w  ww.  j  a  v a 2 s  .c o m
    path.moveTo((float) point.getX(), (float) point.getY());

    while (iter.hasNext()) {
        point = iter.next();
        path.lineTo((float) point.getX(), (float) point.getY());
    }

    if (close) {
        path.closeSubpath();
    }
}

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 www  .j a v a2 s. c  o 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;
}

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

License:Open Source License

private static float applyDash(Path dashedPath, Point2D segStart, Point2D segEnd, Point2D dashTo,
        boolean isGap) {
    float remainingDist = 0;

    if (!liesOnSegment(segStart, segEnd, dashTo)) {
        remainingDist = (float) dashTo.distance(segEnd);
        dashTo = segEnd;// ww  w .  ja v a 2s  .c  om
    }

    if (isGap) {
        dashedPath.moveTo((float) dashTo.getX(), (float) dashTo.getY());
    } else {
        dashedPath.lineTo((float) dashTo.getX(), (float) dashTo.getY());
    }

    return remainingDist;
}