// Image size (excluding the 8 byte header)
int imgsize = LittleEndian.getInt(pictstream, pos);
pos += LittleEndian.INT_SIZE;
- byte[] imgdata = new byte[imgsize];
- System.arraycopy(pictstream, pos, imgdata, 0, imgdata.length);
// The image size must be 0 or greater
// (0 is allowed, but odd, since we do wind on by the header each
// If they type (including the bonus 0xF018) is 0, skip it
if(type == 0) {
- System.err.println("Problem reading picture: Invalid image type 0, on picture with length" + imgsize + ".\nYou document will probably become corrupted if you save it!");
+ System.err.println("Problem reading picture: Invalid image type 0, on picture with length " + imgsize + ".\nYou document will probably become corrupted if you save it!");
+ System.err.println(pos);
} else {
+ // Copy the data, ready to pass to PictureData
+ byte[] imgdata = new byte[imgsize];
+ if(imgsize > 0) {
+ System.arraycopy(pictstream, pos, imgdata, 0, imgdata.length);
+ }
+
// Build the PictureData object from the data
try {
PictureData pict = PictureData.create(type - 0xF018);
assertEquals(Picture.WMF, hslf.getPictures()[0].getType());
assertEquals(Picture.WMF, hslf.getPictures()[1].getType());
- // TODO: DISABLED: Pending bug #41176
+ // Now test what happens when we use the SlideShow interface
+ SlideShow ppt = new SlideShow(hslf);
+ Slide[] slides = ppt.getSlides();
+ PictureData[] pictures = ppt.getPictureData();
+ assertEquals(12, slides.length);
+ assertEquals(2, pictures.length);
+
+ Picture pict;
+ PictureData pdata;
+
+ pict = (Picture)slides[0].getShapes()[1]; // 2nd object on 1st slide
+ pdata = pict.getPictureData();
+ assertTrue(pdata instanceof WMF);
+ assertEquals(Picture.WMF, pdata.getType());
+
+ pict = (Picture)slides[0].getShapes()[2]; // 3rd object on 1st slide
+ pdata = pict.getPictureData();
+ assertTrue(pdata instanceof WMF);
+ assertEquals(Picture.WMF, pdata.getType());
+ }
+
+ public void testZeroPictureLength() throws Exception {
+ HSLFSlideShow hslf = new HSLFSlideShow(new File(cwd, "PictureLengthZero.ppt").getPath());
+ // Should still have 2 real pictures
+ assertEquals(2, hslf.getPictures().length);
+ // Both are real pictures, both WMF
+ assertEquals(Picture.WMF, hslf.getPictures()[0].getType());
+ assertEquals(Picture.WMF, hslf.getPictures()[1].getType());
+
// Now test what happens when we use the SlideShow interface
- //SlideShow ppt = new SlideShow(hslf);
+ SlideShow ppt = new SlideShow(hslf);
+ Slide[] slides = ppt.getSlides();
+ PictureData[] pictures = ppt.getPictureData();
+ assertEquals(27, slides.length);
+ assertEquals(2, pictures.length);
+
+ Picture pict;
+ PictureData pdata;
+
+ pict = (Picture)slides[6].getShapes()[13];
+ pdata = pict.getPictureData();
+ assertTrue(pdata instanceof WMF);
+ assertEquals(Picture.WMF, pdata.getType());
+
+ pict = (Picture)slides[7].getShapes()[13];
+ pdata = pict.getPictureData();
+ assertTrue(pdata instanceof WMF);
+ assertEquals(Picture.WMF, pdata.getType());
}
}