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
This commit is contained in:
Yegor Kozlov 2012-02-21 12:13:39 +00:00
parent 946733c773
commit b0b28bf53c
3 changed files with 31 additions and 0 deletions

View File

@ -34,6 +34,7 @@
<changes>
<release version="3.8-beta6" date="2012-??-??">
<action dev="poi-developers" type="fix">52687 - fixed merging slides with pictures with associated custom tags</action>
<action dev="poi-developers" type="add"> allow runtime registration of functions in FormulaEvaluator</action>
<action dev="poi-developers" type="fix">52665 - When reading from a ZipFileZipEntrySource that has already been closed, give IllegalArgumentException rather than NPE</action>
<action dev="poi-developers" type="fix">52664 - MAPIMessage may not always have name chunks when checking for 7 bit encodings</action>

View File

@ -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();
}
}
}

View File

@ -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());
}
}