Commit 1e2fcf55 authored by konovalovsergey's avatar konovalovsergey

open/save math spreadsheet and presentation

parent 83dbff9a
...@@ -12647,7 +12647,8 @@ function CorrectUniColor(asc_color, unicolor, flag) ...@@ -12647,7 +12647,8 @@ function CorrectUniColor(asc_color, unicolor, flag)
window['AscFormat'].PARRUN_TYPE_RUN = 1; window['AscFormat'].PARRUN_TYPE_RUN = 1;
window['AscFormat'].PARRUN_TYPE_FLD = 2; window['AscFormat'].PARRUN_TYPE_FLD = 2;
window['AscFormat'].PARRUN_TYPE_BR = 3; window['AscFormat'].PARRUN_TYPE_BR = 3;
window['AscFormat'].PARRUN_TYPE_TEXT_MATH = 4; window['AscFormat'].PARRUN_TYPE_MATH = 4;
window['AscFormat'].PARRUN_TYPE_MATHPARA = 5;
window['AscFormat']._weight_body = _weight_body; window['AscFormat']._weight_body = _weight_body;
window['AscFormat']._weight_chart = _weight_chart; window['AscFormat']._weight_chart = _weight_chart;
......
...@@ -160,6 +160,7 @@ function BinaryPPTYLoader() ...@@ -160,6 +160,7 @@ function BinaryPPTYLoader()
this.RebuildImages = []; this.RebuildImages = [];
this.textBodyTextFit = []; this.textBodyTextFit = [];
this.DocReadResult = null;
this.Start_UseFullUrl = function() this.Start_UseFullUrl = function()
{ {
...@@ -8062,6 +8063,42 @@ function BinaryPPTYLoader() ...@@ -8062,6 +8063,42 @@ function BinaryPPTYLoader()
} }
break; break;
} }
case AscFormat.PARRUN_TYPE_MATHPARA:
case AscFormat.PARRUN_TYPE_MATH:
{
var _end = s.cur + s.GetULong() + 4;
var _stream = new AscCommon.FT_Stream2();
_stream.data = s.data;
_stream.pos = s.pos;
_stream.cur = s.cur;
_stream.size = s.size;
var parContentOld = par.Content.length;
var oParStruct = new OpenParStruct(par, par);
if (!this.DocReadResult) {
this.DocReadResult = new AscCommonWord.DocReadResult(null);
}
var boMathr = new Binary_oMathReader(_stream, this.DocReadResult, null);
var nDocLength = _stream.GetULongLE();
if (AscFormat.PARRUN_TYPE_MATHPARA == _type) {
var props = {};
boMathr.bcr.Read1(nDocLength, function(t, l){
return boMathr.ReadMathOMathPara(t,l,oParStruct, props);
});
} else {
var oMath = new ParaMath();
oParStruct.addToContent(oMath);
boMathr.bcr.Read1(nDocLength, function(t, l){
return boMathr.ReadMathArg(t,l,oMath.Root,oParStruct);
});
oMath.Root.Correct_Content(true);
}
s.Seek2(_end);
EndPos += par.Content.length - parContentOld;
break;
}
default: default:
break; break;
} }
...@@ -8623,6 +8660,41 @@ function CPres() ...@@ -8623,6 +8660,41 @@ function CPres()
return oNewSpPr; return oNewSpPr;
}; };
this.ReadRunProperties = function(stream, type)
{
if (this.Reader == null)
this.Reader = new AscCommon.BinaryPPTYLoader();
var oLogicDocument = this.LogicDocument;
this.LogicDocument = null;
this.Reader.ImageMapChecker = this.ImageMapChecker;
if (null == this.stream)
{
this.stream = new AscCommon.FileStream();
this.stream.obj = stream.obj;
this.stream.data = stream.data;
this.stream.size = stream.size;
}
this.stream.pos = stream.pos;
this.stream.cur = stream.cur;
this.Reader.stream = this.stream;
var s = this.stream;
var _main_type = s.GetUChar(); // 0!!!
var oNewrPr = this.Reader.ReadRunProperties();
stream.pos = s.pos;
stream.cur = s.cur;
this.LogicDocument = oLogicDocument;
return oNewrPr;
};
this.ReadShape = function() this.ReadShape = function()
{ {
var s = this.stream; var s = this.stream;
......
...@@ -122,6 +122,7 @@ function CBinaryFileWriter() ...@@ -122,6 +122,7 @@ function CBinaryFileWriter()
this.IsUseFullUrl = false; this.IsUseFullUrl = false;
this.PresentationThemesOrigin = ""; this.PresentationThemesOrigin = "";
this.DocSaveParams = null;
var oThis = this; var oThis = this;
this.Start_UseFullUrl = function() this.Start_UseFullUrl = function()
...@@ -2714,6 +2715,39 @@ function CBinaryFileWriter() ...@@ -2714,6 +2715,39 @@ function CBinaryFileWriter()
break; break;
} }
case para_Math:
{
if (null != _elem.Root)
{
oThis.StartRecord(0); // subtype
oThis.StartRecord(AscFormat.PARRUN_TYPE_MATHPARA);
var _memory = new AscCommon.CMemory(true);
_memory.ImData = oThis.ImData;
_memory.data = oThis.data;
_memory.len = oThis.len;
_memory.pos = oThis.pos;
oThis.UseContinueWriter = true;
if (!oThis.DocSaveParams) {
oThis.DocSaveParams = new AscCommonWord.DocSaveParams(false, false);
}
var boMaths = new Binary_oMathWriter(_memory, null, oThis.DocSaveParams);
boMaths.bs.WriteItemWithLength(function(){boMaths.WriteOMathPara(_elem)});
oThis.ImData = _memory.ImData;
oThis.data = _memory.data;
oThis.len = _memory.len;
oThis.pos = _memory.pos;
oThis.UseContinueWriter = false;
_memory.ImData = null;
_memory.data = null;
oThis.EndRecord();
oThis.EndRecord();
_count++;
}
}
default: default:
break; break;
} }
...@@ -4491,6 +4525,44 @@ function CBinaryFileWriter() ...@@ -4491,6 +4525,44 @@ function CBinaryFileWriter()
_writer.WriteSpPr(spPr); _writer.WriteSpPr(spPr);
_writer.EndRecord(); _writer.EndRecord();
if (this.BinaryFileWriter.UseContinueWriter)
{
memory.ImData = this.BinaryFileWriter.ImData;
memory.data = this.BinaryFileWriter.data;
memory.len = this.BinaryFileWriter.len;
memory.pos = this.BinaryFileWriter.pos;
}
else
{
this.TreeDrawingIndex--;
var oldPos = this.arrayStackStarts[this.arrayStackStarts.length - 1];
memory.WriteBuffer(this.BinaryFileWriter.data, oldPos, this.BinaryFileWriter.pos - oldPos);
this.BinaryFileWriter.pos = oldPos;
this.arrayStackStarts.splice(this.arrayStackStarts.length - 1, 1);
}
}
this.WriteRunProperties = function(memory, rPr)
{
if (this.BinaryFileWriter.UseContinueWriter)
{
this.BinaryFileWriter.ImData = memory.ImData;
this.BinaryFileWriter.data = memory.data;
this.BinaryFileWriter.len = memory.len;
this.BinaryFileWriter.pos = memory.pos;
}
else
{
this.TreeDrawingIndex++;
this.arrayStackStarts.push(this.BinaryFileWriter.pos);
}
var _writer = this.BinaryFileWriter;
_writer.StartRecord(0);
_writer.WriteRunProperties(rPr);
_writer.EndRecord();
if (this.BinaryFileWriter.UseContinueWriter) if (this.BinaryFileWriter.UseContinueWriter)
{ {
memory.ImData = this.BinaryFileWriter.ImData; memory.ImData = this.BinaryFileWriter.ImData;
......
...@@ -727,7 +727,8 @@ var c_oSer_OMathContentType = { ...@@ -727,7 +727,8 @@ var c_oSer_OMathContentType = {
Run: 61, Run: 61,
Ins: 62, Ins: 62,
Del: 63, Del: 63,
columnbreak: 64 columnbreak: 64,
ARPr: 65
}; };
var c_oSer_HyperlinkType = { var c_oSer_HyperlinkType = {
Content: 0, Content: 0,
...@@ -1064,13 +1065,7 @@ function BinaryFileWriter(doc, bMailMergeDocx, bMailMergeHtml) ...@@ -1064,13 +1065,7 @@ function BinaryFileWriter(doc, bMailMergeDocx, bMailMergeHtml)
nNumIdIndex: null, nNumIdIndex: null,
oUsedStyleMap: null oUsedStyleMap: null
}; };
this.saveParams = { this.saveParams = new DocSaveParams(bMailMergeDocx, bMailMergeHtml);
bMailMergeDocx: bMailMergeDocx,
bMailMergeHtml: bMailMergeHtml,
trackRevisionId: 0,
footnotes: {},
footnotesIndex: 0
};
this.Write = function() this.Write = function()
{ {
pptx_content_writer._Start(); pptx_content_writer._Start();
...@@ -2466,6 +2461,11 @@ function Binary_oMathWriter(memory, oMathPara, saveParams) ...@@ -2466,6 +2461,11 @@ function Binary_oMathWriter(memory, oMathPara, saveParams)
this.bs.WriteItem(c_oSer_OMathContentType.RPr, function(){oThis.brPrs.Write_rPr(props.wRPrp, null, null);}); // w:rPr this.bs.WriteItem(c_oSer_OMathContentType.RPr, function(){oThis.brPrs.Write_rPr(props.wRPrp, null, null);}); // w:rPr
this.bs.WriteItem(c_oSer_OMathContentType.MRPr, function(){oThis.WriteMRPr(props.mathRPrp);}); // m:rPr this.bs.WriteItem(c_oSer_OMathContentType.MRPr, function(){oThis.WriteMRPr(props.mathRPrp);}); // m:rPr
// if (oMRun.ARPr) { // a:rPr
// this.bs.WriteItem(c_oSer_OMathContentType.ARPr, function(){
// pptx_content_writer.WriteRunProperties(oThis.memory, oMRun.ARPr);
// });
// }
this.bs.WriteItem(c_oSer_OMathContentType.MText,function(){oThis.WriteMText(oText.toString());}); // m:t this.bs.WriteItem(c_oSer_OMathContentType.MText,function(){oThis.WriteMText(oText.toString());}); // m:t
} }
this.WriteMText = function(sText) this.WriteMText = function(sText)
...@@ -5372,34 +5372,7 @@ function BinaryFileReader(doc, openParams) ...@@ -5372,34 +5372,7 @@ function BinaryFileReader(doc, openParams)
this.Document = doc; this.Document = doc;
this.openParams = openParams; this.openParams = openParams;
this.stream; this.stream;
this.oReadResult = { this.oReadResult = new DocReadResult(doc);
logicDocument: doc,
ImageMap: null,
oComments: null,
oCommentsPlaces: null,
setting: null,
numToNumClass: null,
paraNumPrs: null,
styles: null,
runStyles: null,
paraStyles: null,
tableStyles: null,
lvlStyles: null,
styleLinks: null,
numStyleLinks: null,
DefpPr: null,
DefrPr: null,
DocumentContent: null,
bLastRun: null,
aPostOpenStyleNumCallbacks: null,
headers: null,
footers: null,
trackRevisions: null,
drawingToMath: null,
aTableCorrect: null,
footnotes: null,
footnoteRefs: null
};
this.getbase64DecodedData = function(szSrc) this.getbase64DecodedData = function(szSrc)
{ {
...@@ -5559,29 +5532,6 @@ function BinaryFileReader(doc, openParams) ...@@ -5559,29 +5532,6 @@ function BinaryFileReader(doc, openParams)
} }
this.ReadMainTable = function() this.ReadMainTable = function()
{ {
this.oReadResult.ImageMap = {};
this.oReadResult.oComments = {};
this.oReadResult.oCommentsPlaces = {};
this.oReadResult.setting = {titlePg: false, EvenAndOddHeaders: false};
this.oReadResult.numToNumClass = {};
this.oReadResult.paraNumPrs = [];
this.oReadResult.styles = [];
this.oReadResult.runStyles = [];
this.oReadResult.paraStyles = [];
this.oReadResult.tableStyles = [];
this.oReadResult.lvlStyles = [];
this.oReadResult.styleLinks = [];
this.oReadResult.numStyleLinks = [];
this.oReadResult.DocumentContent = [];
this.oReadResult.bLastRun = null;
this.oReadResult.aPostOpenStyleNumCallbacks = [];
this.oReadResult.headers = [];
this.oReadResult.footers = [];
this.oReadResult.drawingToMath = [];
this.oReadResult.aTableCorrect = [];
this.oReadResult.footnotes = {};
this.oReadResult.footnoteRefs = [];
var res = c_oSerConstants.ReadOk; var res = c_oSerConstants.ReadOk;
//mtLen //mtLen
res = this.stream.EnterFrame(1); res = this.stream.EnterFrame(1);
...@@ -5967,6 +5917,7 @@ function BinaryFileReader(doc, openParams) ...@@ -5967,6 +5917,7 @@ function BinaryFileReader(doc, openParams)
if(null != this.oReadResult.DefrPr) if(null != this.oReadResult.DefrPr)
this.Document.Styles.Default.TextPr.Merge( this.oReadResult.DefrPr ); this.Document.Styles.Default.TextPr.Merge( this.oReadResult.DefrPr );
//Footnotes strict after style //Footnotes strict after style
if (this.oReadResult.logicDocument) {
this.oReadResult.logicDocument.Footnotes.ResetSpecialFootnotes(); this.oReadResult.logicDocument.Footnotes.ResetSpecialFootnotes();
for (var i = 0; i < this.oReadResult.footnoteRefs.length; ++i) { for (var i = 0; i < this.oReadResult.footnoteRefs.length; ++i) {
var footnote = this.oReadResult.footnotes[this.oReadResult.footnoteRefs[i]]; var footnote = this.oReadResult.footnotes[this.oReadResult.footnoteRefs[i]];
...@@ -5978,6 +5929,7 @@ function BinaryFileReader(doc, openParams) ...@@ -5978,6 +5929,7 @@ function BinaryFileReader(doc, openParams)
this.oReadResult.logicDocument.Footnotes.SetSeparator(footnote.content); this.oReadResult.logicDocument.Footnotes.SetSeparator(footnote.content);
} }
} }
}
var setting = this.oReadResult.setting; var setting = this.oReadResult.setting;
var fInitCommentData = function(comment) var fInitCommentData = function(comment)
...@@ -8610,7 +8562,7 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, curFoo ...@@ -8610,7 +8562,7 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, curFoo
} }
else if ( c_oSerParType.Content === type ) else if ( c_oSerParType.Content === type )
{ {
var oParStruct = new OpenParStruct(paragraph, Content, paragraph); var oParStruct = new OpenParStruct(paragraph, paragraph);
//для случая гиперссылок на несколько строк в конце параграфа завершаем начатые, а начале - продолжаем незавершенные //для случая гиперссылок на несколько строк в конце параграфа завершаем начатые, а начале - продолжаем незавершенные
if (this.aFields.length > 0) { if (this.aFields.length > 0) {
for (var i = 0; i < this.aFields.length; ++i) { for (var i = 0; i < this.aFields.length; ++i) {
...@@ -8788,7 +8740,7 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, curFoo ...@@ -8788,7 +8740,7 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, curFoo
} }
else if (c_oSer_FldSimpleType.Content === type) { else if (c_oSer_FldSimpleType.Content === type) {
if(null != oFldSimpleObj.ParaField) { if(null != oFldSimpleObj.ParaField) {
var oFldStruct = new OpenParStruct(oFldSimpleObj.ParaField, oParStruct.Content, oParStruct.paragraph); var oFldStruct = new OpenParStruct(oFldSimpleObj.ParaField, oParStruct.paragraph);
res = this.bcr.Read1(length, function (t, l) { res = this.bcr.Read1(length, function (t, l) {
return oThis.ReadParagraphContent(t, l, oFldStruct); return oThis.ReadParagraphContent(t, l, oFldStruct);
}); });
...@@ -8825,7 +8777,7 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, curFoo ...@@ -8825,7 +8777,7 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, curFoo
oHyperlinkObj.TgtFrame = this.stream.GetString2LE(length); oHyperlinkObj.TgtFrame = this.stream.GetString2LE(length);
} }
else if (c_oSer_HyperlinkType.Content === type) { else if (c_oSer_HyperlinkType.Content === type) {
var oHypStruct = new OpenParStruct(oNewHyperlink, oParStruct.Content, oParStruct.paragraph); var oHypStruct = new OpenParStruct(oNewHyperlink, oParStruct.paragraph);
res = this.bcr.Read1(length, function (t, l) { res = this.bcr.Read1(length, function (t, l) {
return oThis.ReadParagraphContent(t, l, oHypStruct); return oThis.ReadParagraphContent(t, l, oHypStruct);
}); });
...@@ -8972,34 +8924,6 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, curFoo ...@@ -8972,34 +8924,6 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, curFoo
if(null != oDrawing.content.GraphicObj) if(null != oDrawing.content.GraphicObj)
oNewElem = oDrawing.content; oNewElem = oDrawing.content;
} }
else if(c_oSerRunType.table === type)
{
var doc = this.Document;
var oNewTable = new CTable(doc.DrawingDocument, doc, true, 0, 0, 0, 0, 0, 0, 0, []);
res = this.bcr.Read1(length, function(t, l){
return oThis.ReadDocTable(t, l, oNewTable);
});
if (oNewTable.Content.length > 0) {
oNewTable.ReIndexing(0);
oNewTable.Correct_BadTable();
if(2 == AscCommon.CurFileVersion && false == oNewTable.Inline)
{
//делаем смещение левой границы
if(false == oNewTable.PositionH.Align)
{
var dx = Get_TableOffsetCorrection(oNewTable);
oNewTable.PositionH.Value += dx;
}
}
if(null != this.lastPar)
{
oNewTable.Set_DocumentPrev(this.lastPar);
this.lastPar.Set_DocumentNext(oNewTable);
}
this.lastPar = oNewTable;
oParStruct.DocContent.push(oNewTable);
}
}
else if(c_oSerRunType.fldstart === type) else if(c_oSerRunType.fldstart === type)
{ {
oRes.bRes = false; oRes.bRes = false;
...@@ -9069,7 +8993,7 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, curFoo ...@@ -9069,7 +8993,7 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, curFoo
return oThis.ReadFootnoteRef(t, l, ref); return oThis.ReadFootnoteRef(t, l, ref);
}); });
var footnote = this.oReadResult.footnotes[ref.id]; var footnote = this.oReadResult.footnotes[ref.id];
if (footnote) { if (footnote && this.oReadResult.logicDocument) {
this.oReadResult.logicDocument.Footnotes.AddFootnote(footnote.content); this.oReadResult.logicDocument.Footnotes.AddFootnote(footnote.content);
oNewElem = new ParaFootnoteReference(footnote.content, ref.customMark); oNewElem = new ParaFootnoteReference(footnote.content, ref.customMark);
} }
...@@ -11440,6 +11364,11 @@ function Binary_oMathReader(stream, oReadResult, curFootnote) ...@@ -11440,6 +11364,11 @@ function Binary_oMathReader(stream, oReadResult, curFootnote)
return oThis.ReadMathMRPr(t,l,mrPr); return oThis.ReadMathMRPr(t,l,mrPr);
}); });
oMRun.Set_MathPr(mrPr); oMRun.Set_MathPr(mrPr);
}
else if (c_oSer_OMathContentType.ARPr === type)
{
var rPr = pptx_content_loader.ReadRunProperties(this.stream);
//oMRun.ARPr = rPr;
} }
else if (c_oSer_OMathContentType.RPr === type) else if (c_oSer_OMathContentType.RPr === type)
{ {
...@@ -12604,6 +12533,7 @@ function Binary_SettingsTableReader(doc, oReadResult, stream) ...@@ -12604,6 +12533,7 @@ function Binary_SettingsTableReader(doc, oReadResult, stream)
res = this.bcr.Read1(length, function(t, l) { res = this.bcr.Read1(length, function(t, l) {
return oThis.bpPrr.ReadFootnotePr(t, l, props); return oThis.bpPrr.ReadFootnotePr(t, l, props);
}); });
if (this.oReadResult.logicDocument) {
var footnotes = this.oReadResult.logicDocument.Footnotes; var footnotes = this.oReadResult.logicDocument.Footnotes;
if (null != props.fmt) { if (null != props.fmt) {
footnotes.SetFootnotePrNumFormat(props.fmt); footnotes.SetFootnotePrNumFormat(props.fmt);
...@@ -12618,6 +12548,7 @@ function Binary_SettingsTableReader(doc, oReadResult, stream) ...@@ -12618,6 +12548,7 @@ function Binary_SettingsTableReader(doc, oReadResult, stream)
footnotes.SetFootnotePrPos(props.pos); footnotes.SetFootnotePrPos(props.pos);
} }
} }
}
else else
res = c_oSerConstants.ReadUnknown; res = c_oSerConstants.ReadUnknown;
return res; return res;
...@@ -13237,8 +13168,7 @@ function getStyleFirstRun(oField){ ...@@ -13237,8 +13168,7 @@ function getStyleFirstRun(oField){
} }
return res; return res;
} }
function OpenParStruct(oContainer, Content, paragraph) { function OpenParStruct(oContainer, paragraph) {
this.DocContent = Content;
this.paragraph = paragraph; this.paragraph = paragraph;
this.cur = { pos: 0, elem: oContainer }; this.cur = { pos: 0, elem: oContainer };
this.stack = [this.cur]; this.stack = [this.cur];
...@@ -13319,9 +13249,45 @@ OpenParStruct.prototype = { ...@@ -13319,9 +13249,45 @@ OpenParStruct.prototype = {
return this.cur.pos; return this.cur.pos;
} }
} }
function DocSaveParams(bMailMergeDocx, bMailMergeHtml) {
this.bMailMergeDocx = bMailMergeDocx;
this.bMailMergeHtml = bMailMergeHtml;
this.trackRevisionId = 0;
this.footnotes = {};
this.footnotesIndex = 0;
};
function DocReadResult(doc) {
this.logicDocument = doc;
this.ImageMap = {};
this.oComments = {};
this.oCommentsPlaces = {};
this.setting = {titlePg: false, EvenAndOddHeaders: false};
this.numToNumClass = {};
this.paraNumPrs = [];
this.styles = [];
this.runStyles = [];
this.paraStyles = [];
this.tableStyles = [];
this.lvlStyles = [];
this.styleLinks = [];
this.numStyleLinks = [];
this.DefpPr = null;
this.DefrPr = null;
this.DocumentContent = [];
this.bLastRun = null;
this.aPostOpenStyleNumCallbacks = [];
this.headers = [];
this.footers = [];
this.trackRevisions = null;
this.drawingToMath = [];
this.aTableCorrect = [];
this.footnotes = {};
this.footnoteRefs = []
};
//---------------------------------------------------------export--------------------------------------------------- //---------------------------------------------------------export---------------------------------------------------
window['AscCommonWord'] = window['AscCommonWord'] || {}; window['AscCommonWord'] = window['AscCommonWord'] || {};
window["AscCommonWord"].BinaryFileReader = BinaryFileReader; window["AscCommonWord"].BinaryFileReader = BinaryFileReader;
window["AscCommonWord"].BinaryFileWriter = BinaryFileWriter; window["AscCommonWord"].BinaryFileWriter = BinaryFileWriter;
window["AscCommonWord"].EThemeColor = EThemeColor; window["AscCommonWord"].EThemeColor = EThemeColor;
window["AscCommonWord"].DocReadResult = DocReadResult;
window["AscCommonWord"].DocSaveParams = DocSaveParams;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment