Я использую PDFBox 3.0.2, чтобы получить путь отсечения и нормальный путь в PDF, но я не уверен, связан ли путь, который я получаю, включен в нормальный путь? Иногда я получаю много клипов, но я не уверен, что этот клип нуждается или в том, что это нормальный путь. />
@Override
public void endPath() throws IOException {}
< /code>
< /blockquote>
Мой нормальный путь получается с использованием следующего метода < /p>
@Override
public void strokePath() {}
@Override
public void fillPath(int i) {}
< /code>
< /blockquote>
@Override
public void endPath() throws IOException {
if (clipWindingRule != -1) {
linePath.setWindingRule(clipWindingRule);
Rectangle2D bounds = linePath.getBounds2D();
ClipPathInfo info = new ClipPathInfo();
Area currentClippingPath = getGraphicsState().getCurrentClippingPath();
if (clipWindingRule == PathIterator.WIND_EVEN_ODD) {
info.setRule("Even-Odd");
} else {
info.setRule("NonZero");
}
Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();
PDRectangle cropBox = page.getCropBox();
float pageHeight = cropBox.getHeight();
double x = bounds.getX() * scale;
double y = (pageHeight - bounds.getY() - bounds.getHeight()) * scale;
double width = bounds.getWidth() * scale;
double height = bounds.getHeight() * scale;
Matrix matrix = new Matrix();
matrix.scale(1, -1);
matrix.translate(0, (float) -y);
matrix.scale(scale, scale);
Matrix multiply = matrix.multiply(ctm);
double[][] mCTMatrix = {
{multiply.getScaleX(), multiply.getShearY(), 0},
{multiply.getShearX(), multiply.getScaleY(), 0},
{multiply.getTranslateX(), multiply.getTranslateY(), 1},
};
info.setCtm(mCTMatrix);
info.setBoundary(new OfdBoxImpl(x, y, width, height));
AbbreviatedData data = new AbbreviatedData();
drawLine(linePath.getPathIterator(null), data, pageHeight * scale, true);
info.setData(data);
clipPathInfos.add(info);
clipWindingRule = -1;}linePath.reset();
< /code>
< /blockquote>
@Override
public void appendRectangle(Point2D p0, Point2D p1, Point2D p2, Point2D p3) {
linePath.moveTo((float) p0.getX(), (float) p0.getY());
linePath.lineTo((float) p1.getX(), (float) p1.getY());
linePath.lineTo((float) p2.getX(), (float) p2.getY());
linePath.lineTo((float) p3.getX(), (float) p3.getY());
linePath.closePath();
}
private void drawLine(PathIterator iterator, AbbreviatedData data, float height, boolean isPath) throws IOException {
double[] coords = new double[6];
while (!iterator.isDone()) {
switch (iterator.currentSegment(coords)) {
case SEG_MOVETO:
data.moveTo(coords[0] * scale, height - coords[1] * scale);
break;
case SEG_LINETO:
data.lineTo(coords[0] * scale, height - coords[1] * scale);
break;
case SEG_CUBICTO:
data.B(coords[0] * scale, height - coords[1] * scale,
coords[2] * scale, height - coords[3] * scale,
coords[4] * scale, height - coords[5] * scale);
break;
case SEG_CLOSE:
data.close();
if (isPath) {
closePath();
}
break;
default:
break;
}
iterator.next();
}
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... -or-fillpa