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
This commit is contained in:
Andreas Beeker 2016-10-19 23:25:51 +00:00
parent eeff9989ee
commit 3ac60f4bcc
2 changed files with 58 additions and 11 deletions

View File

@ -241,18 +241,35 @@ implements Slide<XSLFShape,XSLFTextParagraph> {
@Override @Override
public XSLFSlide importContent(XSLFSheet src){ public XSLFSlide importContent(XSLFSheet src){
super.importContent(src); super.importContent(src);
if (!(src instanceof XSLFSlide)) {
XSLFBackground bgShape = getBackground(); return this;
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; return this;
} }

View File

@ -31,7 +31,10 @@ import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream;
import java.net.URI; import java.net.URI;
import java.util.Collection; 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.draw.DrawPaint;
import org.apache.poi.sl.usermodel.PaintStyle; import org.apache.poi.sl.usermodel.PaintStyle;
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint; 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;
import org.apache.poi.sl.usermodel.PictureData.PictureType; import org.apache.poi.sl.usermodel.PictureData.PictureType;
import org.apache.poi.sl.usermodel.ShapeType; import org.apache.poi.sl.usermodel.ShapeType;
@ -517,4 +521,30 @@ public class TestXSLFBugs {
float actRGB[] = actual.getRGBComponents(null); float actRGB[] = actual.getRGBComponents(null);
assertArrayEquals(expRGB, actRGB, 0.0001f); 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();
}
} }