Search in sources :

Example 16 with CTNonVisualDrawingProps

use of org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps in project poi by apache.

the class XSSFConnector method prototype.

/**
     * Initialize default structure of a new auto-shape
     *
     */
protected static CTConnector prototype() {
    if (prototype == null) {
        CTConnector shape = CTConnector.Factory.newInstance();
        CTConnectorNonVisual nv = shape.addNewNvCxnSpPr();
        CTNonVisualDrawingProps nvp = nv.addNewCNvPr();
        nvp.setId(1);
        nvp.setName("Shape 1");
        nv.addNewCNvCxnSpPr();
        CTShapeProperties sp = shape.addNewSpPr();
        CTTransform2D t2d = sp.addNewXfrm();
        CTPositiveSize2D p1 = t2d.addNewExt();
        p1.setCx(0);
        p1.setCy(0);
        CTPoint2D p2 = t2d.addNewOff();
        p2.setX(0);
        p2.setY(0);
        CTPresetGeometry2D geom = sp.addNewPrstGeom();
        geom.setPrst(STShapeType.LINE);
        geom.addNewAvLst();
        CTShapeStyle style = shape.addNewStyle();
        CTSchemeColor scheme = style.addNewLnRef().addNewSchemeClr();
        scheme.setVal(STSchemeColorVal.ACCENT_1);
        style.getLnRef().setIdx(1);
        CTStyleMatrixReference fillref = style.addNewFillRef();
        fillref.setIdx(0);
        fillref.addNewSchemeClr().setVal(STSchemeColorVal.ACCENT_1);
        CTStyleMatrixReference effectRef = style.addNewEffectRef();
        effectRef.setIdx(0);
        effectRef.addNewSchemeClr().setVal(STSchemeColorVal.ACCENT_1);
        CTFontReference fontRef = style.addNewFontRef();
        fontRef.setIdx(STFontCollectionIndex.MINOR);
        fontRef.addNewSchemeClr().setVal(STSchemeColorVal.TX_1);
        prototype = shape;
    }
    return prototype;
}
Also used : CTTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D) CTPoint2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D) CTShapeStyle(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle) CTConnector(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector) CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) CTPresetGeometry2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTSchemeColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor) CTStyleMatrixReference(org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference) CTPositiveSize2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D) CTFontReference(org.openxmlformats.schemas.drawingml.x2006.main.CTFontReference) CTConnectorNonVisual(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnectorNonVisual)

Example 17 with CTNonVisualDrawingProps

use of org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps in project poi by apache.

the class XSSFDrawing method createObjectData.

@Override
public XSSFObjectData createObjectData(ClientAnchor anchor, int storageId, int pictureIndex) {
    XSSFSheet sh = getSheet();
    PackagePart sheetPart = sh.getPackagePart();
    /*
         * The shape id of the ole object seems to be a legacy shape id.
         * 
         * see 5.3.2.1 legacyDrawing (Legacy Drawing Object):
         * Legacy Shape ID that is unique throughout the entire document.
         * Legacy shape IDs should be assigned based on which portion of the document the
         * drawing resides on. The assignment of these ids is broken down into clusters of
         * 1024 values. The first cluster is 1-1024, the second 1025-2048 and so on.
         *
         * Ole shapes seem to start with 1025 on the first sheet ...
         * and not sure, if the ids need to be reindexed when sheets are removed
         * or more than 1024 shapes are on a given sheet (see #51332 for a similar issue)
         */
    XSSFSheet sheet = getSheet();
    XSSFWorkbook wb = sheet.getWorkbook();
    int sheetIndex = wb.getSheetIndex(sheet);
    long shapeId = (sheetIndex + 1) * 1024 + newShapeId();
    // add reference to OLE part
    PackagePartName olePN;
    try {
        olePN = PackagingURIHelper.createPartName("/xl/embeddings/oleObject" + storageId + ".bin");
    } catch (InvalidFormatException e) {
        throw new POIXMLException(e);
    }
    PackageRelationship olePR = sheetPart.addRelationship(olePN, TargetMode.INTERNAL, POIXMLDocument.OLE_OBJECT_REL_TYPE);
    // add reference to image part
    XSSFPictureData imgPD = sh.getWorkbook().getAllPictures().get(pictureIndex);
    PackagePartName imgPN = imgPD.getPackagePart().getPartName();
    PackageRelationship imgSheetPR = sheetPart.addRelationship(imgPN, TargetMode.INTERNAL, PackageRelationshipTypes.IMAGE_PART);
    PackageRelationship imgDrawPR = getPackagePart().addRelationship(imgPN, TargetMode.INTERNAL, PackageRelationshipTypes.IMAGE_PART);
    // add OLE part metadata to sheet
    CTWorksheet cwb = sh.getCTWorksheet();
    CTOleObjects oo = cwb.isSetOleObjects() ? cwb.getOleObjects() : cwb.addNewOleObjects();
    CTOleObject ole1 = oo.addNewOleObject();
    ole1.setProgId("Package");
    ole1.setShapeId(shapeId);
    ole1.setId(olePR.getId());
    XmlCursor cur1 = ole1.newCursor();
    cur1.toEndToken();
    cur1.beginElement("objectPr", XSSFRelation.NS_SPREADSHEETML);
    cur1.insertAttributeWithValue("id", PackageRelationshipTypes.CORE_PROPERTIES_ECMA376_NS, imgSheetPR.getId());
    cur1.insertAttributeWithValue("defaultSize", "0");
    cur1.beginElement("anchor", XSSFRelation.NS_SPREADSHEETML);
    cur1.insertAttributeWithValue("moveWithCells", "1");
    CTTwoCellAnchor ctAnchor = createTwoCellAnchor((XSSFClientAnchor) anchor);
    XmlCursor cur2 = ctAnchor.newCursor();
    cur2.copyXmlContents(cur1);
    cur2.dispose();
    cur1.toParent();
    cur1.toFirstChild();
    cur1.setName(new QName(XSSFRelation.NS_SPREADSHEETML, "from"));
    cur1.toNextSibling();
    cur1.setName(new QName(XSSFRelation.NS_SPREADSHEETML, "to"));
    cur1.dispose();
    // add a new shape and link OLE & image part
    CTShape ctShape = ctAnchor.addNewSp();
    ctShape.set(XSSFObjectData.prototype());
    ctShape.getSpPr().setXfrm(createXfrm((XSSFClientAnchor) anchor));
    // workaround for not having the vmlDrawing filled
    CTBlipFillProperties blipFill = ctShape.getSpPr().addNewBlipFill();
    blipFill.addNewBlip().setEmbed(imgDrawPR.getId());
    blipFill.addNewStretch().addNewFillRect();
    CTNonVisualDrawingProps cNvPr = ctShape.getNvSpPr().getCNvPr();
    cNvPr.setId(shapeId);
    cNvPr.setName("Object " + shapeId);
    XmlCursor extCur = cNvPr.getExtLst().getExtArray(0).newCursor();
    extCur.toFirstChild();
    extCur.setAttributeText(new QName("spid"), "_x0000_s" + shapeId);
    extCur.dispose();
    XSSFObjectData shape = new XSSFObjectData(this, ctShape);
    shape.anchor = (XSSFClientAnchor) anchor;
    return shape;
}
Also used : PackagePartName(org.apache.poi.openxml4j.opc.PackagePartName) QName(javax.xml.namespace.QName) CTWorksheet(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet) CTOleObjects(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTOleObjects) CTShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape) POIXMLException(org.apache.poi.POIXMLException) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) XmlCursor(org.apache.xmlbeans.XmlCursor) PackageRelationship(org.apache.poi.openxml4j.opc.PackageRelationship) CTBlipFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTOleObject(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTOleObject) CTTwoCellAnchor(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor)

Example 18 with CTNonVisualDrawingProps

use of org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps in project poi by apache.

the class XSSFObjectData method prototype.

/**
     * Prototype with the default structure of a new auto-shape.
     */
/**
     * Prototype with the default structure of a new auto-shape.
     */
protected static CTShape prototype() {
    final String drawNS = "http://schemas.microsoft.com/office/drawing/2010/main";
    if (prototype == null) {
        CTShape shape = CTShape.Factory.newInstance();
        CTShapeNonVisual nv = shape.addNewNvSpPr();
        CTNonVisualDrawingProps nvp = nv.addNewCNvPr();
        nvp.setId(1);
        nvp.setName("Shape 1");
        //            nvp.setHidden(true);
        CTOfficeArtExtensionList extLst = nvp.addNewExtLst();
        // https://msdn.microsoft.com/en-us/library/dd911027(v=office.12).aspx
        CTOfficeArtExtension ext = extLst.addNewExt();
        ext.setUri("{63B3BB69-23CF-44E3-9099-C40C66FF867C}");
        XmlCursor cur = ext.newCursor();
        cur.toEndToken();
        cur.beginElement(new QName(drawNS, "compatExt", "a14"));
        cur.insertNamespace("a14", drawNS);
        cur.insertAttributeWithValue("spid", "_x0000_s1");
        cur.dispose();
        nv.addNewCNvSpPr();
        CTShapeProperties sp = shape.addNewSpPr();
        CTTransform2D t2d = sp.addNewXfrm();
        CTPositiveSize2D p1 = t2d.addNewExt();
        p1.setCx(0);
        p1.setCy(0);
        CTPoint2D p2 = t2d.addNewOff();
        p2.setX(0);
        p2.setY(0);
        CTPresetGeometry2D geom = sp.addNewPrstGeom();
        geom.setPrst(STShapeType.RECT);
        geom.addNewAvLst();
        prototype = shape;
    }
    return prototype;
}
Also used : CTTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D) CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) QName(javax.xml.namespace.QName) CTShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape) XmlCursor(org.apache.xmlbeans.XmlCursor) CTPoint2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D) CTShapeNonVisual(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShapeNonVisual) CTPresetGeometry2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTOfficeArtExtension(org.openxmlformats.schemas.drawingml.x2006.main.CTOfficeArtExtension) CTPositiveSize2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D) CTOfficeArtExtensionList(org.openxmlformats.schemas.drawingml.x2006.main.CTOfficeArtExtensionList)

Example 19 with CTNonVisualDrawingProps

use of org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps in project Gargoyle by callakrsos.

the class MSWord method addPicture.

/**
	 * 사진추가.
	 *
	 * @param imgFile
	 * @param id
	 * @param width
	 * @param height
	 * @param run
	 */
public void addPicture(final String imgFile, final int id, int width, int height, final XWPFRun run) {
    FileInputStream fileInputStream = null;
    try {
        fileInputStream = new FileInputStream(imgFile);
        final String blipId = run.getDocument().addPictureData(fileInputStream, Document.PICTURE_TYPE_JPEG);
        final int EMU = 9525;
        width *= EMU;
        height *= EMU;
        // String blipId =
        // getAllPictures().get(id).getPackageRelationship().getId();
        final CTInline inline = run.getCTR().addNewDrawing().addNewInline();
        final String picXml = "" + "<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">" + "   <a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">" + "      <pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">" + "         <pic:nvPicPr>" + "            <pic:cNvPr id=\"" + id + "\" name=\"Generated\"/>" + "            <pic:cNvPicPr/>" + "         </pic:nvPicPr>" + "         <pic:blipFill>" + "            <a:blip r:embed=\"" + blipId + "\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"/>" + "            <a:stretch>" + "               <a:fillRect/>" + "            </a:stretch>" + "         </pic:blipFill>" + "         <pic:spPr>" + "            <a:xfrm>" + "               <a:off x=\"0\" y=\"0\"/>" + "               <a:ext cx=\"" + width + "\" cy=\"" + height + "\"/>" + "            </a:xfrm>" + "            <a:prstGeom prst=\"rect\">" + "               <a:avLst/>" + "            </a:prstGeom>" + "         </pic:spPr>" + "      </pic:pic>" + "   </a:graphicData>" + "</a:graphic>";
        XmlToken xmlToken = null;
        xmlToken = XmlToken.Factory.parse(picXml);
        inline.set(xmlToken);
        inline.setDistT(0);
        inline.setDistB(0);
        inline.setDistL(0);
        inline.setDistR(0);
        final CTPositiveSize2D extent = inline.addNewExtent();
        extent.setCx(width);
        extent.setCy(height);
        final CTNonVisualDrawingProps docPr = inline.addNewDocPr();
        docPr.setId(id);
        docPr.setName("Picture " + id);
        docPr.setDescr("Generated");
    } catch (final Exception e) {
        e.printStackTrace();
    } finally {
        // close streams
        if (fileInputStream != null) {
            try {
                fileInputStream.close();
            } catch (final IOException ioEx) {
            // can be ignored
            }
        }
    }
}
Also used : CTInline(org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTString(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTString) IOException(java.io.IOException) CTPositiveSize2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) XmlToken(org.apache.xmlbeans.XmlToken)

Aggregations

CTNonVisualDrawingProps (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps)18 CTPositiveSize2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D)8 CTShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties)8 CTPoint2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D)7 CTPresetGeometry2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D)7 CTTransform2D (org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D)5 CTBlipFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties)4 QName (javax.xml.namespace.QName)3 XmlCursor (org.apache.xmlbeans.XmlCursor)3 CTShape (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape)3 CTShapeNonVisual (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShapeNonVisual)3 CTBlip (org.openxmlformats.schemas.drawingml.x2006.main.CTBlip)2 CTGraphicalObjectData (org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData)2 CTGroupShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTGroupShapeProperties)2 CTGroupTransform2D (org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D)2 CTHyperlink (org.openxmlformats.schemas.drawingml.x2006.main.CTHyperlink)2 CTNonVisualPictureProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualPictureProperties)2 CTInline (org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline)2 CTGroupShape (org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)2 CTGroupShapeNonVisual (org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShapeNonVisual)2