/** * Adds additional line to each closed subpath and makes the subpath unclosed. * The line connects the last and the first points of the subpaths. * * @return Indices of modified subpaths. */ public List<Integer> replaceCloseWithLine() { List<Integer> modifiedSubpathsIndices = new ArrayList<>(); int i = 0; /* It could be replaced with "for" cycle, because IList in C# provides effective * access by index. In Java List interface has at least one implementation (LinkedList) * which is "bad" for access elements by index. */ for (Subpath subpath : subpaths) { if (subpath.isClosed()) { subpath.setClosed(false); subpath.addSegment(new Line(subpath.getLastPoint(), subpath.getStartPoint())); modifiedSubpathsIndices.add(i); } ++i; } return modifiedSubpathsIndices; }
private Subpath transformSubpath(Subpath subpath, Matrix newCtm) { Subpath newSubpath = new Subpath(); newSubpath.setClosed(subpath.isClosed()); for (IShape segment : subpath.getSegments()) { IShape transformedSegment = transformSegment(segment, newCtm); newSubpath.addSegment(transformedSegment); } return newSubpath; }
/** * Adds all iText {@link Subpath}s of the iText {@link Path} to the {@link ClipperOffset} object with one * note: it doesn't add degenerate subpaths. * * @return {@link java.util.List} consisting of all degenerate iText {@link Subpath}s of the path. */ public static List<Subpath> addPath(ClipperOffset offset, com.itextpdf.kernel.geom.Path path, IClipper.JoinType joinType, IClipper.EndType endType) { List<Subpath> degenerateSubpaths = new ArrayList<>(); for (Subpath subpath : path.getSubpaths()) { if (subpath.isDegenerate()) { degenerateSubpaths.add(subpath); continue; } if (!subpath.isSinglePointClosed() && !subpath.isSinglePointOpen()) { IClipper.EndType et; if (subpath.isClosed()) { // Offsetting is never used for path being filled et = IClipper.EndType.CLOSED_LINE; } else { et = endType; } List<com.itextpdf.kernel.geom.Point> linearApproxPoints = subpath.getPiecewiseLinearApproximation(); offset.addPath(new Path(convertToLongPoints(linearApproxPoints)), joinType, et); } } return degenerateSubpaths; }
/** * Adds iText {@link Path} to the given {@link IClipper} object. * @param clipper The {@link IClipper} object. * @param path The {@link com.itextpdf.kernel.geom.Path} object to be added to the {@link IClipper}. * @param polyType See {@link IClipper.PolyType}. */ public static void addPath(IClipper clipper, com.itextpdf.kernel.geom.Path path, IClipper.PolyType polyType) { for (Subpath subpath : path.getSubpaths()) { if (!subpath.isSinglePointClosed() && !subpath.isSinglePointOpen()) { List<com.itextpdf.kernel.geom.Point> linearApproxPoints = subpath.getPiecewiseLinearApproximation(); clipper.addPath(new Path(convertToLongPoints(linearApproxPoints)), polyType, subpath.isClosed()); } } }