List<XSLFShape> tgtShapes = getShapes(); List<XSLFShape> srcShapes = gr.getShapes(); clear(); XSLFShape newShape; if (shape instanceof XSLFTextBox) { newShape = createTextBox(); } else if (shape instanceof XSLFFreeformShape) { newShape = createFreeform(); } else if (shape instanceof XSLFAutoShape) { newShape = createAutoShape(); } else if (shape instanceof XSLFConnectorShape) { newShape = createConnector(); } else if (shape instanceof XSLFPictureShape) { XSLFPictureShape p = (XSLFPictureShape)shape; XSLFPictureData pd = p.getPictureData(); XSLFPictureData pdNew = getSheet().getSlideShow().addPicture(pd.getData(), pd.getType()); newShape = createPicture(pdNew); } else if (shape instanceof XSLFGroupShape) { newShape = createGroup(); } else if (shape instanceof XSLFTable) { newShape = createTable(); } else { _logger.log(POILogger.WARN, "copying of class "+shape.getClass()+" not supported.");
public XSLFGroupShape createGroup(){ CTGroupShape sp = _spTree.addNewGrpSp(); sp.set(XSLFGroupShape.prototype(_sheet.allocateShapeId())); XSLFGroupShape shape = new XSLFGroupShape(sp, _sheet); shape.setAnchor(new Rectangle2D.Double()); return shape; }
@Override public XSLFObjectShape createOleShape(PictureData pictureData) { if (!(pictureData instanceof XSLFPictureData)) { throw new IllegalArgumentException("pictureData needs to be of type XSLFPictureData"); } RelationPart rp = getSheet().addRelation(null, XSLFRelation.IMAGES, (XSLFPictureData)pictureData); XSLFObjectShape sh = getDrawing().createOleShape(rp.getRelationship().getId()); CTOleObject oleObj = sh.getCTOleObject(); Dimension dim = pictureData.getImageDimension(); oleObj.setImgW(Units.toEMU(dim.getWidth())); oleObj.setImgH(Units.toEMU(dim.getHeight())); getShapes().add(sh); sh.setParent(this); return sh; }
/** * Removes all of the elements from this container (optional operation). * The container will be empty after this call returns. */ @Override public void clear() { List<XSLFShape> shapes = new ArrayList<>(getShapes()); for(XSLFShape shape : shapes){ removeShape(shape); } }
@Override public XSLFGroupShape createGroup(){ XSLFGroupShape sh = getDrawing().createGroup(); _shapes.add(sh); sh.setParent(this); return sh; }
/** * Remove the specified shape from this group */ @Override public boolean removeShape(XSLFShape xShape) { XmlObject obj = xShape.getXmlObject(); CTGroupShape grpSp = (CTGroupShape)getXmlObject(); getSheet().deregisterShapeId(xShape.getShapeId()); if(obj instanceof CTShape){ grpSp.getSpList().remove(obj); } else if (obj instanceof CTGroupShape){ XSLFGroupShape gs = (XSLFGroupShape)xShape; new ArrayList<>(gs.getShapes()).forEach(gs::removeShape); grpSp.getGrpSpList().remove(obj); } else if (obj instanceof CTConnector){ grpSp.getCxnSpList().remove(obj); } else if (obj instanceof CTGraphicalObjectFrame) { grpSp.getGraphicFrameList().remove(obj); } else if (obj instanceof CTPicture) { XSLFPictureShape ps = (XSLFPictureShape)xShape; XSLFSheet sh = getSheet(); if (sh != null) { sh.removePictureRelation(ps); } grpSp.getPicList().remove(obj); } else { throw new IllegalArgumentException("Unsupported shape: " + xShape); } return _shapes.remove(xShape); }
@Override public XSLFFreeformShape createFreeform(){ XSLFFreeformShape sh = getDrawing().createFreeform(); _shapes.add(sh); sh.setParent(this); return sh; }
} else if (obj instanceof CTGroupShape) { XSLFGroupShape gs = (XSLFGroupShape)xShape; new ArrayList<>(gs.getShapes()).forEach(gs::removeShape); spTree.getGrpSpList().remove(obj); } else if (obj instanceof CTConnector) {
public static Shape<?,?> parseShape(byte metroBytes[]) throws InvalidFormatException, IOException, XmlException { PackagePartName shapePN = PackagingURIHelper.createPartName("/drs/shapexml.xml"); OPCPackage pkg = null; try { pkg = OPCPackage.open(new ByteArrayInputStream(metroBytes)); PackagePart shapePart = pkg.getPart(shapePN); CTGroupShape gs = CTGroupShape.Factory.parse(shapePart.getInputStream(), DEFAULT_XML_OPTIONS); XSLFGroupShape xgs = new XSLFGroupShape(gs, null); return xgs.getShapes().get(0); } finally { if (pkg != null) { pkg.close(); } } } }
@Override public void draw(Graphics2D graphics){ // the coordinate system of this group of shape Rectangle2D interior = getInteriorAnchor(); // anchor of this group relative to the parent shape Rectangle2D exterior = getAnchor(); AffineTransform tx = (AffineTransform)graphics.getRenderingHint(XSLFRenderingHint.GROUP_TRANSFORM); AffineTransform tx0 = new AffineTransform(tx); double scaleX = interior.getWidth() == 0. ? 1.0 : exterior.getWidth() / interior.getWidth(); double scaleY = interior.getHeight() == 0. ? 1.0 : exterior.getHeight() / interior.getHeight(); tx.translate(exterior.getX(), exterior.getY()); tx.scale(scaleX, scaleY); tx.translate(-interior.getX(), -interior.getY()); for (XSLFShape shape : getShapes()) { // remember the initial transform and restore it after we are done with the drawing AffineTransform at = graphics.getTransform(); graphics.setRenderingHint(XSLFRenderingHint.GSAVE, true); shape.applyTransform(graphics); shape.draw(graphics); // restore the coordinate system graphics.setTransform(at); graphics.setRenderingHint(XSLFRenderingHint.GRESTORE, true); } graphics.setRenderingHint(XSLFRenderingHint.GROUP_TRANSFORM, tx0); }
@Override public XSLFPictureShape createPicture(PictureData pictureData){ if (!(pictureData instanceof XSLFPictureData)) { throw new IllegalArgumentException("pictureData needs to be of type XSLFPictureData"); } RelationPart rp = getSheet().addRelation(null, XSLFRelation.IMAGES, (XSLFPictureData)pictureData); XSLFPictureShape sh = getDrawing().createPicture(rp.getRelationship().getId()); new DrawPictureShape(sh).resize(); _shapes.add(sh); sh.setParent(this); return sh; }
shapes.add(shape); } else if (ch instanceof CTGroupShape){ shapes.add(new XSLFGroupShape((CTGroupShape)ch, sheet)); } else if (ch instanceof CTConnector){ shapes.add(new XSLFConnectorShape((CTConnector)ch, sheet));
/** * Removes all of the elements from this container (optional operation). * The container will be empty after this call returns. */ public void clear() { for(XSLFShape shape : getShapes()){ removeShape(shape); } }
/** * Remove the specified shape from this group */ @Override public boolean removeShape(XSLFShape xShape) { XmlObject obj = xShape.getXmlObject(); CTGroupShape grpSp = (CTGroupShape)getXmlObject(); getSheet().deregisterShapeId(xShape.getShapeId()); if(obj instanceof CTShape){ grpSp.getSpList().remove(obj); } else if (obj instanceof CTGroupShape){ XSLFGroupShape gs = (XSLFGroupShape)xShape; new ArrayList<>(gs.getShapes()).forEach(gs::removeShape); grpSp.getGrpSpList().remove(obj); } else if (obj instanceof CTConnector){ grpSp.getCxnSpList().remove(obj); } else if (obj instanceof CTGraphicalObjectFrame) { grpSp.getGraphicFrameList().remove(obj); } else if (obj instanceof CTPicture) { XSLFPictureShape ps = (XSLFPictureShape)xShape; XSLFSheet sh = getSheet(); if (sh != null) { sh.removePictureRelation(ps); } grpSp.getPicList().remove(obj); } else { throw new IllegalArgumentException("Unsupported shape: " + xShape); } return _shapes.remove(xShape); }
@Override public XSLFAutoShape createAutoShape(){ XSLFAutoShape sh = getDrawing().createAutoShape(); _shapes.add(sh); sh.setParent(this); return sh; }
extractContent(group.getShapes(), skipPlaceholders, xhtml, slideDesc); } else if (sh instanceof XSLFTable) {
public static Shape<?,?> parseShape(byte metroBytes[]) throws InvalidFormatException, IOException, XmlException { PackagePartName shapePN = PackagingURIHelper.createPartName("/drs/shapexml.xml"); OPCPackage pkg = null; try { pkg = OPCPackage.open(new ByteArrayInputStream(metroBytes)); PackagePart shapePart = pkg.getPart(shapePN); CTGroupShape gs = CTGroupShape.Factory.parse(shapePart.getInputStream(), DEFAULT_XML_OPTIONS); XSLFGroupShape xgs = new XSLFGroupShape(gs, null); return xgs.getShapes().get(0); } finally { if (pkg != null) { pkg.close(); } } } }
@Override public XSLFGroupShape createGroup(){ XSLFGroupShape sh = getDrawing().createGroup(); _shapes.add(sh); sh.setParent(this); return sh; }
@Override public XSLFPictureShape createPicture(PictureData pictureData){ if (!(pictureData instanceof XSLFPictureData)) { throw new IllegalArgumentException("pictureData needs to be of type XSLFPictureData"); } RelationPart rp = getSheet().addRelation(null, XSLFRelation.IMAGES, (XSLFPictureData)pictureData); XSLFPictureShape sh = getDrawing().createPicture(rp.getRelationship().getId()); new DrawPictureShape(sh).resize(); _shapes.add(sh); sh.setParent(this); return sh; }
protected List<XSLFShape> buildShapes(CTGroupShape spTree){ List<XSLFShape> shapes = new ArrayList<XSLFShape>(); for(XmlObject ch : spTree.selectPath("*")){ if(ch instanceof CTShape){ // simple shape XSLFAutoShape shape = XSLFAutoShape.create((CTShape)ch, this); shapes.add(shape); } else if (ch instanceof CTGroupShape){ shapes.add(new XSLFGroupShape((CTGroupShape)ch, this)); } else if (ch instanceof CTConnector){ shapes.add(new XSLFConnectorShape((CTConnector)ch, this)); } else if (ch instanceof CTPicture){ shapes.add(new XSLFPictureShape((CTPicture)ch, this)); } else if (ch instanceof CTGraphicalObjectFrame){ XSLFGraphicFrame shape = XSLFGraphicFrame.create((CTGraphicalObjectFrame)ch, this); shapes.add(shape); } } return shapes; }