use of com.itextpdf.kernel.geom.Subpath in project i7j-pdfsweep by itext.
the class PdfCleanUpFilter method convertToSquares.
/**
* Converts specified degenerate subpaths to squares.
* Note: the list of degenerate subpaths should contain at least 2 elements. Otherwise
* we can't determine the direction which the rotation of each square depends on.
*
* @param squareWidth Width of each constructed square.
* @param sourcePath The path which dash pattern applied to. Needed to calc rotation angle of each square.
* @return {@link java.util.List} consisting of squares constructed on given degenerated subpaths.
*/
private static List<Subpath> convertToSquares(List<Subpath> degenerateSubpaths, double squareWidth, com.itextpdf.kernel.geom.Path sourcePath) {
List<Point> pathApprox = getPathApproximation(sourcePath);
if (pathApprox.size() < 2) {
return Collections.<Subpath>emptyList();
}
Iterator<Point> approxIter = pathApprox.iterator();
Point approxPt1 = approxIter.next();
Point approxPt2 = approxIter.next();
StandardLine line = new StandardLine(approxPt1, approxPt2);
List<Subpath> squares = new ArrayList<>(degenerateSubpaths.size());
float widthHalf = (float) squareWidth / 2;
for (Subpath subpath : degenerateSubpaths) {
Point point = subpath.getStartPoint();
while (!line.contains(point)) {
approxPt1 = approxPt2;
approxPt2 = approxIter.next();
line = new StandardLine(approxPt1, approxPt2);
}
double slope = line.getSlope();
double angle;
if (slope != Float.POSITIVE_INFINITY) {
angle = Math.atan(slope);
} else {
angle = Math.PI / 2;
}
squares.add(constructSquare(point, widthHalf, angle));
}
return squares;
}
Aggregations