Search in sources :

Example 6 with CTPicture

use of org.openxmlformats.schemas.presentationml.x2006.main.CTPicture in project poi by apache.

the class XSLFSheet method appendContent.

/**
     * Append content to this sheet.
     *
     * @param src the source sheet
     * @return modified <code>this</code>.
     */
public XSLFSheet appendContent(XSLFSheet src) {
    CTGroupShape spTree = getSpTree();
    int numShapes = getShapes().size();
    CTGroupShape srcTree = src.getSpTree();
    for (XmlObject ch : srcTree.selectPath("*")) {
        if (ch instanceof CTShape) {
            // simple shape
            spTree.addNewSp().set(ch);
        } else if (ch instanceof CTGroupShape) {
            spTree.addNewGrpSp().set(ch);
        } else if (ch instanceof CTConnector) {
            spTree.addNewCxnSp().set(ch);
        } else if (ch instanceof CTPicture) {
            spTree.addNewPic().set(ch);
        } else if (ch instanceof CTGraphicalObjectFrame) {
            spTree.addNewGraphicFrame().set(ch);
        }
    }
    _shapes = null;
    _spTree = null;
    _drawing = null;
    _spTree = null;
    _placeholders = null;
    // recursively update each shape
    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(numShapes + i);
        s2.copy(s1);
    }
    return this;
}
Also used : CTConnector(org.openxmlformats.schemas.presentationml.x2006.main.CTConnector) CTGraphicalObjectFrame(org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame) CTPicture(org.openxmlformats.schemas.presentationml.x2006.main.CTPicture) XmlObject(org.apache.xmlbeans.XmlObject) CTShape(org.openxmlformats.schemas.presentationml.x2006.main.CTShape) CTGroupShape(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)

Example 7 with CTPicture

use of org.openxmlformats.schemas.presentationml.x2006.main.CTPicture in project poi by apache.

the class XSLFPictureShape method copy.

@Override
void copy(XSLFShape sh) {
    super.copy(sh);
    XSLFPictureShape p = (XSLFPictureShape) sh;
    String blipId = p.getBlipId();
    String relId = getSheet().importBlip(blipId, p.getSheet().getPackagePart());
    CTPicture ct = (CTPicture) getXmlObject();
    CTBlip blip = getBlipFill().getBlip();
    blip.setEmbed(relId);
    CTApplicationNonVisualDrawingProps nvPr = ct.getNvPicPr().getNvPr();
    if (nvPr.isSetCustDataLst()) {
        // discard any custom tags associated with the picture being copied
        nvPr.unsetCustDataLst();
    }
    if (blip.isSetExtLst()) {
        CTOfficeArtExtensionList extLst = blip.getExtLst();
        for (CTOfficeArtExtension ext : extLst.getExtArray()) {
            String xpath = "declare namespace a14='http://schemas.microsoft.com/office/drawing/2010/main' $this//a14:imgProps/a14:imgLayer";
            XmlObject[] obj = ext.selectPath(xpath);
            if (obj != null && obj.length == 1) {
                XmlCursor c = obj[0].newCursor();
                //selectPath("declare namespace r='http://schemas.openxmlformats.org/officeDocument/2006/relationships' $this//[@embed]");
                String id = c.getAttributeText(new QName("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "embed"));
                String newId = getSheet().importBlip(id, p.getSheet().getPackagePart());
                c.setAttributeText(new QName("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "embed"), newId);
                c.dispose();
            }
        }
    }
}
Also used : CTBlip(org.openxmlformats.schemas.drawingml.x2006.main.CTBlip) QName(javax.xml.namespace.QName) CTPicture(org.openxmlformats.schemas.presentationml.x2006.main.CTPicture) CTApplicationNonVisualDrawingProps(org.openxmlformats.schemas.presentationml.x2006.main.CTApplicationNonVisualDrawingProps) CTOfficeArtExtension(org.openxmlformats.schemas.drawingml.x2006.main.CTOfficeArtExtension) XmlObject(org.apache.xmlbeans.XmlObject) CTOfficeArtExtensionList(org.openxmlformats.schemas.drawingml.x2006.main.CTOfficeArtExtensionList) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 8 with CTPicture

use of org.openxmlformats.schemas.presentationml.x2006.main.CTPicture in project poi by apache.

the class XSLFPictureShape method prototype.

/**
     * @param shapeId 1-based shapeId
     * @param rel     relationship to the picture data in the ooxml package
     */
static CTPicture prototype(int shapeId, String rel) {
    CTPicture ct = CTPicture.Factory.newInstance();
    CTPictureNonVisual nvSpPr = ct.addNewNvPicPr();
    CTNonVisualDrawingProps cnv = nvSpPr.addNewCNvPr();
    cnv.setName("Picture " + shapeId);
    cnv.setId(shapeId + 1);
    nvSpPr.addNewCNvPicPr().addNewPicLocks().setNoChangeAspect(true);
    nvSpPr.addNewNvPr();
    CTBlipFillProperties blipFill = ct.addNewBlipFill();
    CTBlip blip = blipFill.addNewBlip();
    blip.setEmbed(rel);
    blipFill.addNewStretch().addNewFillRect();
    CTShapeProperties spPr = ct.addNewSpPr();
    CTPresetGeometry2D prst = spPr.addNewPrstGeom();
    prst.setPrst(STShapeType.RECT);
    prst.addNewAvLst();
    return ct;
}
Also used : CTBlipFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties) CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) CTBlip(org.openxmlformats.schemas.drawingml.x2006.main.CTBlip) CTPresetGeometry2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTPicture(org.openxmlformats.schemas.presentationml.x2006.main.CTPicture) CTPictureNonVisual(org.openxmlformats.schemas.presentationml.x2006.main.CTPictureNonVisual)

Example 9 with CTPicture

use of org.openxmlformats.schemas.presentationml.x2006.main.CTPicture in project poi by apache.

the class XSLFDrawing method createPicture.

public XSLFPictureShape createPicture(String rel) {
    CTPicture obj = _spTree.addNewPic();
    obj.set(XSLFPictureShape.prototype(_shapeId++, rel));
    XSLFPictureShape shape = new XSLFPictureShape(obj, _sheet);
    shape.setAnchor(new Rectangle2D.Double());
    return shape;
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) CTPicture(org.openxmlformats.schemas.presentationml.x2006.main.CTPicture)

Example 10 with CTPicture

use of org.openxmlformats.schemas.presentationml.x2006.main.CTPicture in project poi by apache.

the class XSLFGroupShape method removeShape.

/**
     * Remove the specified shape from this group
     */
@Override
public boolean removeShape(XSLFShape xShape) {
    XmlObject obj = xShape.getXmlObject();
    CTGroupShape grpSp = (CTGroupShape) getXmlObject();
    if (obj instanceof CTShape) {
        grpSp.getSpList().remove(obj);
    } else if (obj instanceof CTGroupShape) {
        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);
}
Also used : CTConnector(org.openxmlformats.schemas.presentationml.x2006.main.CTConnector) CTGraphicalObjectFrame(org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame) CTPicture(org.openxmlformats.schemas.presentationml.x2006.main.CTPicture) XmlObject(org.apache.xmlbeans.XmlObject) CTShape(org.openxmlformats.schemas.presentationml.x2006.main.CTShape) CTGroupShape(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)

Aggregations

CTPicture (org.openxmlformats.schemas.presentationml.x2006.main.CTPicture)10 XmlObject (org.apache.xmlbeans.XmlObject)7 CTConnector (org.openxmlformats.schemas.presentationml.x2006.main.CTConnector)4 CTGraphicalObjectFrame (org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame)4 CTGroupShape (org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)4 CTShape (org.openxmlformats.schemas.presentationml.x2006.main.CTShape)4 QName (javax.xml.namespace.QName)2 CTBlip (org.openxmlformats.schemas.drawingml.x2006.main.CTBlip)2 CTBlipFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties)2 CTLock (com.microsoft.schemas.office.office.CTLock)1 CTFormulas (com.microsoft.schemas.vml.CTFormulas)1 CTGroup (com.microsoft.schemas.vml.CTGroup)1 CTH (com.microsoft.schemas.vml.CTH)1 CTHandles (com.microsoft.schemas.vml.CTHandles)1 CTPath (com.microsoft.schemas.vml.CTPath)1 CTShape (com.microsoft.schemas.vml.CTShape)1 CTShapetype (com.microsoft.schemas.vml.CTShapetype)1 CTTextPath (com.microsoft.schemas.vml.CTTextPath)1 Rectangle2D (java.awt.geom.Rectangle2D)1 ArrayList (java.util.ArrayList)1