use of org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DClose in project poi by apache.
the class XSLFFreeformShape method getPath.
@Override
public Path2D.Double getPath() {
Path2D.Double path = new Path2D.Double();
Rectangle2D bounds = getAnchor();
XmlObject xo = getShapeProperties();
if (!(xo instanceof CTShapeProperties)) {
return null;
}
CTCustomGeometry2D geom = ((CTShapeProperties) xo).getCustGeom();
for (CTPath2D spPath : geom.getPathLst().getPathArray()) {
double scaleW = bounds.getWidth() / Units.toPoints(spPath.getW());
double scaleH = bounds.getHeight() / Units.toPoints(spPath.getH());
for (XmlObject ch : spPath.selectPath("*")) {
if (ch instanceof CTPath2DMoveTo) {
CTAdjPoint2D pt = ((CTPath2DMoveTo) ch).getPt();
path.moveTo((float) (Units.toPoints((Long) pt.getX()) * scaleW), (float) (Units.toPoints((Long) pt.getY()) * scaleH));
} else if (ch instanceof CTPath2DLineTo) {
CTAdjPoint2D pt = ((CTPath2DLineTo) ch).getPt();
path.lineTo((float) Units.toPoints((Long) pt.getX()), (float) Units.toPoints((Long) pt.getY()));
} else if (ch instanceof CTPath2DQuadBezierTo) {
CTPath2DQuadBezierTo bez = ((CTPath2DQuadBezierTo) ch);
CTAdjPoint2D pt1 = bez.getPtArray(0);
CTAdjPoint2D pt2 = bez.getPtArray(1);
path.quadTo((float) (Units.toPoints((Long) pt1.getX()) * scaleW), (float) (Units.toPoints((Long) pt1.getY()) * scaleH), (float) (Units.toPoints((Long) pt2.getX()) * scaleW), (float) (Units.toPoints((Long) pt2.getY()) * scaleH));
} else if (ch instanceof CTPath2DCubicBezierTo) {
CTPath2DCubicBezierTo bez = ((CTPath2DCubicBezierTo) ch);
CTAdjPoint2D pt1 = bez.getPtArray(0);
CTAdjPoint2D pt2 = bez.getPtArray(1);
CTAdjPoint2D pt3 = bez.getPtArray(2);
path.curveTo((float) (Units.toPoints((Long) pt1.getX()) * scaleW), (float) (Units.toPoints((Long) pt1.getY()) * scaleH), (float) (Units.toPoints((Long) pt2.getX()) * scaleW), (float) (Units.toPoints((Long) pt2.getY()) * scaleH), (float) (Units.toPoints((Long) pt3.getX()) * scaleW), (float) (Units.toPoints((Long) pt3.getY()) * scaleH));
} else if (ch instanceof CTPath2DClose) {
path.closePath();
}
}
}
// the created path starts at (x=0, y=0).
// The returned path should fit in the bounding rectangle
AffineTransform at = new AffineTransform();
at.translate(bounds.getX(), bounds.getY());
return new Path2D.Double(at.createTransformedShape(path));
}
Aggregations