From 3ac60f4bcc5fc0f6170ad9e424e8bc547afba76b Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Wed, 19 Oct 2016 23:25:51 +0000 Subject: [PATCH] Bug 55714 - Background image ignored on slide copy git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1765733 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/xslf/usermodel/XSLFSlide.java | 39 +++++++++++++------ .../org/apache/poi/xslf/TestXSLFBugs.java | 30 ++++++++++++++ 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java index 7301b553a..66ec5e176 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java @@ -241,18 +241,35 @@ implements Slide { @Override public XSLFSlide importContent(XSLFSheet src){ super.importContent(src); - - 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); - } + if (!(src instanceof XSLFSlide)) { + return this; } + + // 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; } diff --git a/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java b/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java index b0c0e5243..dcf8c1cb8 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java @@ -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(); + } }