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);
}
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
}
}
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;
}
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;
}
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();
}
}
Aggregations