]> source.dussan.org Git - poi.git/commitdiff
Bug 55714 - Background image ignored on slide copy
authorAndreas Beeker <kiwiwings@apache.org>
Wed, 19 Oct 2016 23:25:51 +0000 (23:25 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Wed, 19 Oct 2016 23:25:51 +0000 (23:25 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1765733 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java
src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java

index 7301b553a5846a2427b2ee67679f5ee3fff3a3c9..66ec5e17645396210199fcba526b433f6b81b40e 100644 (file)
@@ -241,18 +241,35 @@ implements Slide<XSLFShape,XSLFTextParagraph> {
     @Override
     public XSLFSlide importContent(XSLFSheet src){
         super.importContent(src);
+        if (!(src instanceof XSLFSlide)) {
+            return this;
+        }
 
-        XSLFBackground bgShape = getBackground();
-        if(bgShape != null) {
-            CTBackground bg = (CTBackground)bgShape.getXmlObject();
-            if(bg.isSetBgPr() && bg.getBgPr().isSetBlipFill()){
-                CTBlip blip = bg.getBgPr().getBlipFill().getBlip();
-                String blipId = blip.getEmbed();
-
-                String relId = importBlip(blipId, src.getPackagePart());
-                blip.setEmbed(relId);
+        // only copy direct backgrounds - not backgrounds of master sheet
+        CTBackground bgOther = ((XSLFSlide)src)._slide.getCSld().getBg();
+        if (bgOther == null) {
+            return this;
+        }
+        
+        CTBackground bgThis = _slide.getCSld().getBg();
+        // remove existing background
+        if (bgThis != null) {
+            if (bgThis.isSetBgPr() && bgThis.getBgPr().isSetBlipFill()) {
+                String oldId = bgThis.getBgPr().getBlipFill().getBlip().getEmbed();
+                removeRelation(getRelationById(oldId));
             }
+            _slide.getCSld().unsetBg();
+        }
+            
+        bgThis = (CTBackground)_slide.getCSld().addNewBg().set(bgOther);
+            
+        if(bgOther.isSetBgPr() && bgOther.getBgPr().isSetBlipFill()){
+            String idOther = bgOther.getBgPr().getBlipFill().getBlip().getEmbed();
+            String idThis = importBlip(idOther, src.getPackagePart());
+            bgThis.getBgPr().getBlipFill().getBlip().setEmbed(idThis);
+            
         }
+
         return this;
     }
 
index b0c0e52431405a5738dfe3a71531d3be90282fd2..dcf8c1cb80b35666ffea400533627a08c76cdf9b 100644 (file)
@@ -31,7 +31,10 @@ import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.net.URI;
 import java.util.Collection;
 
@@ -43,6 +46,7 @@ import org.apache.poi.POIXMLDocumentPart.RelationPart;
 import org.apache.poi.sl.draw.DrawPaint;
 import org.apache.poi.sl.usermodel.PaintStyle;
 import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
+import org.apache.poi.sl.usermodel.PaintStyle.TexturePaint;
 import org.apache.poi.sl.usermodel.PictureData;
 import org.apache.poi.sl.usermodel.PictureData.PictureType;
 import org.apache.poi.sl.usermodel.ShapeType;
@@ -517,4 +521,30 @@ public class TestXSLFBugs {
         float actRGB[] = actual.getRGBComponents(null);
         assertArrayEquals(expRGB, actRGB, 0.0001f);
     }
+
+    @Test
+    public void bug55714() throws IOException {
+        XMLSlideShow srcPptx = XSLFTestDataSamples.openSampleDocument("pptx2svg.pptx");
+        XMLSlideShow newPptx = new XMLSlideShow();
+        XSLFSlide srcSlide = srcPptx.getSlides().get(0);
+        XSLFSlide newSlide = newPptx.createSlide();
+
+        XSLFSlideLayout srcSlideLayout = srcSlide.getSlideLayout();
+        XSLFSlideLayout newSlideLayout = newSlide.getSlideLayout();
+        newSlideLayout.importContent(srcSlideLayout);
+
+        XSLFSlideMaster srcSlideMaster = srcSlide.getSlideMaster();
+        XSLFSlideMaster newSlideMaster = newSlide.getSlideMaster();
+        newSlideMaster.importContent(srcSlideMaster); 
+
+        newSlide.importContent(srcSlide);
+        XMLSlideShow rwPptx = XSLFTestDataSamples.writeOutAndReadBack(newPptx);
+        
+        PaintStyle ps = rwPptx.getSlides().get(0).getBackground().getFillStyle().getPaint();
+        assertTrue(ps instanceof TexturePaint);
+        
+        rwPptx.close();
+        newPptx.close();
+        srcPptx.close();
+    }
 }