Search in sources :

Example 1 with CTGraphicalObjectFrame

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

the class XSLFGraphicFrame method getAnchor.

@Override
public Rectangle2D getAnchor() {
    CTTransform2D xfrm = ((CTGraphicalObjectFrame) getXmlObject()).getXfrm();
    CTPoint2D off = xfrm.getOff();
    double x = Units.toPoints(off.getX());
    double y = Units.toPoints(off.getY());
    CTPositiveSize2D ext = xfrm.getExt();
    double cx = Units.toPoints(ext.getCx());
    double cy = Units.toPoints(ext.getCy());
    return new Rectangle2D.Double(x, y, cx, cy);
}
Also used : CTTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D) CTPoint2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D) CTGraphicalObjectFrame(org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame) CTPositiveSize2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D)

Example 2 with CTGraphicalObjectFrame

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

the class XSLFGraphicFrame method copy.

@Override
void copy(XSLFShape sh) {
    super.copy(sh);
    CTGraphicalObjectData data = ((CTGraphicalObjectFrame) getXmlObject()).getGraphic().getGraphicData();
    String uri = data.getUri();
    if (uri.equals("http://schemas.openxmlformats.org/drawingml/2006/diagram")) {
        copyDiagram(data, (XSLFGraphicFrame) sh);
    } else {
    // TODO  support other types of objects
    }
}
Also used : CTGraphicalObjectData(org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData)

Example 3 with CTGraphicalObjectFrame

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

the class XSLFTable method prototype.

static CTGraphicalObjectFrame prototype(int shapeId) {
    CTGraphicalObjectFrame frame = CTGraphicalObjectFrame.Factory.newInstance();
    CTGraphicalObjectFrameNonVisual nvGr = frame.addNewNvGraphicFramePr();
    CTNonVisualDrawingProps cnv = nvGr.addNewCNvPr();
    cnv.setName("Table " + shapeId);
    cnv.setId(shapeId + 1);
    nvGr.addNewCNvGraphicFramePr().addNewGraphicFrameLocks().setNoGrp(true);
    nvGr.addNewNvPr();
    frame.addNewXfrm();
    CTGraphicalObjectData gr = frame.addNewGraphic().addNewGraphicData();
    XmlCursor grCur = gr.newCursor();
    grCur.toNextToken();
    grCur.beginElement(new QName(DRAWINGML_URI, "tbl"));
    CTTable tbl = CTTable.Factory.newInstance();
    tbl.addNewTblPr();
    tbl.addNewTblGrid();
    XmlCursor tblCur = tbl.newCursor();
    tblCur.moveXmlContents(grCur);
    tblCur.dispose();
    grCur.dispose();
    gr.setUri(TABLE_URI);
    return frame;
}
Also used : CTGraphicalObjectData(org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData) CTGraphicalObjectFrame(org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame) QName(javax.xml.namespace.QName) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTTable(org.openxmlformats.schemas.drawingml.x2006.main.CTTable) CTGraphicalObjectFrameNonVisual(org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrameNonVisual) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 4 with CTGraphicalObjectFrame

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

the class XSSFDrawing method createGraphicFrame.

/**
     * Creates a new graphic frame.
     *
     * @param anchor    the client anchor describes how this frame is attached
     *                  to the sheet
     * @return  the newly created graphic frame
     */
private XSSFGraphicFrame createGraphicFrame(XSSFClientAnchor anchor) {
    CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
    CTGraphicalObjectFrame ctGraphicFrame = ctAnchor.addNewGraphicFrame();
    ctGraphicFrame.set(XSSFGraphicFrame.prototype());
    ctGraphicFrame.setXfrm(createXfrm(anchor));
    long frameId = numOfGraphicFrames++;
    XSSFGraphicFrame graphicFrame = new XSSFGraphicFrame(this, ctGraphicFrame);
    graphicFrame.setAnchor(anchor);
    graphicFrame.setId(frameId);
    graphicFrame.setName("Diagramm" + frameId);
    return graphicFrame;
}
Also used : CTGraphicalObjectFrame(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrame) CTTwoCellAnchor(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor)

Example 5 with CTGraphicalObjectFrame

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrame 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)

Aggregations

CTGraphicalObjectFrame (org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame)5 XmlCursor (org.apache.xmlbeans.XmlCursor)3 CTGraphicalObjectData (org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData)3 CTPoint2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D)3 CTPositiveSize2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D)3 CTTransform2D (org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D)3 CTGraphicalObjectFrame (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrame)3 XmlException (org.apache.xmlbeans.XmlException)2 XmlObject (org.apache.xmlbeans.XmlObject)2 XmlAnyTypeImpl (org.apache.xmlbeans.impl.values.XmlAnyTypeImpl)2 CTNonVisualDrawingProps (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps)2 CTTable (org.openxmlformats.schemas.drawingml.x2006.main.CTTable)2 ArrayList (java.util.ArrayList)1 QName (javax.xml.namespace.QName)1 POIXMLException (org.apache.poi.POIXMLException)1 BorderEdge (org.apache.poi.sl.usermodel.TableCell.BorderEdge)1 Test (org.junit.Test)1 CTTableCell (org.openxmlformats.schemas.drawingml.x2006.main.CTTableCell)1 CTConnector (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector)1 CTDrawing (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing)1