Search in sources :

Example 1 with XSLFGeometryProperties

use of org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFGeometryProperties in project poi by apache.

the class XSLFSimpleShape method getGeometry.

/**
     *
     * @return definition of the shape geometry
     */
@Override
public CustomGeometry getGeometry() {
    XSLFGeometryProperties gp = XSLFPropertiesDelegate.getGeometryDelegate(getShapeProperties());
    if (gp == null) {
        return null;
    }
    CustomGeometry geom;
    PresetGeometries dict = PresetGeometries.getInstance();
    if (gp.isSetPrstGeom()) {
        String name = gp.getPrstGeom().getPrst().toString();
        geom = dict.get(name);
        if (geom == null) {
            throw new IllegalStateException("Unknown shape geometry: " + name + ", available geometries are: " + dict.keySet());
        }
    } else if (gp.isSetCustGeom()) {
        XMLStreamReader staxReader = gp.getCustGeom().newXMLStreamReader();
        geom = PresetGeometries.convertCustomGeometry(staxReader);
        try {
            staxReader.close();
        } catch (XMLStreamException e) {
            LOG.log(POILogger.WARN, "An error occurred while closing a Custom Geometry XML Stream Reader: " + e.getMessage());
        }
    } else {
        geom = dict.get("rect");
    }
    return geom;
}
Also used : XSLFGeometryProperties(org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFGeometryProperties) XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) PresetGeometries(org.apache.poi.sl.draw.geom.PresetGeometries) CustomGeometry(org.apache.poi.sl.draw.geom.CustomGeometry)

Example 2 with XSLFGeometryProperties

use of org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFGeometryProperties in project poi by apache.

the class XSLFSimpleShape method setShapeType.

@Override
public void setShapeType(ShapeType type) {
    XSLFGeometryProperties gp = XSLFPropertiesDelegate.getGeometryDelegate(getShapeProperties());
    if (gp == null) {
        return;
    }
    if (gp.isSetCustGeom()) {
        gp.unsetCustGeom();
    }
    CTPresetGeometry2D prst = (gp.isSetPrstGeom()) ? gp.getPrstGeom() : gp.addNewPrstGeom();
    prst.setPrst(STShapeType.Enum.forInt(type.ooxmlId));
}
Also used : XSLFGeometryProperties(org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFGeometryProperties) CTPresetGeometry2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D)

Aggregations

XSLFGeometryProperties (org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFGeometryProperties)2 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 CustomGeometry (org.apache.poi.sl.draw.geom.CustomGeometry)1 PresetGeometries (org.apache.poi.sl.draw.geom.PresetGeometries)1 CTPresetGeometry2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D)1