/** * As there's no xmlbeans hierarchy, but XSLF works with subclassing, not all * child classes work with a {@link CTShape} object, but often contain the same * properties. This method is the generalized form of selecting and casting those * properties. * * @param resultClass the requested result class * @param xquery the simple (xmlbean) xpath expression to the property * @return the xml object at the xpath location, or null if not found */ @SuppressWarnings({"unchecked", "WeakerAccess"}) protected <T extends XmlObject> T selectProperty(Class<T> resultClass, String xquery) { XmlObject[] rs = getXmlObject().selectPath(xquery); if (rs.length == 0) { return null; } return (resultClass.isInstance(rs[0])) ? (T)rs[0] : null; }
/** * Set the contents of this shape to be a copy of the source shape. * This method is called recursively for each shape when merging slides * * @param sh the source shape * @see org.apache.poi.xslf.usermodel.XSLFSlide#importContent(XSLFSheet) */ @Internal void copy(XSLFShape sh) { if (!getClass().isInstance(sh)) { throw new IllegalArgumentException( "Can't copy " + sh.getClass().getSimpleName() + " into " + getClass().getSimpleName()); } if (this instanceof PlaceableShape) { PlaceableShape<?,?> ps = (PlaceableShape<?,?>)this; ps.setAnchor(sh.getAnchor()); } }
private void wipeAndReinitialize(XSLFSheet src, int offset) { // explicitly initialize drawing and shapes from _spTree _shapes = null; _drawing = null; initDrawingAndShapes(); // placeholders will be implicitly initialized when requested _placeholders = null; // update each shape according to its own additional copy rules List<XSLFShape> tgtShapes = getShapes(); List<XSLFShape> srcShapes = src.getShapes(); for(int i = 0; i < srcShapes.size(); i++){ XSLFShape s1 = srcShapes.get(i); XSLFShape s2 = tgtShapes.get(offset + i); s2.copy(s1); } }
protected PaintStyle getFillPaint() { final XSLFTheme theme = getSheet().getTheme(); final boolean hasPlaceholder = getPlaceholder() != null; PropertyFetcher<PaintStyle> fetcher = new PropertyFetcher<PaintStyle>() { @Override fetchShapeProperty(fetcher);
XmlObject obj = xShape.getXmlObject(); CTGroupShape spTree = getSpTree(); deregisterShapeId(xShape.getShapeId()); if(obj instanceof CTShape){ spTree.getSpList().remove(obj);
Rectangle2D anchor = getAnchor(); AffineTransform tx = (AffineTransform)graphics.getRenderingHint(XSLFRenderingHint.GROUP_TRANSFORM); if(tx != null) { double rotation = getRotation(); if (rotation != 0.) { if (getFlipHorizontal()) { graphics.translate(anchor.getX() + anchor.getWidth(), anchor.getY()); graphics.scale(-1, 1); if (getFlipVertical()) { graphics.translate(anchor.getX(), anchor.getY() + anchor.getHeight()); graphics.scale(1, -1);
final CTPlaceholder ph = getPlaceholderDetails().getCTPlaceholder(false); if (ph == null) { return false; MasterSheet<XSLFShape,XSLFTextParagraph> sm = getSheet().getMasterSheet(); int textType = getPlaceholderType(ph); XSLFSimpleShape masterShape = master.getPlaceholderByType(textType); return masterShape != null && visitor.fetch(masterShape);
/** * Set the contents of this shape to be a copy of the source shape. * This method is called recursively for each shape when merging slides * * @param sh the source shape * @see org.apache.poi.xslf.usermodel.XSLFSlide#importContent(XSLFSheet) */ @Internal void copy(XSLFShape sh) { if (!getClass().isInstance(sh)) { throw new IllegalArgumentException( "Can't copy " + sh.getClass().getSimpleName() + " into " + getClass().getSimpleName()); } setAnchor(sh.getAnchor()); } }
@SuppressWarnings("WeakerAccess") protected CTShapeStyle getSpStyle() { if (_spStyle == null) { _spStyle = getChild(CTShapeStyle.class, PML_NS, "style"); } return _spStyle; }
/** * @see PlaceholderDetails#setPlaceholder(Placeholder) */ public void setPlaceholder(final Placeholder placeholder) { getPlaceholderDetails().setPlaceholder(placeholder); }
@Override public String getShapeName(){ return getCNvPr().getName(); }
/** * 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); }
protected PaintStyle getFillPaint() { final XSLFTheme theme = getSheet().getTheme(); final boolean hasPlaceholder = getPlaceholder() != null; PropertyFetcher<PaintStyle> fetcher = new PropertyFetcher<PaintStyle>() { @Override fetchShapeProperty(fetcher);
final CTPlaceholder ph = getPlaceholderDetails().getCTPlaceholder(false); if (ph == null) { return false; MasterSheet<XSLFShape,XSLFTextParagraph> sm = getSheet().getMasterSheet(); int textType = getPlaceholderType(ph); XSLFSimpleShape masterShape = master.getPlaceholderByType(textType); return masterShape != null && visitor.fetch(masterShape);
/** * Return the shape specific (visual) properties * * @return the shape specific properties */ protected XmlObject getShapeProperties() { return getChild(CTShapeProperties.class, PML_NS, "spPr"); } }
/** * @see PlaceholderDetails#getPlaceholder() */ public Placeholder getPlaceholder() { return getPlaceholderDetails().getPlaceholder(); }
@Override public int getShapeId() { return (int)getCNvPr().getId(); }
public boolean fetch(XSLFShape shape) { XmlObject[] o = shape.getXmlObject().selectPath( "declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' " + "declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' " + ".//p:txBody/a:lstStyle/a:lvl" + (_level + 1) + "pPr" ); if (o.length == 1) { CTTextParagraphProperties props = (CTTextParagraphProperties) o[0]; return fetch(props); } return false; }
XmlObject obj = xShape.getXmlObject(); CTGroupShape spTree = getSpTree(); deregisterShapeId(xShape.getShapeId()); if(obj instanceof CTShape){ spTree.getSpList().remove(obj);
@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); } if(uri.equals("http://schemas.openxmlformats.org/drawingml/2006/chart")){ copyChart(data, (XSLFGraphicFrame)sh); } else { // TODO support other types of objects } }