List of usage examples for com.itextpdf.text.pdf.parser Subpath getPiecewiseLinearApproximation
public List<Point2D> getPiecewiseLinearApproximation()
From source file:mkl.testarea.itext5.pdfcleanup.PdfCleanUpRegionFilter.java
License:Open Source License
private static List<Point2D> getPathApproximation(Path path) { List<Point2D> approx = new ArrayList<Point2D>() { @Override/*from w ww . j ava 2 s .co m*/ public boolean addAll(Collection<? extends Point2D> c) { Point2D prevPoint = (size() - 1 < 0 ? null : get(size() - 1)); boolean ret = false; for (Point2D pt : c) { if (!pt.equals(prevPoint)) { add(pt); prevPoint = pt; ret = true; } } return true; } }; for (Subpath subpath : path.getSubpaths()) { approx.addAll(subpath.getPiecewiseLinearApproximation()); } return approx; }
From source file:mkl.testarea.itext5.pdfcleanup.PdfCleanUpRegionFilter.java
License:Open Source License
/** * Adds all subpaths of the path to the {@link ClipperOffset} object with one * note: it doesn't add degenerate subpaths. * * @return {@link java.util.List} consisting of all degenerate subpaths of the path. *//*from www . j a v a2s.c o m*/ private static List<Subpath> addPath(ClipperOffset offset, Path path, JoinType joinType, EndType endType) { List<Subpath> degenerateSubpaths = new ArrayList<Subpath>(); for (Subpath subpath : path.getSubpaths()) { if (subpath.isDegenerate()) { degenerateSubpaths.add(subpath); continue; } if (!subpath.isSinglePointClosed() && !subpath.isSinglePointOpen()) { EndType et; if (subpath.isClosed()) { // Offsetting is never used for path being filled et = EndType.CLOSED_LINE; } else { et = endType; } List<Point2D> linearApproxPoints = subpath.getPiecewiseLinearApproximation(); offset.addPath(convertToIntPoints(linearApproxPoints), joinType, et); } } return degenerateSubpaths; }
From source file:mkl.testarea.itext5.pdfcleanup.PdfCleanUpRegionFilter.java
License:Open Source License
private static void addPath(Clipper clipper, Path path) { for (Subpath subpath : path.getSubpaths()) { if (!subpath.isSinglePointClosed() && !subpath.isSinglePointOpen()) { List<Point2D> linearApproxPoints = subpath.getPiecewiseLinearApproximation(); clipper.addPath(convertToIntPoints(linearApproxPoints), PolyType.SUBJECT, subpath.isClosed()); }/*from www. ja v a 2 s . c o m*/ } }
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 ww w . ja v a 2 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; }