Skip to content

Commit

Permalink
Fix/ooxml opening (#2795)
Browse files Browse the repository at this point in the history
* fix: return loadSync result

* read/write formulas
  • Loading branch information
SergeyLuzyanin authored May 30, 2022
1 parent 1a91241 commit 5b458af
Show file tree
Hide file tree
Showing 5 changed files with 713 additions and 598 deletions.
49 changes: 41 additions & 8 deletions common/Drawings/Format/Format.js
Original file line number Diff line number Diff line change
Expand Up @@ -12389,25 +12389,28 @@
reader.context.assignConnectors(this.spTree);
}
};
CSpTree.prototype.readChildXml = function (name, reader) {
CSpTree.prototype.readSpTreeElement = function(name, reader) {
let oSp = null;
switch (name) {
case "contentPart": {
break;
}
case "cxnSp": {
oSp = new AscFormat.CConnectionShape();
oSp.fromXml(reader);
break;
}
case "extLst": {
break;
}
case "graphicFrame": {
oSp = new AscFormat.CGraphicFrame();
oSp.fromXml(reader);
break;
}
case "grpSp": {
oSp = new AscFormat.CGroupShape();
oSp.fromXml(reader);
break;
}
case "grpSpPr": {
Expand All @@ -12418,15 +12421,40 @@
}
case "pic": {
oSp = new AscFormat.CImageShape();
oSp.fromXml(reader);
break;
}
case "sp": {
oSp = new AscFormat.CShape();
oSp.fromXml(reader);
break;
}
case "AlternateContent": {
let oThis = this;
let oNode = new CT_XmlNode(function (reader, name) {
if(!oSp) {
if(name === "Choice") {
let oChoiceNode = new CT_XmlNode(function(reader, name) {
oSp = CSpTree.prototype.readSpTreeElement.call(oThis, name, reader);
return true;
});
oChoiceNode.fromXml(reader);
}
else if(name === "Fallback") {
let oFallbackNode = new CT_XmlNode(function(reader, name) {
oSp = CSpTree.prototype.readSpTreeElement.call(oThis, name, reader);
return true;
});
oFallbackNode.fromXml(reader);
}
}
return true;
});
oNode.fromXml(reader);
break;
}
}
if (oSp) {
oSp.fromXml(reader);
if (name === "graphicFrame" && !(oSp.graphicObject instanceof AscCommonWord.CTable)) {

let _xfrm = oSp.spPr && oSp.spPr.xfrm;
Expand Down Expand Up @@ -12457,14 +12485,19 @@
_xfrm.setParent(oSp.spPr);
}
}
if (oSp) {
oSp.setBDeleted(false);
if(this.slideObject) {
oSp.setParent(this.slideObject);
}
this.spTree.push(oSp);
}
return oSp;
};
CSpTree.prototype.readChildXml = function (name, reader) {
let oSp = CSpTree.prototype.readSpTreeElement.call(this, name, reader);
if (oSp) {
oSp.setBDeleted(false);
if(this.slideObject) {
oSp.setParent(this.slideObject);
}
this.spTree.push(oSp);
}
return oSp;
};
CSpTree.prototype.toXml = function (writer) {
let name_;
Expand Down
86 changes: 73 additions & 13 deletions common/Shapes/SerializeXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,30 @@
res = res.graphicObject;
} else if ("AlternateContent" === name) {
let elem = new CT_XmlNode(function(reader, name) {
if ("Choice" === name) {
let elem = new CT_XmlNode(function(reader, name) {
if ("graphicFrame" === name) {
res = new AscFormat.CGraphicFrame();
res.fromXml(reader);
res = res.graphicObject;
}
return new CT_XmlNode();
});
elem.fromXml(reader);
return elem;
let oThis = this;
if(!res) {
if ("Choice" === name) {
let elem = new CT_XmlNode(function(reader, name) {
if(!res) {
res = window['AscFormat'].CGraphicObjectBase.prototype.fromXmlElem.call(oThis, reader, name, graphicFrame);
}
return true;
});
elem.fromXml(reader);
return elem;
}
else if("Fallback" === name) {
let elem = new CT_XmlNode(function(reader, name) {
if(!res) {
res = window['AscFormat'].CGraphicObjectBase.prototype.fromXmlElem.call(oThis, reader, name, graphicFrame);
}
return true;
});
elem.fromXml(reader);
return elem;
}
}
return true;
});
elem.fromXml(reader);
} else if ("slicer" === name) {
Expand Down Expand Up @@ -549,17 +561,63 @@
}
break;
}
case "m": {
let oThis = this;
let oMathNode = new CT_XmlNode(function (reader, name) {
switch (name) {
case "oMath":
CParagraphContentWithParagraphLikeContent.prototype.fromXmlElem.call(oThis, reader, name);
break;
case "oMathPara":
CParagraphContentWithParagraphLikeContent.prototype.fromXmlElem.call(oThis, reader, name);
break;
}
return true;
});
oMathNode.fromXml(reader);
break;
}
}
}
};
AscCommonWord.ParaHyperlink.prototype.toDrawingML = function(writer) {
for(let nIdx = 0; nIdx < this.Content.length; ++nIdx) {
let oElement = this.Content[nIdx];
if(oElement.toDrawingML) {
oElement.toDrawingML(writer);
oElement.toDrawingML(writer, nIdx, this.Paragraph);
}
}
};
ParaMath.prototype.toDrawingML = function(writer, index, paragraph) {
writer.WriteXmlNodeStart("mc:AlternateContent");
writer.WriteXmlAttributeString("xmlns:mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
writer.WriteXmlAttributeString("xmlns:m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
writer.WriteXmlAttributesEnd();

writer.WriteXmlNodeStart("mc:Choice");
writer.WriteXmlAttributeString("xmlns:a14", "http://schemas.microsoft.com/office/drawing/2010/main");
writer.WriteXmlAttributeString("Requires", "a14");
writer.WriteXmlAttributesEnd();

writer.WriteXmlNodeStart("a14:m");
writer.WriteXmlAttributesEnd();
if (paragraph.CheckMathPara(index)) {
let mathPara = new AscCommon.CT_OMathPara();
mathPara.setMath(this);
mathPara.toXml(writer, "m:oMathPara");
} else {
this.toXml(writer, "m:oMath");
}
writer.WriteXmlNodeEnd("a14:m");

writer.WriteXmlNodeEnd("mc:Choice");


writer.WriteXmlNodeStart("mc:Fallback");
writer.WriteXmlAttributesEnd(true);

writer.WriteXmlNodeEnd("mc:AlternateContent");
};
AscCommonWord.Paragraph.prototype.toDrawingML = function(writer) {
writer.WriteXmlNodeStart("a:p");
writer.WriteXmlAttributesEnd();
Expand All @@ -570,7 +628,9 @@

let nCount = this.Content.length;
for (let i = 0; i < nCount; ++i)
this.Content[i].toDrawingML(writer);
if(this.Content[i].toDrawingML) {
this.Content[i].toDrawingML(writer, i, this);
}

if(this.TextPr && this.TextPr.Value) {
this.TextPr.Value.toDrawingML(writer, "a:endParaRPr")
Expand Down
1 change: 1 addition & 0 deletions configs/cell.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"common/SerializeChartXml.js",
"common/SerializeMathXml.js",
"cell/model/SerializeXml.js",
"word/Editor/SerializeXml.js",
"word/Editor/SerializeXmlAssets.js"
],
"desktop": {
Expand Down
1 change: 1 addition & 0 deletions configs/slide.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@
"common/Shapes/SerializeXml.js",
"common/SerializeChartXml.js",
"common/SerializeMathXml.js",
"word/Editor/SerializeXml.js",
"word/Editor/SerializeXmlAssets.js"
],
"desktop": {
Expand Down
Loading

0 comments on commit 5b458af

Please sign in to comment.