more progress with merging external slides

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1225169 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2011-12-28 12:32:07 +00:00
parent b964597d23
commit ff8ec41980
3 changed files with 65 additions and 5 deletions

View File

@ -25,6 +25,7 @@ import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.util.Beta; import org.apache.poi.util.Beta;
import org.apache.poi.util.Units; import org.apache.poi.util.Units;
import org.apache.xmlbeans.XmlObject; 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.CTGroupShapeProperties;
import org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D; import org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D;
import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps; 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.CTConnector;
import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape; import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape;
import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShapeNonVisual; 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 org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
import java.awt.Graphics2D; 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);
}
}
} }

View File

@ -286,8 +286,9 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements Iterable<X
_shapes = null; _shapes = null;
_spTree = null; _spTree = null;
_drawing = null; _drawing = null;
_spTree = null;
// first copy the source xml // first copy the source xml
getXmlObject().set(src.getXmlObject()); getSpTree().set(src.getSpTree());
// recursively update each shape // recursively update each shape
List<XSLFShape> tgtShapes = getShapeList(); List<XSLFShape> tgtShapes = getShapeList();
@ -302,10 +303,52 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements Iterable<X
} }
/** /**
* Append content to this sheet.
*
* @param src the source sheet
* @return modified <code>this</code>.
*/
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<XSLFShape> tgtShapes = getShapeList();
List<XSLFShape> 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. * @return theme (shared styles) associated with this theme.
* By default returns <code>null</code> which means that this sheet is theme-less. * By default returns <code>null</code> which means that this sheet is theme-less.
* Sheets that support the notion of themes (slides, masters, layouts, etc.) should override this * 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(){ XSLFTheme getTheme(){
return null; return null;

View File

@ -225,8 +225,9 @@ public final class XSLFSlide extends XSLFSheet {
public XSLFSlide importContent(XSLFSheet src){ public XSLFSlide importContent(XSLFSheet src){
super.importContent(src); super.importContent(src);
CTBackground bg = ((CTSlide)src.getXmlObject()).getCSld().getBg(); XSLFBackground bgShape = getBackground();
if(bg != null) { if(bgShape != null) {
CTBackground bg = (CTBackground)bgShape.getXmlObject();
if(bg.isSetBgPr() && bg.getBgPr().isSetBlipFill()){ if(bg.isSetBgPr() && bg.getBgPr().isSetBlipFill()){
CTBlip blip = bg.getBgPr().getBlipFill().getBlip(); CTBlip blip = bg.getBgPr().getBlipFill().getBlip();
String blipId = blip.getEmbed(); String blipId = blip.getEmbed();