Search in sources :

Example 1 with CTShapeProperties

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

the class XSLFFreeformShape method setPath.

@Override
public int setPath(Path2D.Double path) {
    CTPath2D ctPath = CTPath2D.Factory.newInstance();
    Rectangle2D bounds = path.getBounds2D();
    int x0 = Units.toEMU(bounds.getX());
    int y0 = Units.toEMU(bounds.getY());
    PathIterator it = path.getPathIterator(new AffineTransform());
    int numPoints = 0;
    ctPath.setH(Units.toEMU(bounds.getHeight()));
    ctPath.setW(Units.toEMU(bounds.getWidth()));
    while (!it.isDone()) {
        double[] vals = new double[6];
        int type = it.currentSegment(vals);
        switch(type) {
            case PathIterator.SEG_MOVETO:
                CTAdjPoint2D mv = ctPath.addNewMoveTo().addNewPt();
                mv.setX(Units.toEMU(vals[0]) - x0);
                mv.setY(Units.toEMU(vals[1]) - y0);
                numPoints++;
                break;
            case PathIterator.SEG_LINETO:
                CTAdjPoint2D ln = ctPath.addNewLnTo().addNewPt();
                ln.setX(Units.toEMU(vals[0]) - x0);
                ln.setY(Units.toEMU(vals[1]) - y0);
                numPoints++;
                break;
            case PathIterator.SEG_QUADTO:
                CTPath2DQuadBezierTo qbez = ctPath.addNewQuadBezTo();
                CTAdjPoint2D qp1 = qbez.addNewPt();
                qp1.setX(Units.toEMU(vals[0]) - x0);
                qp1.setY(Units.toEMU(vals[1]) - y0);
                CTAdjPoint2D qp2 = qbez.addNewPt();
                qp2.setX(Units.toEMU(vals[2]) - x0);
                qp2.setY(Units.toEMU(vals[3]) - y0);
                numPoints += 2;
                break;
            case PathIterator.SEG_CUBICTO:
                CTPath2DCubicBezierTo bez = ctPath.addNewCubicBezTo();
                CTAdjPoint2D p1 = bez.addNewPt();
                p1.setX(Units.toEMU(vals[0]) - x0);
                p1.setY(Units.toEMU(vals[1]) - y0);
                CTAdjPoint2D p2 = bez.addNewPt();
                p2.setX(Units.toEMU(vals[2]) - x0);
                p2.setY(Units.toEMU(vals[3]) - y0);
                CTAdjPoint2D p3 = bez.addNewPt();
                p3.setX(Units.toEMU(vals[4]) - x0);
                p3.setY(Units.toEMU(vals[5]) - y0);
                numPoints += 3;
                break;
            case PathIterator.SEG_CLOSE:
                numPoints++;
                ctPath.addNewClose();
                break;
            default:
                throw new IllegalStateException("Unrecognized path segment type: " + type);
        }
        it.next();
    }
    XmlObject xo = getShapeProperties();
    if (!(xo instanceof CTShapeProperties)) {
        return -1;
    }
    ((CTShapeProperties) xo).getCustGeom().getPathLst().setPathArray(new CTPath2D[] { ctPath });
    setAnchor(bounds);
    return numPoints;
}
Also used : CTAdjPoint2D(org.openxmlformats.schemas.drawingml.x2006.main.CTAdjPoint2D) CTPath2DCubicBezierTo(org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DCubicBezierTo) CTPath2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPath2D) CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) PathIterator(java.awt.geom.PathIterator) Rectangle2D(java.awt.geom.Rectangle2D) AffineTransform(java.awt.geom.AffineTransform) XmlObject(org.apache.xmlbeans.XmlObject) CTPath2DQuadBezierTo(org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DQuadBezierTo)

Example 2 with CTShapeProperties

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

the class XSLFAutoShape 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("AutoShape " + shapeId);
    cnv.setId(shapeId + 1);
    nvSpPr.addNewCNvSpPr();
    nvSpPr.addNewNvPr();
    CTShapeProperties spPr = ct.addNewSpPr();
    CTPresetGeometry2D prst = spPr.addNewPrstGeom();
    prst.setPrst(STShapeType.RECT);
    prst.addNewAvLst();
    return ct;
}
Also used : CTShapeNonVisual(org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual) CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) CTPresetGeometry2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTShape(org.openxmlformats.schemas.presentationml.x2006.main.CTShape)

Example 3 with CTShapeProperties

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

the class XSLFConnectorShape method prototype.

/**
     * @param shapeId 1-based shapeId
     */
static CTConnector prototype(int shapeId) {
    CTConnector ct = CTConnector.Factory.newInstance();
    CTConnectorNonVisual nvSpPr = ct.addNewNvCxnSpPr();
    CTNonVisualDrawingProps cnv = nvSpPr.addNewCNvPr();
    cnv.setName("Connector " + shapeId);
    cnv.setId(shapeId + 1);
    nvSpPr.addNewCNvCxnSpPr();
    nvSpPr.addNewNvPr();
    CTShapeProperties spPr = ct.addNewSpPr();
    CTPresetGeometry2D prst = spPr.addNewPrstGeom();
    prst.setPrst(STShapeType.LINE);
    prst.addNewAvLst();
    /* CTLineProperties ln = */
    spPr.addNewLn();
    return ct;
}
Also used : CTConnector(org.openxmlformats.schemas.presentationml.x2006.main.CTConnector) CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) CTPresetGeometry2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTConnectorNonVisual(org.openxmlformats.schemas.presentationml.x2006.main.CTConnectorNonVisual)

Example 4 with CTShapeProperties

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

the class XSLFSimpleShape method getLn.

private static CTLineProperties getLn(XSLFShape shape, boolean create) {
    XmlObject pr = shape.getShapeProperties();
    if (!(pr instanceof CTShapeProperties)) {
        LOG.log(POILogger.WARN, shape.getClass() + " doesn't have line properties");
        return null;
    }
    CTShapeProperties spr = (CTShapeProperties) pr;
    return (spr.isSetLn() || !create) ? spr.getLn() : spr.addNewLn();
}
Also used : CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) XmlObject(org.apache.xmlbeans.XmlObject)

Example 5 with CTShapeProperties

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

the class XSSFShape method setNoFill.

@Override
public void setNoFill(boolean noFill) {
    CTShapeProperties props = getShapeProperties();
    //unset solid and pattern fills if they are set
    if (props.isSetPattFill())
        props.unsetPattFill();
    if (props.isSetSolidFill())
        props.unsetSolidFill();
    props.setNoFill(CTNoFillProperties.Factory.newInstance());
}
Also used : CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties)

Aggregations

CTShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties)21 CTPresetGeometry2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D)9 CTNonVisualDrawingProps (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps)8 XmlObject (org.apache.xmlbeans.XmlObject)6 CTTransform2D (org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D)5 CTBlipFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties)4 CTLineProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties)4 CTPoint2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D)4 CTPositiveSize2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D)4 AffineTransform (java.awt.geom.AffineTransform)2 Rectangle2D (java.awt.geom.Rectangle2D)2 Test (org.junit.Test)2 CTAdjPoint2D (org.openxmlformats.schemas.drawingml.x2006.main.CTAdjPoint2D)2 CTBlip (org.openxmlformats.schemas.drawingml.x2006.main.CTBlip)2 CTCustomGeometry2D (org.openxmlformats.schemas.drawingml.x2006.main.CTCustomGeometry2D)2 CTNonVisualPictureProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualPictureProperties)2 CTPath2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPath2D)2 CTPath2DCubicBezierTo (org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DCubicBezierTo)2 CTPath2DQuadBezierTo (org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DQuadBezierTo)2 CTSRgbColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor)2