Search in sources :

Example 6 with CTShape

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape in project poi by apache.

the class XSSFDrawing method createTextbox.

/**
     * Constructs a textbox under the drawing.
     *
     * @param anchor    the client anchor describes how this group is attached
     *                  to the sheet.
     * @return      the newly created textbox.
     */
public XSSFTextBox createTextbox(XSSFClientAnchor anchor) {
    long shapeId = newShapeId();
    CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
    CTShape ctShape = ctAnchor.addNewSp();
    ctShape.set(XSSFSimpleShape.prototype());
    ctShape.getNvSpPr().getCNvPr().setId(shapeId);
    XSSFTextBox shape = new XSSFTextBox(this, ctShape);
    shape.anchor = anchor;
    return shape;
}
Also used : CTShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape) CTTwoCellAnchor(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor)

Example 7 with CTShape

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape in project poi by apache.

the class XSSFDrawing method addShapes.

private void addShapes(XmlCursor cur, List<XSSFShape> lst) {
    try {
        do {
            cur.push();
            if (cur.toFirstChild()) {
                do {
                    XmlObject obj = cur.getObject();
                    XSSFShape shape;
                    if (obj instanceof CTMarker) {
                        // ignore anchor elements
                        continue;
                    } else if (obj instanceof CTPicture) {
                        shape = new XSSFPicture(this, (CTPicture) obj);
                    } else if (obj instanceof CTConnector) {
                        shape = new XSSFConnector(this, (CTConnector) obj);
                    } else if (obj instanceof CTShape) {
                        shape = hasOleLink(obj) ? new XSSFObjectData(this, (CTShape) obj) : new XSSFSimpleShape(this, (CTShape) obj);
                    } else if (obj instanceof CTGraphicalObjectFrame) {
                        shape = new XSSFGraphicFrame(this, (CTGraphicalObjectFrame) obj);
                    } else if (obj instanceof CTGroupShape) {
                        shape = new XSSFShapeGroup(this, (CTGroupShape) obj);
                    } else if (obj instanceof XmlAnyTypeImpl) {
                        LOG.log(POILogger.WARN, "trying to parse AlternateContent, " + "this unlinks the returned Shapes from the underlying xml content, " + "so those shapes can't be used to modify the drawing, " + "i.e. modifications will be ignored!");
                        // XmlAnyTypeImpl is returned for AlternateContent parts, which might contain a CTDrawing
                        cur.push();
                        cur.toFirstChild();
                        XmlCursor cur2 = null;
                        try {
                            // need to parse AlternateContent again, otherwise the child elements aren't typed,
                            // but also XmlAnyTypes
                            CTDrawing alterWS = CTDrawing.Factory.parse(cur.newXMLStreamReader());
                            cur2 = alterWS.newCursor();
                            if (cur2.toFirstChild()) {
                                addShapes(cur2, lst);
                            }
                        } catch (XmlException e) {
                            LOG.log(POILogger.WARN, "unable to parse CTDrawing in alternate content.", e);
                        } finally {
                            if (cur2 != null) {
                                cur2.dispose();
                            }
                            cur.pop();
                        }
                        continue;
                    } else {
                        // ignore anything else
                        continue;
                    }
                    assert (shape != null);
                    shape.anchor = getAnchorFromParent(obj);
                    lst.add(shape);
                } while (cur.toNextSibling());
            }
            cur.pop();
        } while (cur.toNextSibling());
    } finally {
        cur.dispose();
    }
}
Also used : CTMarker(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker) CTConnector(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector) CTGraphicalObjectFrame(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrame) CTDrawing(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing) CTShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape) CTGroupShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape) XmlCursor(org.apache.xmlbeans.XmlCursor) XmlException(org.apache.xmlbeans.XmlException) CTPicture(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPicture) XmlAnyTypeImpl(org.apache.xmlbeans.impl.values.XmlAnyTypeImpl) XmlObject(org.apache.xmlbeans.XmlObject)

Example 8 with CTShape

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape in project poi by apache.

the class TestXSLFBugs method bug60662.

@Test
public void bug60662() throws IOException {
    XMLSlideShow src = new XMLSlideShow();
    XSLFSlide sl = src.createSlide();
    XSLFGroupShape gs = sl.createGroup();
    gs.setAnchor(new Rectangle2D.Double(100, 100, 100, 100));
    gs.setInteriorAnchor(new Rectangle2D.Double(0, 0, 100, 100));
    XSLFAutoShape as = gs.createAutoShape();
    as.setAnchor(new Rectangle2D.Double(0, 0, 100, 100));
    as.setShapeType(ShapeType.STAR_24);
    as.setFillColor(Color.YELLOW);
    CTShape csh = (CTShape) as.getXmlObject();
    CTOuterShadowEffect shadow = csh.getSpPr().addNewEffectLst().addNewOuterShdw();
    shadow.setDir(270000);
    shadow.setDist(100000);
    shadow.addNewSrgbClr().setVal(new byte[] { 0x00, (byte) 0xFF, 0x00 });
    XMLSlideShow dst = new XMLSlideShow();
    XSLFSlide sl2 = dst.createSlide();
    sl2.importContent(sl);
    XSLFGroupShape gs2 = (XSLFGroupShape) sl2.getShapes().get(0);
    XSLFAutoShape as2 = (XSLFAutoShape) gs2.getShapes().get(0);
    CTShape csh2 = (CTShape) as2.getXmlObject();
    assertTrue(csh2.getSpPr().isSetEffectLst());
    dst.close();
    src.close();
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) CTShape(org.openxmlformats.schemas.presentationml.x2006.main.CTShape) CTOuterShadowEffect(org.openxmlformats.schemas.drawingml.x2006.main.CTOuterShadowEffect) Test(org.junit.Test)

Example 9 with CTShape

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape 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 10 with CTShape

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape in project tika by apache.

the class XSSFBExcelExtractorDecorator method extractHyperLinksFromShape.

private void extractHyperLinksFromShape(CTShape ctShape, XHTMLContentHandler xhtml) throws SAXException {
    if (ctShape == null)
        return;
    CTShapeNonVisual nvSpPR = ctShape.getNvSpPr();
    if (nvSpPR == null)
        return;
    CTNonVisualDrawingProps cNvPr = nvSpPR.getCNvPr();
    if (cNvPr == null)
        return;
    CTHyperlink ctHyperlink = cNvPr.getHlinkClick();
    if (ctHyperlink == null)
        return;
    String url = drawingHyperlinks.get(ctHyperlink.getId());
    if (url != null) {
        xhtml.startElement("a", "href", url);
        xhtml.characters(url);
        xhtml.endElement("a");
    }
    CTHyperlink ctHoverHyperlink = cNvPr.getHlinkHover();
    if (ctHoverHyperlink == null)
        return;
    url = drawingHyperlinks.get(ctHoverHyperlink.getId());
    if (url != null) {
        xhtml.startElement("a", "href", url);
        xhtml.characters(url);
        xhtml.endElement("a");
    }
}
Also used : CTShapeNonVisual(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShapeNonVisual) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTHyperlink(org.openxmlformats.schemas.drawingml.x2006.main.CTHyperlink)

Aggregations

CTShape (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape)8 CTNonVisualDrawingProps (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps)6 CTTwoCellAnchor (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor)5 CTShape (org.openxmlformats.schemas.presentationml.x2006.main.CTShape)5 CTShapeNonVisual (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShapeNonVisual)4 PackageRelationship (org.apache.poi.openxml4j.opc.PackageRelationship)3 XmlCursor (org.apache.xmlbeans.XmlCursor)3 CTShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties)3 CTConnector (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector)3 CTPicture (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPicture)3 QName (javax.xml.namespace.QName)2 CTHyperlink (org.openxmlformats.schemas.drawingml.x2006.main.CTHyperlink)2 CTPresetGeometry2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D)2 CTTextBody (org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody)2 CTTransform2D (org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D)2 CTGroupShape (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape)2 CTShapeNonVisual (org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual)2 Rectangle2D (java.awt.geom.Rectangle2D)1 POIXMLException (org.apache.poi.POIXMLException)1 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)1