From b0b28bf53cdd2dfa0f6c3b8fcf4d687c14a76531 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Tue, 21 Feb 2012 12:13:39 +0000 Subject: [PATCH] fixed importing pictures having associated custom tags, see Bugzilla 52687 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1291730 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../poi/xslf/usermodel/XSLFPictureShape.java | 7 ++++++ .../xslf/usermodel/TestXSLFPictureShape.java | 23 +++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index edfd430e92..85064486b6 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 52687 - fixed merging slides with pictures with associated custom tags allow runtime registration of functions in FormulaEvaluator 52665 - When reading from a ZipFileZipEntrySource that has already been closed, give IllegalArgumentException rather than NPE 52664 - MAPIMessage may not always have name chunks when checking for 7 bit encodings diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java index 8ad48364ce..035e15e438 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java @@ -29,6 +29,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps; import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D; import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties; import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType; +import org.openxmlformats.schemas.presentationml.x2006.main.CTApplicationNonVisualDrawingProps; import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture; import org.openxmlformats.schemas.presentationml.x2006.main.CTPictureNonVisual; @@ -147,5 +148,11 @@ public class XSLFPictureShape extends XSLFSimpleShape { CTBlip blip = ct.getBlipFill().getBlip(); blip.setEmbed(relId); + CTApplicationNonVisualDrawingProps nvPr = ct.getNvPicPr().getNvPr(); + if(nvPr.isSetCustDataLst()) { + // discard any custom tags associated with the picture being copied + nvPr.unsetCustDataLst(); + } + } } diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java index bf56481f59..efdccb65a3 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java @@ -18,6 +18,7 @@ package org.apache.poi.xslf.usermodel; import junit.framework.TestCase; import org.apache.poi.xslf.XSLFTestDataSamples; +import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture; import java.io.IOException; import java.util.Arrays; @@ -130,4 +131,26 @@ public class TestXSLFPictureShape extends TestCase { XSLFSlide slide2 = ppt.createSlide(); } + + public void testMerge() { + XMLSlideShow ppt1 = new XMLSlideShow(); + byte[] data1 = new byte[100]; + int idx1 = ppt1.addPicture(data1, XSLFPictureData.PICTURE_TYPE_JPEG); + + XSLFSlide slide1 = ppt1.createSlide(); + XSLFPictureShape shape1 = slide1.createPicture(idx1); + CTPicture ctPic1 = (CTPicture)shape1.getXmlObject(); + ctPic1.getNvPicPr().getNvPr().addNewCustDataLst().addNewTags().setId("rId99"); + + XMLSlideShow ppt2 = new XMLSlideShow(); + + XSLFSlide slide2 = ppt2.createSlide().importContent(slide1); + XSLFPictureShape shape2 = (XSLFPictureShape)slide2.getShapes()[0]; + + assertTrue(Arrays.equals(data1, shape2.getPictureData().getData())); + + CTPicture ctPic2 = (CTPicture)shape2.getXmlObject(); + assertFalse(ctPic2.getNvPicPr().getNvPr().isSetCustDataLst()); + + } } \ No newline at end of file -- 2.39.5