List of usage examples for com.itextpdf.text.pdf.parser Path Path
public Path()
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 . j ava 2 s. c om 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 Path convertToPath(PolyTree result) { Path path = new Path(); PolyNode node = result.getFirst();//from w w w . ja va 2 s. c om while (node != null) { addContour(path, node.getContour(), !node.isOpen()); node = node.getNext(); } return path; }
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 a 2 s . c om*/ 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.PdfCleanUpRenderListener.java
License:Open Source License
public Path renderPath(PathPaintingRenderInfo renderInfo) { boolean stroke = (renderInfo.getOperation() & PathPaintingRenderInfo.STROKE) != 0; boolean fill = (renderInfo.getOperation() & PathPaintingRenderInfo.FILL) != 0; float lineWidth = renderInfo.getLineWidth(); int lineCapStyle = renderInfo.getLineCapStyle(); int lineJoinStyle = renderInfo.getLineJoinStyle(); float miterLimit = renderInfo.getMiterLimit(); LineDashPattern lineDashPattern = renderInfo.getLineDashPattern(); if (stroke) { currentStrokePath = filterCurrentPath(renderInfo.getCtm(), true, -1, lineWidth, lineCapStyle, lineJoinStyle, miterLimit, lineDashPattern); }/*from ww w . ja va2 s.c om*/ if (fill) { currentFillPath = filterCurrentPath(renderInfo.getCtm(), false, renderInfo.getRule(), lineWidth, lineCapStyle, lineJoinStyle, miterLimit, lineDashPattern); } if (clipPath) { if (fill && renderInfo.getRule() == clippingRule) { newClippingPath = currentFillPath; } else { newClippingPath = filterCurrentPath(renderInfo.getCtm(), false, clippingRule, lineWidth, lineCapStyle, lineJoinStyle, miterLimit, lineDashPattern); } } unfilteredCurrentPath = new Path(); return newClippingPath; }