if(eventType == XmlPullParser.START_TAG) {
String tnm = xpp.getName();
if(tnm.equals("twoCellAnchor")) { // beginning of DrawingML for a single image or chart
lastTag.push(tnm);
// TODO: handle group shapes which combine images, shapes and/or charts ********************************************************
TwoCellAnchor t= (TwoCellAnchor) TwoCellAnchor.parseOOXML(xpp, lastTag, bk).cloneElement();
if (t.hasImage()) {
String s= t.getEmbed(); // rid of embedded object
if (s.indexOf("rId")==0) { // should!
String imgFile= OOXMLReader.parsePathForZip(OOXMLReader.getFilename(drawingFiles, s), parentDir);
ZipEntry img= new ZipEntry(imgFile);
BufferedInputStream is= new BufferedInputStream(zip.getInputStream(img));
ImageHandle im= new ImageHandle(is, this);
this.insertImage(im);
im.setName(t.getName());
im.setShapeName(t.getDescr());
im.setBounds(TwoCellAnchor.convertBoundsToBIFF8(this, t.getBounds())); // must do after insert
im.setSpPr(t.getSppr()); // set image shape properties
im.setEditMovement(t.getEditAs()); // specify how to resize or move
im.update(); // update underlying image record with set data
}
} else if (t.hasChart()) {
String s= t.getChartRId();
if (s.indexOf("rId")==0) { // should!
String chartfilename= OOXMLReader.getFilename(drawingFiles, s);
String name= t.getName();
if (name==null || name.equals("null")) {
name="Untitled Chart";
}
ChartHandle ch= bk.createChart(name, bk.getWorkSheet(this.getSheetName()));
ch.setRelativeBounds(TwoCellAnchor.convertBoundsToBIFF8(this, t.getBounds())); // must do after insert
ch.setEditMovement(t.getEditAs()); // specify how to resize or move
ch.setOOXMLName(name);
chartfilename= OOXMLReader.parsePathForZip(chartfilename, parentDir);
ZipEntry chFile= new ZipEntry(chartfilename);
// must account for default chart settings: set fontx recs to default font for this workbook ...
ch.resetFonts(); // reset all fonts for the chart
ch.removeLegend(); // not all charts have legends!
int ps= chartfilename.lastIndexOf("/") + 1;
ZipEntry rels= OOXMLReader.getEntry(zip,chartfilename.substring(0, ps) + "_rels/" + chartfilename.substring(ps)+".rels");
if (rels!=null) { // chart file has embeds - usually drawing ml which defines userShapes
//xxx TODO: REFACTOR to get these specifics out
ArrayList chartEmbeds= OOXMLReader.parseRels(OOXMLReader.wrapInputStream(zip.getInputStream(rels)));
for (int i= 0; i < chartEmbeds.size(); i++) {
String[] dr= (String[]) chartEmbeds.get(i);
if (dr[0].equals("userShape")) { // should!
dr[1]= dr[1].substring(dr[1].lastIndexOf("/")+1);
ch.addChartEmbed(new String[] {dr[0], externalDir + dr[1]});
OOXMLReader.passThrough(zip, parentDir + dr[1], externalDir + dr[1]); // Store Embedded Object on disk for later retrieval
} else if (dr[0].equals("image")) {
String parentp= OOXMLReader.parsePathForZip(dr[1], parentDir);
parentp= parentp.substring(0, parentp.lastIndexOf("/")+1);
dr[1]= dr[1].substring(dr[1].lastIndexOf("/")+1);
ch.addChartEmbed(new String[] {dr[0], externalDir + dr[1]});
OOXMLReader.passThrough(zip, parentp+dr[1], externalDir +dr[1]); // save the original target file for later re-packaging
} else if (dr[0].equals("themeOverride")) {
String parentp= OOXMLReader.parsePathForZip(dr[1], parentDir);
parentp= parentp.substring(0, parentp.lastIndexOf("/")+1);
dr[1]= dr[1].substring(dr[1].lastIndexOf("/")+1);
ch.addChartEmbed(new String[] {dr[0], externalDir + dr[1]});
ZipEntry target= OOXMLAdapter.getEntry(zip, parentp + dr[1]);
bk.getWorkBook().getTheme().parseOOXML(bk, OOXMLAdapter.wrapInputStream(zip.getInputStream(target)));
} else {
Logger.logWarn("OOXMLAdapter.parseDrawingML: unknown chart embed " + dr[0]);
}
}
}
// do after parsing rels in case there is override theme colors ...
ch.parseOOXML(OOXMLReader.wrapInputStream(zip.getInputStream(chFile)));
}
} else if (t.hasShape()) {
this.addOOXMLShape(t); // just store shape for later output since prev. versions do not handle shapes
if (t.getEmbed()!=null) { // if this shape has embedded objects such as images
String imgFile= OOXMLReader.parsePathForZip(OOXMLReader.getFilename(drawingFiles, t.getEmbed()), parentDir); // look up embedded rid in content list to get filename
t.setEmbedFilename(imgFile); // save embedded filename for later retrieval
OOXMLReader.passThrough(zip, imgFile, externalDir + imgFile); // Store Embedded Object on disk for later retrieval
}
} else { // TESTING!
Logger.logErr("OOXMLAdapter.parseDrawingXML: Unknown twoCellAnchor type");
}