From 463c68c6b374a110b3ec688ef85d5fcaeda85afd Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Wed, 28 Dec 2011 12:32:07 +0000 Subject: [PATCH] more progress with merging external slides git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1225169 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xslf/usermodel/XSLFGroupShape.java | 16 ++++++ .../apache/poi/xslf/usermodel/XSLFSheet.java | 49 +++++++++++++++++-- .../apache/poi/xslf/usermodel/XSLFSlide.java | 5 +- 3 files changed, 65 insertions(+), 5 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java index 66cb5abb53..920cf8beaf 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java @@ -25,6 +25,7 @@ import org.apache.poi.openxml4j.opc.TargetMode; import org.apache.poi.util.Beta; import org.apache.poi.util.Units; import org.apache.xmlbeans.XmlObject; +import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip; import org.openxmlformats.schemas.drawingml.x2006.main.CTGroupShapeProperties; import org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D; import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps; @@ -33,6 +34,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D; import org.openxmlformats.schemas.presentationml.x2006.main.CTConnector; import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape; import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShapeNonVisual; +import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture; import org.openxmlformats.schemas.presentationml.x2006.main.CTShape; import java.awt.Graphics2D; @@ -309,4 +311,18 @@ public class XSLFGroupShape extends XSLFShape { } + @Override + void copy(XSLFShape src){ + XSLFGroupShape gr = (XSLFGroupShape)src; + // recursively update each shape + XSLFShape[] tgtShapes = getShapes(); + XSLFShape[] srcShapes = gr.getShapes(); + for(int i = 0; i < tgtShapes.length; i++){ + XSLFShape s1 = srcShapes[i]; + XSLFShape s2 = tgtShapes[i]; + + s2.copy(s1); + } + } + } \ No newline at end of file diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java index ce568f0ff6..0c64947b9c 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java @@ -286,10 +286,11 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements Iterable tgtShapes = getShapeList(); List srcShapes = src.getShapeList(); for(int i = 0; i < tgtShapes.size(); i++){ @@ -302,10 +303,52 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements Iterablethis. + */ + public XSLFSheet appendContent(XSLFSheet src){ + CTGroupShape spTree = getSpTree(); + int numShapes = getShapeList().size(); + + CTGroupShape srcTree = src.getSpTree(); + for(XmlObject ch : srcTree.selectPath("*")){ + if(ch instanceof CTShape){ // simple shape + spTree.addNewSp().set(ch); + } else if (ch instanceof CTGroupShape){ + spTree.addNewGrpSp().set(ch); + } else if (ch instanceof CTConnector){ + spTree.addNewCxnSp().set(ch); + } else if (ch instanceof CTPicture){ + spTree.addNewPic().set(ch); + } else if (ch instanceof CTGraphicalObjectFrame){ + spTree.addNewGraphicFrame().set(ch); + } + } + + _shapes = null; + _spTree = null; + _drawing = null; + _spTree = null; + + // recursively update each shape + List tgtShapes = getShapeList(); + List srcShapes = src.getShapeList(); + for(int i = 0; i < srcShapes.size(); i++){ + XSLFShape s1 = srcShapes.get(i); + XSLFShape s2 = tgtShapes.get(numShapes + i); + + s2.copy(s1); + } + return this; + } + + /** * @return theme (shared styles) associated with this theme. * By default returns null which means that this sheet is theme-less. * Sheets that support the notion of themes (slides, masters, layouts, etc.) should override this - * method and return the corresposnding package part. + * method and return the corresponding package part. */ XSLFTheme getTheme(){ return null; 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 91566cb09a..f2d4b6eff1 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java @@ -225,8 +225,9 @@ public final class XSLFSlide extends XSLFSheet { public XSLFSlide importContent(XSLFSheet src){ super.importContent(src); - CTBackground bg = ((CTSlide)src.getXmlObject()).getCSld().getBg(); - if(bg != null) { + 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(); -- 2.39.5