Search in sources :

Example 16 with CTPositiveSize2D

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

the class XSLFTableCell method getXfrm.

/**
     * Return a fake-xfrm which is used for calculating the text height
     */
protected CTTransform2D getXfrm() {
    Rectangle2D anc = getAnchor();
    CTTransform2D xfrm = CTTransform2D.Factory.newInstance();
    CTPoint2D off = xfrm.addNewOff();
    off.setX(Units.toEMU(anc.getX()));
    off.setY(Units.toEMU(anc.getY()));
    CTPositiveSize2D size = xfrm.addNewExt();
    size.setCx(Units.toEMU(anc.getWidth()));
    size.setCy(Units.toEMU(anc.getHeight()));
    return xfrm;
}
Also used : CTTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D) CTPoint2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D) Rectangle2D(java.awt.geom.Rectangle2D) CTPositiveSize2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D)

Example 17 with CTPositiveSize2D

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

the class XWPFRun method addPicture.

/**
     * Adds a picture to the run. This method handles
     * attaching the picture data to the overall file.
     *
     * @param pictureData The raw picture data
     * @param pictureType The type of the picture, eg {@link Document#PICTURE_TYPE_JPEG}
     * @param width       width in EMUs. To convert to / from points use {@link org.apache.poi.util.Units}
     * @param height      height in EMUs. To convert to / from points use {@link org.apache.poi.util.Units}
     * @throws org.apache.poi.openxml4j.exceptions.InvalidFormatException
     * @throws IOException
     * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_EMF
     * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_WMF
     * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_PICT
     * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_JPEG
     * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_PNG
     * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_DIB
     */
public XWPFPicture addPicture(InputStream pictureData, int pictureType, String filename, int width, int height) throws InvalidFormatException, IOException {
    String relationId;
    XWPFPictureData picData;
    // TODO Should we have an interface for this sort of thing?
    if (parent.getPart() instanceof XWPFHeaderFooter) {
        XWPFHeaderFooter headerFooter = (XWPFHeaderFooter) parent.getPart();
        relationId = headerFooter.addPictureData(pictureData, pictureType);
        picData = (XWPFPictureData) headerFooter.getRelationById(relationId);
    } else {
        @SuppressWarnings("resource") XWPFDocument doc = parent.getDocument();
        relationId = doc.addPictureData(pictureData, pictureType);
        picData = (XWPFPictureData) doc.getRelationById(relationId);
    }
    // Create the drawing entry for it
    try {
        CTDrawing drawing = run.addNewDrawing();
        CTInline inline = drawing.addNewInline();
        // Do the fiddly namespace bits on the inline
        // (We need full control of what goes where and as what)
        String xml = "<a:graphic xmlns:a=\"" + CTGraphicalObject.type.getName().getNamespaceURI() + "\">" + "<a:graphicData uri=\"" + CTPicture.type.getName().getNamespaceURI() + "\">" + "<pic:pic xmlns:pic=\"" + CTPicture.type.getName().getNamespaceURI() + "\" />" + "</a:graphicData>" + "</a:graphic>";
        InputSource is = new InputSource(new StringReader(xml));
        org.w3c.dom.Document doc = DocumentHelper.readDocument(is);
        inline.set(XmlToken.Factory.parse(doc.getDocumentElement(), DEFAULT_XML_OPTIONS));
        // Setup the inline
        inline.setDistT(0);
        inline.setDistR(0);
        inline.setDistB(0);
        inline.setDistL(0);
        CTNonVisualDrawingProps docPr = inline.addNewDocPr();
        long id = getParent().getDocument().getDrawingIdManager().reserveNew();
        docPr.setId(id);
        /* This name is not visible in Word 2010 anywhere. */
        docPr.setName("Drawing " + id);
        docPr.setDescr(filename);
        CTPositiveSize2D extent = inline.addNewExtent();
        extent.setCx(width);
        extent.setCy(height);
        // Grab the picture object
        CTGraphicalObject graphic = inline.getGraphic();
        CTGraphicalObjectData graphicData = graphic.getGraphicData();
        CTPicture pic = getCTPictures(graphicData).get(0);
        // Set it up
        CTPictureNonVisual nvPicPr = pic.addNewNvPicPr();
        CTNonVisualDrawingProps cNvPr = nvPicPr.addNewCNvPr();
        /* use "0" for the id. See ECM-576, 20.2.2.3 */
        cNvPr.setId(0L);
        /* This name is not visible in Word 2010 anywhere */
        cNvPr.setName("Picture " + id);
        cNvPr.setDescr(filename);
        CTNonVisualPictureProperties cNvPicPr = nvPicPr.addNewCNvPicPr();
        cNvPicPr.addNewPicLocks().setNoChangeAspect(true);
        CTBlipFillProperties blipFill = pic.addNewBlipFill();
        CTBlip blip = blipFill.addNewBlip();
        blip.setEmbed(parent.getPart().getRelationId(picData));
        blipFill.addNewStretch().addNewFillRect();
        CTShapeProperties spPr = pic.addNewSpPr();
        CTTransform2D xfrm = spPr.addNewXfrm();
        CTPoint2D off = xfrm.addNewOff();
        off.setX(0);
        off.setY(0);
        CTPositiveSize2D ext = xfrm.addNewExt();
        ext.setCx(width);
        ext.setCy(height);
        CTPresetGeometry2D prstGeom = spPr.addNewPrstGeom();
        prstGeom.setPrst(STShapeType.RECT);
        prstGeom.addNewAvLst();
        // Finish up
        XWPFPicture xwpfPicture = new XWPFPicture(pic, this);
        pictures.add(xwpfPicture);
        return xwpfPicture;
    } catch (XmlException e) {
        throw new IllegalStateException(e);
    } catch (SAXException e) {
        throw new IllegalStateException(e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) CTTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D) CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) XmlString(org.apache.xmlbeans.XmlString) SAXException(org.xml.sax.SAXException) CTPoint2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D) CTBlip(org.openxmlformats.schemas.drawingml.x2006.main.CTBlip) CTPresetGeometry2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D) StringReader(java.io.StringReader) CTPicture(org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture) CTGraphicalObject(org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObject) CTInline(org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline) CTDrawing(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDrawing) CTPictureNonVisual(org.openxmlformats.schemas.drawingml.x2006.picture.CTPictureNonVisual) CTGraphicalObjectData(org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData) CTNonVisualPictureProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualPictureProperties) CTBlipFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties) XmlException(org.apache.xmlbeans.XmlException) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTPositiveSize2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D)

Example 18 with CTPositiveSize2D

use of org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D 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 19 with CTPositiveSize2D

use of org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D 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 20 with CTPositiveSize2D

use of org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D 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

CTPositiveSize2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D)21 CTPoint2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D)18 CTTransform2D (org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D)11 CTNonVisualDrawingProps (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps)8 CTGroupTransform2D (org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D)7 CTPresetGeometry2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D)4 CTShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties)4 Dimension (java.awt.Dimension)2 CTBlipFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties)2 CTGroupShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTGroupShapeProperties)2 CTNonVisualPictureProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualPictureProperties)2 CTShape (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape)2 CTShapeNonVisual (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShapeNonVisual)2 CTInline (org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline)2 CTGraphicalObjectFrame (org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame)2 Rectangle2D (java.awt.geom.Rectangle2D)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 QName (javax.xml.namespace.QName)1