import java.awt.geom.Rectangle2D;\r
import java.awt.image.BufferedImage;\r
import java.io.ByteArrayInputStream;\r
+import java.net.URI;\r
\r
import javax.imageio.ImageIO;\r
import javax.xml.namespace.QName;\r
setAnchor(new java.awt.Rectangle(50, 50, 200, 200));\r
}\r
}\r
+ \r
+ /**\r
+ * Is this an internal picture (image data included within\r
+ * the PowerPoint file), or an external linked picture\r
+ * (image lives outside)?\r
+ */\r
+ public boolean isExternalLinkedPicture() {\r
+ if (getBlipId() == null && getBlipLink() != null) {\r
+ return true;\r
+ }\r
+ return false;\r
+ }\r
\r
+ /**\r
+ * Return the data on the (internal) picture.\r
+ * For an external linked picture, will return null\r
+ */\r
public XSLFPictureData getPictureData() {\r
if(_data == null){\r
String blipId = getBlipId();\r
+ if (blipId == null) return null;\r
\r
PackagePart p = getSheet().getPackagePart();\r
PackageRelationship rel = p.getRelationship(blipId);\r
}\r
return _data;\r
}\r
+ \r
+ /**\r
+ * For an external linked picture, return the last-seen\r
+ * path to the picture.\r
+ * For an internal picture, returns null.\r
+ */\r
+ public URI getPictureLink() {\r
+ if (getBlipId() != null) {\r
+ // Internal picture, nothing to return\r
+ return null;\r
+ }\r
+ \r
+ String rId = getBlipLink();\r
+ if (rId == null) {\r
+ // No link recorded, nothing we can do\r
+ return null;\r
+ }\r
+ \r
+ PackagePart p = getSheet().getPackagePart();\r
+ PackageRelationship rel = p.getRelationship(rId);\r
+ if (rel != null) {\r
+ return rel.getTargetURI();\r
+ }\r
+ return null;\r
+ }\r
\r
- private String getBlipId(){\r
+ private CTBlip getBlip(){\r
CTPicture ct = (CTPicture)getXmlObject();\r
- return ct.getBlipFill().getBlip().getEmbed();\r
+ return ct.getBlipFill().getBlip();\r
+ }\r
+ private String getBlipLink(){\r
+ String link = getBlip().getLink();\r
+ if (link.isEmpty()) return null;\r
+ return link;\r
+ }\r
+ private String getBlipId(){\r
+ String id = getBlip().getEmbed();\r
+ if (id.isEmpty()) return null;\r
+ return id;\r
}\r
\r
@Override\r
* there is no data available and XSLFPictureShape.getPictureData()
* gives a NPE, see bug #56812
*/
- public void DISABLEDtest56812() throws Exception {
+ public void test56812() throws Exception {
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("56812.pptx");
- int pictures = 0;
+ int internalPictures = 0;
+ int externalPictures = 0;
for (XSLFSlide slide : ppt.getSlides()){
for (XSLFShape shape : slide.getShapes()){
assertNotNull(shape);
if (shape instanceof XSLFPictureShape) {
- XSLFPictureData data = ((XSLFPictureShape) shape).getPictureData();
- assertNotNull(data);
- assertNotNull(data.getFileName());
- pictures++;
+ XSLFPictureShape picture = (XSLFPictureShape)shape;
+ if (picture.isExternalLinkedPicture()) {
+ externalPictures++;
+
+ assertNotNull(picture.getPictureLink());
+ } else {
+ internalPictures++;
+
+ XSLFPictureData data = picture.getPictureData();
+ assertNotNull(data);
+ assertNotNull(data.getFileName());
+ }
}
}
}
- assertEquals(3, pictures);
+ assertEquals(2, internalPictures);
+ assertEquals(1, externalPictures);
}
protected String getSlideText(XSLFSlide slide) {