Search in sources :

Example 1 with Context

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;
}
Also used : Path(org.apache.poi.sl.draw.geom.Path) JAXBContext(javax.xml.bind.JAXBContext) Context(org.apache.poi.sl.draw.geom.Context) ArrayList(java.util.ArrayList) Rectangle2D(java.awt.geom.Rectangle2D) Outline(org.apache.poi.sl.draw.geom.Outline) AffineTransform(java.awt.geom.AffineTransform) CustomGeometry(org.apache.poi.sl.draw.geom.CustomGeometry)

Aggregations

AffineTransform (java.awt.geom.AffineTransform)1 Rectangle2D (java.awt.geom.Rectangle2D)1 ArrayList (java.util.ArrayList)1 JAXBContext (javax.xml.bind.JAXBContext)1 Context (org.apache.poi.sl.draw.geom.Context)1 CustomGeometry (org.apache.poi.sl.draw.geom.CustomGeometry)1 Outline (org.apache.poi.sl.draw.geom.Outline)1 Path (org.apache.poi.sl.draw.geom.Path)1