Search in sources :

Example 11 with CTShapeProperties

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

the class TestXSLFSimpleShape method testValidGeometry.

@Test
public void testValidGeometry() throws Exception {
    XMLSlideShow ppt = new XMLSlideShow();
    XSLFSlide slide = ppt.createSlide();
    XSLFSimpleShape shape = slide.createAutoShape();
    CTShapeProperties spPr = getSpPr(shape);
    CTPresetGeometry2D prstGeom = CTPresetGeometry2D.Factory.newInstance();
    prstGeom.setPrst(STShapeType.Enum.forInt(1));
    assertNotNull(prstGeom.getPrst());
    assertNotNull(prstGeom.getPrst().toString());
    assertNotNull(spPr.getPrstGeom());
    spPr.setPrstGeom(prstGeom);
    assertNotNull(spPr.getPrstGeom().getPrst());
    assertNotNull(spPr.getPrstGeom().getPrst().toString());
    assertNotNull(shape.getGeometry());
    ppt.close();
}
Also used : CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) CTPresetGeometry2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D) Test(org.junit.Test)

Example 12 with CTShapeProperties

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

the class TestXSLFSimpleShape method getSpPr.

static CTShapeProperties getSpPr(XSLFShape shape) {
    XmlObject xo = shape.getShapeProperties();
    assertTrue(xo instanceof CTShapeProperties);
    return (CTShapeProperties) xo;
}
Also used : CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) XmlObject(org.apache.xmlbeans.XmlObject)

Example 13 with CTShapeProperties

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

the class XSSFSimpleShape method prototype.

/**
     * Prototype with the default structure of a new auto-shape.
     */
protected static CTShape prototype() {
    if (prototype == null) {
        CTShape shape = CTShape.Factory.newInstance();
        CTShapeNonVisual nv = shape.addNewNvSpPr();
        CTNonVisualDrawingProps nvp = nv.addNewCNvPr();
        nvp.setId(1);
        nvp.setName("Shape 1");
        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();
        CTTextBody body = shape.addNewTxBody();
        CTTextBodyProperties bodypr = body.addNewBodyPr();
        bodypr.setAnchor(STTextAnchoringType.T);
        bodypr.setRtlCol(false);
        CTTextParagraph p = body.addNewP();
        p.addNewPPr().setAlgn(STTextAlignType.L);
        CTTextCharacterProperties endPr = p.addNewEndParaRPr();
        endPr.setLang("en-US");
        endPr.setSz(1100);
        CTSolidColorFillProperties scfpr = endPr.addNewSolidFill();
        scfpr.addNewSrgbClr().setVal(new byte[] { 0, 0, 0 });
        body.addNewLstStyle();
        prototype = shape;
    }
    return prototype;
}
Also used : CTShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape) CTShapeNonVisual(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShapeNonVisual)

Example 14 with CTShapeProperties

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

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

the class XSLFSimpleShape method getXfrm.

protected CTTransform2D getXfrm(boolean create) {
    PropertyFetcher<CTTransform2D> fetcher = new PropertyFetcher<CTTransform2D>() {

        @Override
        public boolean fetch(XSLFShape shape) {
            XmlObject xo = shape.getShapeProperties();
            if (xo instanceof CTShapeProperties && ((CTShapeProperties) xo).isSetXfrm()) {
                setValue(((CTShapeProperties) xo).getXfrm());
                return true;
            }
            return false;
        }
    };
    fetchShapeProperty(fetcher);
    CTTransform2D xfrm = fetcher.getValue();
    if (!create || xfrm != null) {
        return xfrm;
    } else {
        XmlObject xo = getShapeProperties();
        if (xo instanceof CTShapeProperties) {
            return ((CTShapeProperties) xo).addNewXfrm();
        } else {
            // ... group shapes have their own getXfrm()
            LOG.log(POILogger.WARN, getClass() + " doesn't have xfrm element.");
            return null;
        }
    }
}
Also used : CTTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D) CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) PropertyFetcher(org.apache.poi.xslf.model.PropertyFetcher) XmlObject(org.apache.xmlbeans.XmlObject)

Aggregations

CTShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties)21 CTPresetGeometry2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D)9 CTNonVisualDrawingProps (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps)8 XmlObject (org.apache.xmlbeans.XmlObject)6 CTTransform2D (org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D)5 CTBlipFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties)4 CTLineProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties)4 CTPoint2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D)4 CTPositiveSize2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D)4 AffineTransform (java.awt.geom.AffineTransform)2 Rectangle2D (java.awt.geom.Rectangle2D)2 Test (org.junit.Test)2 CTAdjPoint2D (org.openxmlformats.schemas.drawingml.x2006.main.CTAdjPoint2D)2 CTBlip (org.openxmlformats.schemas.drawingml.x2006.main.CTBlip)2 CTCustomGeometry2D (org.openxmlformats.schemas.drawingml.x2006.main.CTCustomGeometry2D)2 CTNonVisualPictureProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualPictureProperties)2 CTPath2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPath2D)2 CTPath2DCubicBezierTo (org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DCubicBezierTo)2 CTPath2DQuadBezierTo (org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DQuadBezierTo)2 CTSRgbColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor)2