|Summary:||offset of new pictures is sometimes wrong|
|Component:||HSLF||Assignee:||POI Developers List <dev>|
|Attachments:||patch that fixes the problem for me.|
Description David 2009-01-29 08:52:31 UTC
Hi, after images have been removed from a powerpoint file, they are sometimes not really deleted. This causes the calculation of the offset in SlideShow.addPicture to fail. Attached is a patch that bases the calculation on the actual data contained in the file. HTH, David.
Comment 1 David 2009-01-29 08:53:23 UTC
Created attachment 23193 [details] patch that fixes the problem for me.
Comment 2 Yegor Kozlov 2009-01-30 06:01:55 UTC
Can you attach a problem ppt file with removed images? The suggested fix looks good but I don't want to commit it without a unit test. Thanks, Yegor
Comment 3 David 2009-02-01 08:30:41 UTC
Sorry, I am having trouble reproducing this problem on a new ppt file. The one that causes problems for me I cannot submit because of company policy, but this happened before on several files, so this does not seem to be an isolated incident. I will try again to reproduce the problem when I have more time (in about a week or so). bye, David.
Comment 4 Yegor Kozlov 2009-02-01 08:49:05 UTC
I suspect it can be reproduced with PictureTypeZero.ppt or PictureLengthZero.ppt from our collection of test files: http://svn.apache.org/repos/asf/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/ Can check it and post sample code that causes the problem? These two files contain invalid images, the first one contains images with unknown type=0, the second one contains images with zero length, i.e. only header and no data. Yegor
Comment 5 David 2009-02-09 04:58:50 UTC
You are correct, PictureLengthZero.ppt exposes the problem. Simply adding any picture, like the following code does, should result in an invalid image in the resulting ppt: SlideShow ppt = new SlideShow( new ByteArrayInputStream( readFile( args[ 0 ] ) ) ); int index = ppt.addPicture( readFile( args[ 1 ] ), Picture.PNG ); Picture picture = new Picture( index ); ppt.getSlides().addShape( picture ); ByteArrayOutputStream result = new ByteArrayOutputStream(); ppt.write( result ); FileOutputStream os = new FileOutputStream( "output.ppt" ); os.write( result.toByteArray() ); os.close(); readFile is a simple function that returns the bytes contained in a file. After applying the patch this works for me. bye, David.