import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlString;
+import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTEmpty;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
.selectPath("declare namespace pic='http://schemas.openxmlformats.org/drawingml/2006/picture' .//pic:pic");
for(XmlObject pict : picts) {
if(pict instanceof org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture) {
- pictures.add(new XWPFPicture(
+ XWPFPicture picture = new XWPFPicture(
(org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture)pict, p
- ));
+ );
+ pictures.add(picture);
}
}
}
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STLineSpacingRule;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
+import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
+import org.openxmlformats.schemas.drawingml.x2006.picture.PicDocument;
+import org.openxmlformats.schemas.drawingml.x2006.picture.impl.PicDocumentImpl;
/**
* Tests for XWPF Paragraphs
}
public void testPictures() throws Exception {
- // TODO
+ XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("VariousPictures.docx");
+ assertEquals(7, doc.getParagraphs().size());
+
+ XWPFParagraph p;
+ XWPFRun r;
+
+ // Text paragraphs
+ assertEquals("Sheet with various pictures", doc.getParagraphs().get(0).getText());
+ assertEquals("(jpeg, png, wmf, emf and pict) ", doc.getParagraphs().get(1).getText());
+
+ // Spacer ones
+ assertEquals("", doc.getParagraphs().get(2).getText());
+ assertEquals("", doc.getParagraphs().get(3).getText());
+ assertEquals("", doc.getParagraphs().get(4).getText());
+
+ // Image one
+ p = doc.getParagraphs().get(5);
+ assertEquals(6, p.getRuns().size());
+
+ r = p.getRuns().get(0);
+ assertEquals("", r.toString());
+ assertEquals(1, r.getEmbeddedPictures().size());
+ assertNotNull(r.getEmbeddedPictures().get(0).getPictureData());
+ assertEquals("image1.wmf", r.getEmbeddedPictures().get(0).getPictureData().getFileName());
+
+ r = p.getRuns().get(1);
+ assertEquals("", r.toString());
+ assertEquals(1, r.getEmbeddedPictures().size());
+ assertNotNull(r.getEmbeddedPictures().get(0).getPictureData());
+ assertEquals("image2.png", r.getEmbeddedPictures().get(0).getPictureData().getFileName());
+
+ r = p.getRuns().get(2);
+ assertEquals("", r.toString());
+ assertEquals(1, r.getEmbeddedPictures().size());
+ assertNotNull(r.getEmbeddedPictures().get(0).getPictureData());
+ assertEquals("image3.emf", r.getEmbeddedPictures().get(0).getPictureData().getFileName());
+
+ r = p.getRuns().get(3);
+ assertEquals("", r.toString());
+ assertEquals(1, r.getEmbeddedPictures().size());
+ assertNotNull(r.getEmbeddedPictures().get(0).getPictureData());
+ assertEquals("image4.emf", r.getEmbeddedPictures().get(0).getPictureData().getFileName());
+
+ r = p.getRuns().get(4);
+ assertEquals("", r.toString());
+ assertEquals(1, r.getEmbeddedPictures().size());
+ assertNotNull(r.getEmbeddedPictures().get(0).getPictureData());
+ assertEquals("image5.jpeg", r.getEmbeddedPictures().get(0).getPictureData().getFileName());
+
+ r = p.getRuns().get(5);
+ assertEquals(" ", r.toString());
+ assertEquals(0, r.getEmbeddedPictures().size());
+
+ // Final spacer
+ assertEquals("", doc.getParagraphs().get(6).getText());
+
+
+ // Look in detail at one
+ r = p.getRuns().get(4);
+ XWPFPicture pict = r.getEmbeddedPictures().get(0);
+ CTPicture picture = pict.getCTPicture();
+ assertEquals("rId8", picture.getBlipFill().getBlip().getEmbed());
+
+ // Ensure that the ooxml compiler finds everything we need
+ r.getCTR().getDrawingArray(0);
+ r.getCTR().getDrawingArray(0).getInlineArray(0);
+ r.getCTR().getDrawingArray(0).getInlineArray(0).getGraphic();
+ r.getCTR().getDrawingArray(0).getInlineArray(0).getGraphic().getGraphicData();
+ PicDocument pd = new PicDocumentImpl(null);
}
}