use of org.apache.poi.sl.draw.geom.Context in project poi by apache.
the class DrawSimpleShape method computeOutlines.
protected Collection<Outline> computeOutlines(Graphics2D graphics) {
final SimpleShape<?, ?> sh = getShape();
List<Outline> lst = new ArrayList<Outline>();
CustomGeometry geom = sh.getGeometry();
if (geom == null) {
return lst;
}
Rectangle2D anchor = getAnchor(graphics, sh);
for (Path p : geom) {
double w = p.getW(), h = p.getH(), scaleX = Units.toPoints(1), scaleY = scaleX;
if (w == -1) {
w = Units.toEMU(anchor.getWidth());
} else {
scaleX = anchor.getWidth() / w;
}
if (h == -1) {
h = Units.toEMU(anchor.getHeight());
} else {
scaleY = anchor.getHeight() / h;
}
// the guides in the shape definitions are all defined relative to each other,
// so we build the path starting from (0,0).
final Rectangle2D pathAnchor = new Rectangle2D.Double(0, 0, w, h);
Context ctx = new Context(geom, pathAnchor, sh);
java.awt.Shape gp = p.getPath(ctx);
// translate the result to the canvas coordinates in points
AffineTransform at = new AffineTransform();
at.translate(anchor.getX(), anchor.getY());
at.scale(scaleX, scaleY);
java.awt.Shape canvasShape = at.createTransformedShape(gp);
lst.add(new Outline(canvasShape, p));
}
return lst;
}
Aggregations