mirror of https://github.com/apache/poi.git
[bug-62736] Relations on XSLFPictureShape are removed unconditionally. Thanks to Mate Borcsok
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1842055 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9973fecad0
commit
43c57c26c2
|
@ -692,11 +692,24 @@ implements XSLFShapeContainer, Sheet<XSLFShape,XSLFTextParagraph> {
|
|||
/**
|
||||
* Helper method for sheet and group shapes
|
||||
*
|
||||
* @param pictureShape the picture shapes whose relation is to be removed
|
||||
* @param pictureShape the picture shapes whose relation is to be removed,
|
||||
* only if there are no more relations on its sheet to that picture
|
||||
*/
|
||||
void removePictureRelation(XSLFPictureShape pictureShape) {
|
||||
int numberOfRelations = 0;
|
||||
String targetBlipId = pictureShape.getBlipId();
|
||||
for (XSLFShape shape : pictureShape.getSheet().getShapes()) {
|
||||
if (shape instanceof XSLFPictureShape) {
|
||||
XSLFPictureShape currentPictureShape = ((XSLFPictureShape) shape);
|
||||
if (currentPictureShape.getBlipId().equals(targetBlipId)) {
|
||||
numberOfRelations++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (numberOfRelations <= 1) {
|
||||
removeRelation(pictureShape.getBlipId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
|
|
@ -93,6 +93,87 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
|
|||
public class TestXSLFBugs {
|
||||
private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
||||
|
||||
@Test
|
||||
public void bug62736() throws Exception {
|
||||
XMLSlideShow ss1 = XSLFTestDataSamples.openSampleDocument("bug62736.pptx");
|
||||
|
||||
assertEquals(1, ss1.getSlides().size());
|
||||
|
||||
XSLFSlide slide0 = ss1.getSlides().get(0);
|
||||
|
||||
assertEquals(slide0.getShapes().size(), 4);
|
||||
|
||||
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
|
||||
assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
|
||||
assertRelation(slide0, "/ppt/media/image1.png", "rId2");
|
||||
assertEquals(slide0.getRelations().size(), 2);
|
||||
|
||||
List<XSLFPictureShape> pictures = new ArrayList<>();
|
||||
for (XSLFShape shape : slide0.getShapes()) {
|
||||
if (shape instanceof XSLFPictureShape) {
|
||||
pictures.add((XSLFPictureShape) shape);
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(pictures.size(), 2);
|
||||
assertEquals(pictures.get(0).getPictureData().getFileName(), "image1.png");
|
||||
assertEquals(pictures.get(1).getPictureData().getFileName(), "image1.png");
|
||||
// blipId is rId2 of both pictures
|
||||
|
||||
// remove just the first picture
|
||||
slide0.removeShape(pictures.get(0));
|
||||
|
||||
assertEquals(slide0.getShapes().size(), 3);
|
||||
|
||||
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
|
||||
assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
|
||||
// the bug is that the following relation is gone
|
||||
assertRelation(slide0, "/ppt/media/image1.png", "rId2");
|
||||
assertEquals(slide0.getRelations().size(), 2);
|
||||
|
||||
// Save and re-load
|
||||
XMLSlideShow ss2 = XSLFTestDataSamples.writeOutAndReadBack(ss1);
|
||||
ss1.close();
|
||||
assertEquals(1, ss2.getSlides().size());
|
||||
|
||||
slide0 = ss2.getSlides().get(0);
|
||||
|
||||
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
|
||||
assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
|
||||
assertRelation(slide0, "/ppt/media/image1.png", "rId2");
|
||||
assertEquals(slide0.getRelations().size(), 2);
|
||||
|
||||
pictures.clear();
|
||||
for (XSLFShape shape : slide0.getShapes()) {
|
||||
if (shape instanceof XSLFPictureShape) {
|
||||
pictures.add((XSLFPictureShape) shape);
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(pictures.size(), 1);
|
||||
assertEquals(pictures.get(0).getPictureData().getFileName(), "image1.png");
|
||||
|
||||
slide0.removeShape(pictures.get(0));
|
||||
|
||||
assertEquals(slide0.getShapes().size(), 2);
|
||||
|
||||
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
|
||||
assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
|
||||
assertNull(slide0.getRelationById("rId2"));
|
||||
assertEquals(slide0.getRelations().size(), 1);
|
||||
|
||||
// Save and re-load
|
||||
XMLSlideShow ss3 = XSLFTestDataSamples.writeOutAndReadBack(ss2);
|
||||
ss2.close();
|
||||
assertEquals(1, ss3.getSlides().size());
|
||||
|
||||
slide0 = ss3.getSlides().get(0);
|
||||
|
||||
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
|
||||
assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
|
||||
assertEquals(slide0.getShapes().size(), 2);
|
||||
ss3.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug61589() throws IOException {
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue