Search in sources :

Example 1 with CTCustomGeometry2D

use of org.openxmlformats.schemas.drawingml.x2006.main.CTCustomGeometry2D in project poi by apache.

the class XSLFFreeformShape method prototype.

/**
     * @param shapeId 1-based shapeId
     */
static CTShape prototype(int shapeId) {
    CTShape ct = CTShape.Factory.newInstance();
    CTShapeNonVisual nvSpPr = ct.addNewNvSpPr();
    CTNonVisualDrawingProps cnv = nvSpPr.addNewCNvPr();
    cnv.setName("Freeform " + shapeId);
    cnv.setId(shapeId + 1);
    nvSpPr.addNewCNvSpPr();
    nvSpPr.addNewNvPr();
    CTShapeProperties spPr = ct.addNewSpPr();
    CTCustomGeometry2D geom = spPr.addNewCustGeom();
    geom.addNewAvLst();
    geom.addNewGdLst();
    geom.addNewAhLst();
    geom.addNewCxnLst();
    CTGeomRect rect = geom.addNewRect();
    rect.setR("r");
    rect.setB("b");
    rect.setT("t");
    rect.setL("l");
    geom.addNewPathLst();
    return ct;
}
Also used : CTShapeNonVisual(org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual) CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) CTCustomGeometry2D(org.openxmlformats.schemas.drawingml.x2006.main.CTCustomGeometry2D) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTGeomRect(org.openxmlformats.schemas.drawingml.x2006.main.CTGeomRect) CTShape(org.openxmlformats.schemas.presentationml.x2006.main.CTShape)

Example 2 with CTCustomGeometry2D

use of org.openxmlformats.schemas.drawingml.x2006.main.CTCustomGeometry2D 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));
}
Also used : CTPath2DLineTo(org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DLineTo) CTPath2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPath2D) CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) CTCustomGeometry2D(org.openxmlformats.schemas.drawingml.x2006.main.CTCustomGeometry2D) Path2D(java.awt.geom.Path2D) CTPath2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPath2D) Rectangle2D(java.awt.geom.Rectangle2D) CTPath2DQuadBezierTo(org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DQuadBezierTo) CTPath2DMoveTo(org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DMoveTo) CTPath2DClose(org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DClose) CTAdjPoint2D(org.openxmlformats.schemas.drawingml.x2006.main.CTAdjPoint2D) CTPath2DCubicBezierTo(org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DCubicBezierTo) AffineTransform(java.awt.geom.AffineTransform) XmlObject(org.apache.xmlbeans.XmlObject)

Aggregations

CTCustomGeometry2D (org.openxmlformats.schemas.drawingml.x2006.main.CTCustomGeometry2D)2 CTShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties)2 AffineTransform (java.awt.geom.AffineTransform)1 Path2D (java.awt.geom.Path2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1 XmlObject (org.apache.xmlbeans.XmlObject)1 CTAdjPoint2D (org.openxmlformats.schemas.drawingml.x2006.main.CTAdjPoint2D)1 CTGeomRect (org.openxmlformats.schemas.drawingml.x2006.main.CTGeomRect)1 CTNonVisualDrawingProps (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps)1 CTPath2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPath2D)1 CTPath2DClose (org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DClose)1 CTPath2DCubicBezierTo (org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DCubicBezierTo)1 CTPath2DLineTo (org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DLineTo)1 CTPath2DMoveTo (org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DMoveTo)1 CTPath2DQuadBezierTo (org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DQuadBezierTo)1 CTShape (org.openxmlformats.schemas.presentationml.x2006.main.CTShape)1 CTShapeNonVisual (org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual)1