use of org.openxmlformats.schemas.presentationml.x2006.main.CTPicture in project poi by apache.
the class XSLFSheet method removeShape.
/**
* Removes the specified shape from this sheet, if it is present
* (optional operation). If this sheet does not contain the element,
* it is unchanged.
*
* @param xShape shape to be removed from this sheet, if present
* @return <tt>true</tt> if this sheet contained the specified element
* @throws IllegalArgumentException if the type of the specified shape
* is incompatible with this sheet (optional)
*/
public boolean removeShape(XSLFShape xShape) {
XmlObject obj = xShape.getXmlObject();
CTGroupShape spTree = getSpTree();
if (obj instanceof CTShape) {
spTree.getSpList().remove(obj);
} else if (obj instanceof CTGroupShape) {
spTree.getGrpSpList().remove(obj);
} else if (obj instanceof CTConnector) {
spTree.getCxnSpList().remove(obj);
} else if (obj instanceof CTGraphicalObjectFrame) {
spTree.getGraphicFrameList().remove(obj);
} else if (obj instanceof CTPicture) {
XSLFPictureShape ps = (XSLFPictureShape) xShape;
removePictureRelation(ps);
spTree.getPicList().remove(obj);
} else {
throw new IllegalArgumentException("Unsupported shape: " + xShape);
}
return getShapes().remove(xShape);
}
use of org.openxmlformats.schemas.presentationml.x2006.main.CTPicture in project poi by apache.
the class XSLFSheet method buildShapes.
protected static List<XSLFShape> buildShapes(CTGroupShape spTree, XSLFSheet sheet) {
List<XSLFShape> shapes = new ArrayList<XSLFShape>();
for (XmlObject ch : spTree.selectPath("*")) {
if (ch instanceof CTShape) {
// simple shape
XSLFAutoShape shape = XSLFAutoShape.create((CTShape) ch, sheet);
shapes.add(shape);
} else if (ch instanceof CTGroupShape) {
shapes.add(new XSLFGroupShape((CTGroupShape) ch, sheet));
} else if (ch instanceof CTConnector) {
shapes.add(new XSLFConnectorShape((CTConnector) ch, sheet));
} else if (ch instanceof CTPicture) {
shapes.add(new XSLFPictureShape((CTPicture) ch, sheet));
} else if (ch instanceof CTGraphicalObjectFrame) {
XSLFGraphicFrame shape = XSLFGraphicFrame.create((CTGraphicalObjectFrame) ch, sheet);
shapes.add(shape);
}
}
return shapes;
}
use of org.openxmlformats.schemas.presentationml.x2006.main.CTPicture in project poi by apache.
the class TestXSLFPictureShape method testMerge.
@Test
public void testMerge() throws Exception {
XMLSlideShow ppt1 = new XMLSlideShow();
byte[] data1 = new byte[100];
XSLFPictureData pdata1 = ppt1.addPicture(data1, PictureType.JPEG);
XSLFSlide slide1 = ppt1.createSlide();
XSLFPictureShape shape1 = slide1.createPicture(pdata1);
CTPicture ctPic1 = (CTPicture) shape1.getXmlObject();
ctPic1.getNvPicPr().getNvPr().addNewCustDataLst().addNewTags().setId("rId99");
XMLSlideShow ppt2 = new XMLSlideShow();
XSLFSlide slide2 = ppt2.createSlide().importContent(slide1);
XSLFPictureShape shape2 = (XSLFPictureShape) slide2.getShapes().get(0);
assertArrayEquals(data1, shape2.getPictureData().getData());
CTPicture ctPic2 = (CTPicture) shape2.getXmlObject();
assertFalse(ctPic2.getNvPicPr().getNvPr().isSetCustDataLst());
ppt1.close();
ppt2.close();
}
use of org.openxmlformats.schemas.presentationml.x2006.main.CTPicture in project poi by apache.
the class XWPFHeaderFooterPolicy method getWatermarkParagraph.
/*
* This is the default Watermark paragraph; the only variable is the text message
* TODO: manage all the other variables
*/
private XWPFParagraph getWatermarkParagraph(String text, int idx) {
CTP p = CTP.Factory.newInstance();
byte[] rsidr = doc.getDocument().getBody().getPArray(0).getRsidR();
byte[] rsidrdefault = doc.getDocument().getBody().getPArray(0).getRsidRDefault();
p.setRsidP(rsidr);
p.setRsidRDefault(rsidrdefault);
CTPPr pPr = p.addNewPPr();
pPr.addNewPStyle().setVal("Header");
// start watermark paragraph
CTR r = p.addNewR();
CTRPr rPr = r.addNewRPr();
rPr.addNewNoProof();
CTPicture pict = r.addNewPict();
CTGroup group = CTGroup.Factory.newInstance();
CTShapetype shapetype = group.addNewShapetype();
shapetype.setId("_x0000_t136");
shapetype.setCoordsize("1600,21600");
shapetype.setSpt(136);
shapetype.setAdj("10800");
shapetype.setPath2("m@7,0l@8,0m@5,21600l@6,21600e");
CTFormulas formulas = shapetype.addNewFormulas();
formulas.addNewF().setEqn("sum #0 0 10800");
formulas.addNewF().setEqn("prod #0 2 1");
formulas.addNewF().setEqn("sum 21600 0 @1");
formulas.addNewF().setEqn("sum 0 0 @2");
formulas.addNewF().setEqn("sum 21600 0 @3");
formulas.addNewF().setEqn("if @0 @3 0");
formulas.addNewF().setEqn("if @0 21600 @1");
formulas.addNewF().setEqn("if @0 0 @2");
formulas.addNewF().setEqn("if @0 @4 21600");
formulas.addNewF().setEqn("mid @5 @6");
formulas.addNewF().setEqn("mid @8 @5");
formulas.addNewF().setEqn("mid @7 @8");
formulas.addNewF().setEqn("mid @6 @7");
formulas.addNewF().setEqn("sum @6 0 @5");
CTPath path = shapetype.addNewPath();
path.setTextpathok(STTrueFalse.T);
path.setConnecttype(STConnectType.CUSTOM);
path.setConnectlocs("@9,0;@10,10800;@11,21600;@12,10800");
path.setConnectangles("270,180,90,0");
CTTextPath shapeTypeTextPath = shapetype.addNewTextpath();
shapeTypeTextPath.setOn(STTrueFalse.T);
shapeTypeTextPath.setFitshape(STTrueFalse.T);
CTHandles handles = shapetype.addNewHandles();
CTH h = handles.addNewH();
h.setPosition("#0,bottomRight");
h.setXrange("6629,14971");
CTLock lock = shapetype.addNewLock();
lock.setExt(STExt.EDIT);
CTShape shape = group.addNewShape();
shape.setId("PowerPlusWaterMarkObject" + idx);
shape.setSpid("_x0000_s102" + (4 + idx));
shape.setType("#_x0000_t136");
shape.setStyle("position:absolute;margin-left:0;margin-top:0;width:415pt;height:207.5pt;z-index:-251654144;mso-wrap-edited:f;mso-position-horizontal:center;mso-position-horizontal-relative:margin;mso-position-vertical:center;mso-position-vertical-relative:margin");
shape.setWrapcoords("616 5068 390 16297 39 16921 -39 17155 7265 17545 7186 17467 -39 17467 18904 17467 10507 17467 8710 17545 18904 17077 18787 16843 18358 16297 18279 12554 19178 12476 20701 11774 20779 11228 21131 10059 21248 8811 21248 7563 20975 6316 20935 5380 19490 5146 14022 5068 2616 5068");
shape.setFillcolor("black");
shape.setStroked(STTrueFalse.FALSE);
CTTextPath shapeTextPath = shape.addNewTextpath();
shapeTextPath.setStyle("font-family:"Cambria";font-size:1pt");
shapeTextPath.setString(text);
pict.set(group);
// end watermark paragraph
return new XWPFParagraph(p, doc);
}
use of org.openxmlformats.schemas.presentationml.x2006.main.CTPicture in project poi by apache.
the class XSLFPictureShape method getBlipFill.
protected CTBlipFillProperties getBlipFill() {
CTPicture ct = (CTPicture) getXmlObject();
CTBlipFillProperties bfp = ct.getBlipFill();
if (bfp != null) {
return bfp;
}
String xquery = "declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main'; " + "declare namespace mc='http://schemas.openxmlformats.org/markup-compatibility/2006' " + ".//mc:Fallback/p:blipFill";
XmlObject xo = selectProperty(XmlObject.class, xquery);
try {
xo = CTPicture.Factory.parse(xo.getDomNode());
} catch (XmlException xe) {
return null;
}
return ((CTPicture) xo).getBlipFill();
}
Aggregations