Search in sources :

Example 1 with CTGroupShape

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape in project poi by apache.

the class XSLFCommonSlideData method processShape.

private void processShape(CTGroupShape gs, List<DrawingTextBody> out) {
    for (CTShape shape : gs.getSpArray()) {
        CTTextBody ctTextBody = shape.getTxBody();
        if (ctTextBody == null) {
            continue;
        }
        DrawingTextBody textBody;
        CTApplicationNonVisualDrawingProps nvpr = shape.getNvSpPr().getNvPr();
        if (nvpr.isSetPh()) {
            textBody = new DrawingTextPlaceholder(ctTextBody, nvpr.getPh());
        } else {
            textBody = new DrawingTextBody(ctTextBody);
        }
        out.add(textBody);
    }
}
Also used : CTShape(org.openxmlformats.schemas.presentationml.x2006.main.CTShape) CTApplicationNonVisualDrawingProps(org.openxmlformats.schemas.presentationml.x2006.main.CTApplicationNonVisualDrawingProps) CTTextBody(org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody)

Example 2 with CTGroupShape

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape in project poi by apache.

the class XSSFShapeGroup method prototype.

/**
     * Initialize default structure of a new shape group
     */
protected static CTGroupShape prototype() {
    if (prototype == null) {
        CTGroupShape shape = CTGroupShape.Factory.newInstance();
        CTGroupShapeNonVisual nv = shape.addNewNvGrpSpPr();
        CTNonVisualDrawingProps nvpr = nv.addNewCNvPr();
        nvpr.setId(0);
        nvpr.setName("Group 0");
        nv.addNewCNvGrpSpPr();
        CTGroupShapeProperties sp = shape.addNewGrpSpPr();
        CTGroupTransform2D t2d = sp.addNewXfrm();
        CTPositiveSize2D p1 = t2d.addNewExt();
        p1.setCx(0);
        p1.setCy(0);
        CTPoint2D p2 = t2d.addNewOff();
        p2.setX(0);
        p2.setY(0);
        CTPositiveSize2D p3 = t2d.addNewChExt();
        p3.setCx(0);
        p3.setCy(0);
        CTPoint2D p4 = t2d.addNewChOff();
        p4.setX(0);
        p4.setY(0);
        prototype = shape;
    }
    return prototype;
}
Also used : CTPoint2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D) CTGroupTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D) CTGroupShapeNonVisual(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShapeNonVisual) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTGroupShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTGroupShapeProperties) CTPositiveSize2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D) CTGroupShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape)

Example 3 with CTGroupShape

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape in project poi by apache.

the class XSSFDrawing method addShapes.

private void addShapes(XmlCursor cur, List<XSSFShape> lst) {
    try {
        do {
            cur.push();
            if (cur.toFirstChild()) {
                do {
                    XmlObject obj = cur.getObject();
                    XSSFShape shape;
                    if (obj instanceof CTMarker) {
                        // ignore anchor elements
                        continue;
                    } else if (obj instanceof CTPicture) {
                        shape = new XSSFPicture(this, (CTPicture) obj);
                    } else if (obj instanceof CTConnector) {
                        shape = new XSSFConnector(this, (CTConnector) obj);
                    } else if (obj instanceof CTShape) {
                        shape = hasOleLink(obj) ? new XSSFObjectData(this, (CTShape) obj) : new XSSFSimpleShape(this, (CTShape) obj);
                    } else if (obj instanceof CTGraphicalObjectFrame) {
                        shape = new XSSFGraphicFrame(this, (CTGraphicalObjectFrame) obj);
                    } else if (obj instanceof CTGroupShape) {
                        shape = new XSSFShapeGroup(this, (CTGroupShape) obj);
                    } else if (obj instanceof XmlAnyTypeImpl) {
                        LOG.log(POILogger.WARN, "trying to parse AlternateContent, " + "this unlinks the returned Shapes from the underlying xml content, " + "so those shapes can't be used to modify the drawing, " + "i.e. modifications will be ignored!");
                        // XmlAnyTypeImpl is returned for AlternateContent parts, which might contain a CTDrawing
                        cur.push();
                        cur.toFirstChild();
                        XmlCursor cur2 = null;
                        try {
                            // need to parse AlternateContent again, otherwise the child elements aren't typed,
                            // but also XmlAnyTypes
                            CTDrawing alterWS = CTDrawing.Factory.parse(cur.newXMLStreamReader());
                            cur2 = alterWS.newCursor();
                            if (cur2.toFirstChild()) {
                                addShapes(cur2, lst);
                            }
                        } catch (XmlException e) {
                            LOG.log(POILogger.WARN, "unable to parse CTDrawing in alternate content.", e);
                        } finally {
                            if (cur2 != null) {
                                cur2.dispose();
                            }
                            cur.pop();
                        }
                        continue;
                    } else {
                        // ignore anything else
                        continue;
                    }
                    assert (shape != null);
                    shape.anchor = getAnchorFromParent(obj);
                    lst.add(shape);
                } while (cur.toNextSibling());
            }
            cur.pop();
        } while (cur.toNextSibling());
    } finally {
        cur.dispose();
    }
}
Also used : CTMarker(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker) CTConnector(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector) CTGraphicalObjectFrame(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrame) CTDrawing(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing) CTShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape) CTGroupShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape) XmlCursor(org.apache.xmlbeans.XmlCursor) XmlException(org.apache.xmlbeans.XmlException) CTPicture(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPicture) XmlAnyTypeImpl(org.apache.xmlbeans.impl.values.XmlAnyTypeImpl) XmlObject(org.apache.xmlbeans.XmlObject)

Example 4 with CTGroupShape

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape in project poi by apache.

the class XSLFSlide method prototype.

private static CTSlide prototype() {
    CTSlide ctSlide = CTSlide.Factory.newInstance();
    CTCommonSlideData cSld = ctSlide.addNewCSld();
    CTGroupShape spTree = cSld.addNewSpTree();
    CTGroupShapeNonVisual nvGrpSpPr = spTree.addNewNvGrpSpPr();
    CTNonVisualDrawingProps cnvPr = nvGrpSpPr.addNewCNvPr();
    cnvPr.setId(1);
    cnvPr.setName("");
    nvGrpSpPr.addNewCNvGrpSpPr();
    nvGrpSpPr.addNewNvPr();
    CTGroupShapeProperties grpSpr = spTree.addNewGrpSpPr();
    CTGroupTransform2D xfrm = grpSpr.addNewXfrm();
    CTPoint2D off = xfrm.addNewOff();
    off.setX(0);
    off.setY(0);
    CTPositiveSize2D ext = xfrm.addNewExt();
    ext.setCx(0);
    ext.setCy(0);
    CTPoint2D choff = xfrm.addNewChOff();
    choff.setX(0);
    choff.setY(0);
    CTPositiveSize2D chExt = xfrm.addNewChExt();
    chExt.setCx(0);
    chExt.setCy(0);
    ctSlide.addNewClrMapOvr().addNewMasterClrMapping();
    return ctSlide;
}
Also used : CTCommonSlideData(org.openxmlformats.schemas.presentationml.x2006.main.CTCommonSlideData) CTPoint2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D) CTGroupTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D) CTGroupShapeNonVisual(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShapeNonVisual) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTGroupShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTGroupShapeProperties) CTSlide(org.openxmlformats.schemas.presentationml.x2006.main.CTSlide) CTPositiveSize2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D) CTGroupShape(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)

Example 5 with CTGroupShape

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape in project poi by apache.

the class XSLFCommonSlideData method getDrawingText.

public List<DrawingTextBody> getDrawingText() {
    CTGroupShape gs = data.getSpTree();
    List<DrawingTextBody> out = new ArrayList<DrawingTextBody>();
    processShape(gs, out);
    for (CTGroupShape shape : gs.getGrpSpArray()) {
        processShape(shape, out);
    }
    for (CTGraphicalObjectFrame frame : gs.getGraphicFrameArray()) {
        CTGraphicalObjectData data = frame.getGraphic().getGraphicData();
        XmlCursor c = data.newCursor();
        c.selectPath("declare namespace pic='" + CTTable.type.getName().getNamespaceURI() + "' .//pic:tbl");
        while (c.toNextSelection()) {
            XmlObject o = c.getObject();
            if (o instanceof XmlAnyTypeImpl) {
                // Pesky XmlBeans bug - see Bugzilla #49934
                try {
                    o = CTTable.Factory.parse(o.toString(), DEFAULT_XML_OPTIONS);
                } catch (XmlException e) {
                    throw new POIXMLException(e);
                }
            }
            if (o instanceof CTTable) {
                DrawingTable table = new DrawingTable((CTTable) o);
                for (DrawingTableRow row : table.getRows()) {
                    for (DrawingTableCell cell : row.getCells()) {
                        DrawingTextBody textBody = cell.getTextBody();
                        out.add(textBody);
                    }
                }
            }
        }
        c.dispose();
    }
    return out;
}
Also used : CTGraphicalObjectFrame(org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame) ArrayList(java.util.ArrayList) POIXMLException(org.apache.poi.POIXMLException) CTGroupShape(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape) XmlCursor(org.apache.xmlbeans.XmlCursor) CTGraphicalObjectData(org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData) XmlException(org.apache.xmlbeans.XmlException) CTTable(org.openxmlformats.schemas.drawingml.x2006.main.CTTable) XmlAnyTypeImpl(org.apache.xmlbeans.impl.values.XmlAnyTypeImpl) XmlObject(org.apache.xmlbeans.XmlObject)

Aggregations

CTGroupTransform2D (org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D)4 CTGroupShape (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape)4 CTNonVisualDrawingProps (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps)3 CTGroupShape (org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)3 XmlCursor (org.apache.xmlbeans.XmlCursor)2 XmlException (org.apache.xmlbeans.XmlException)2 XmlObject (org.apache.xmlbeans.XmlObject)2 XmlAnyTypeImpl (org.apache.xmlbeans.impl.values.XmlAnyTypeImpl)2 CTGroupShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTGroupShapeProperties)2 CTPoint2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D)2 CTPositiveSize2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D)2 CTTransform2D (org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D)2 CTGroupShapeNonVisual (org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShapeNonVisual)2 ArrayList (java.util.ArrayList)1 POIXMLException (org.apache.poi.POIXMLException)1 CTGraphicalObjectData (org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData)1 CTTable (org.openxmlformats.schemas.drawingml.x2006.main.CTTable)1 CTTextBody (org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody)1 CTConnector (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector)1 CTDrawing (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing)1