Commit cf1786de authored by Sergey Konovalov's avatar Sergey Konovalov

open/save Sdt

parent a688ab64
......@@ -360,7 +360,8 @@ var c_oSerParType = {
FldSimple: 11,
Del: 12,
Ins: 13,
Background: 14
Background: 14,
Sdt: 15
};
var c_oSerDocTableType = {
tblPr:0,
......@@ -373,7 +374,8 @@ var c_oSerDocTableType = {
Cell: 6,
Cell_Pr: 7,
Cell_Content: 8,
tblGridChange: 9
tblGridChange: 9,
Sdt: 10
};
var c_oSerRunType = {
run:0,
......@@ -816,6 +818,44 @@ var c_oSerBackgroundType = {
ColorTheme: 1,
pptxDrawing: 2
};
var c_oSerSdt = {
Pr: 0,
EndPr: 1,
Content: 2,
Type: 3,
Alias: 4,
ComboBox: 5,
LastValue: 6,
SdtListItem: 7,
DisplayText: 8,
Value: 9,
DataBinding: 10,
PrefixMappings: 11,
StoreItemID: 12,
XPath: 13,
PrDate: 14,
FullDate: 15,
Calendar: 16,
DateFormat: 17,
Lid: 18,
StoreMappedDataAs: 19,
DocPartList: 20,
DocPartObj: 21,
DocPartCategory: 22,
DocPartGallery: 23,
DocPartUnique: 24,
DropDownList: 25,
Id: 26,
Label: 27,
Lock: 28,
PlaceHolder: 29,
RPr: 30,
ShowingPlcHdr: 31,
TabIndex: 32,
Tag: 33,
Temporary: 34,
MultiLine: 35
};
var ETblStyleOverrideType = {
tblstyleoverridetypeBand1Horz: 0,
tblstyleoverridetypeBand1Vert: 1,
......@@ -1204,6 +1244,14 @@ function BinaryFileWriter(doc, bMailMergeDocx, bMailMergeHtml)
this.bs.WriteItem(c_oSerParType.Table, function(){oThis.copyParams.bdtw.WriteDocTable(Item, aRowElems, nMinGrid, nMaxGrid);});
this.copyParams.itemCount++;
}
this.CopySdt = function(Item)
{
if(this.copyParams.bLockCopyElems > 0)
return;
var oThis = this;
this.bs.WriteItem(c_oSerParType.Sdt, function(){oThis.copyParams.bdtw.WriteSdt(Item);});
this.copyParams.itemCount++;
}
this.CopyEnd = function()
{
this.bs.WriteItemWithLengthEnd(this.copyParams.nDocumentWriterPos);
......@@ -4089,6 +4137,11 @@ function BinaryDocumentTableWriter(memory, doc, oMapCommentId, oNumIdMap, copyPa
this.memory.WriteByte(c_oSerParType.Table);
this.bs.WriteItemWithLength(function(){oThis.WriteDocTable(item);});
}
else if(type_BlockLevelSdt === item.GetType())
{
this.memory.WriteByte(c_oSerParType.Sdt);
this.bs.WriteItemWithLength(function(){oThis.WriteSdt(item);});
}
}
if(true == bSectPr)
{
......@@ -5104,6 +5157,157 @@ function BinaryDocumentTableWriter(memory, doc, oMapCommentId, oNumIdMap, copyPa
oThis.bs.WriteItem(c_oSerParType.OMath, function(){oThis.boMaths.WriteArgNodes(obj.ParaMath.Root);});
oThis.bs.WriteItem(c_oSerRunType.pptxDrawing, function () { oThis.WriteImage(obj); });
};
this.WriteSdt = function (oSdt)
{
var oThis = this;
// if (oSdt.Pr) {
// oThis.bs.WriteItem(c_oSerSdt.Pr, function () { oThis.WriteSdtPr(oSdt.Pr); });
// }
// if (oSdt.EndPr) {
// this.bs.WriteItem(c_oSerSdt.EndPr, function(){oThis.brPrs.Write_rPr(oSdt.EndPr, null, null);});
// }
var oInnerDocument = new BinaryDocumentTableWriter(this.memory, this.Document, this.oMapCommentId, this.oNumIdMap, this.copyParams, this.saveParams, this.oBinaryHeaderFooterTableWriter);
this.bs.WriteItem(c_oSerSdt.Content, function(){oInnerDocument.WriteDocumentContent(oSdt.Content);});
};
this.WriteSdtPr = function (val)
{
var oThis = this;
if (null != val.Type) {
oThis.bs.WriteItem(c_oSerSdt.Type, function (){oThis.memory.WriteByte(val.Type);});
}
if (null != val.Alias) {
this.memory.WriteByte(c_oSerSdt.Alias);
this.memory.WriteString2(val.Alias);
}
if (null != val.ComboBox) {
oThis.bs.WriteItem(c_oSerSdt.ComboBox, function (){oThis.WriteSdtComboBox(val.ComboBox);});
}
if (null != val.DataBinding) {
oThis.bs.WriteItem(c_oSerSdt.DataBinding, function (){oThis.WriteSdtPrDataBinding(val.DataBinding);});
}
if (null != val.PrDate) {
oThis.bs.WriteItem(c_oSerSdt.PrDate, function (){oThis.WriteSdtPrDate(val.PrDate);});
}
if (null != val.DocPartList) {
oThis.bs.WriteItem(c_oSerSdt.DocPartList, function (){oThis.WriteDocPartList(val.DocPartList);});
}
if (null != val.DocPartObj) {
oThis.bs.WriteItem(c_oSerSdt.DocPartObj, function (){oThis.WriteDocPartList(val.DocPartObj);});
}
if (null != val.DropDownList) {
oThis.bs.WriteItem(c_oSerSdt.DropDownList, function (){oThis.WriteSdtComboBox(val.DropDownList);});
}
if (null != val.Id) {
oThis.bs.WriteItem(c_oSerSdt.Id, function (){oThis.memory.WriteLong(val.Id);});
}
if (null != val.Label) {
oThis.bs.WriteItem(c_oSerSdt.Label, function (){oThis.memory.WriteLong(val.Label);});
}
if (null != val.Lock) {
oThis.bs.WriteItem(c_oSerSdt.Lock, function (){oThis.memory.WriteByte(val.Lock);});
}
if (null != val.PlaceHolder) {
this.memory.WriteByte(c_oSerSdt.PlaceHolder);
this.memory.WriteString2(val.PlaceHolder);
}
if (null != val.RPr) {
this.bs.WriteItem(c_oSerSdt.RPr, function(){oThis.brPrs.Write_rPr(val.RPr, null, null);});
}
if (null != val.ShowingPlcHdr) {
oThis.bs.WriteItem(c_oSerSdt.ShowingPlcHdr, function (){oThis.memory.WriteBool(val.ShowingPlcHdr);});
}
if (null != val.TabIndex) {
oThis.bs.WriteItem(c_oSerSdt.TabIndex, function (){oThis.memory.WriteLong(val.TabIndex);});
}
if (null != val.Tag) {
this.memory.WriteByte(c_oSerSdt.Tag);
this.memory.WriteString2(val.Tag);
}
if (null != val.Temporary) {
oThis.bs.WriteItem(c_oSerSdt.Temporary, function (){oThis.memory.WriteBool(val.Temporary);});
}
if (null != val.MultiLine) {
oThis.bs.WriteItem(c_oSerSdt.MultiLine, function (){oThis.memory.WriteBool(val.MultiLine);});
}
};
this.WriteSdtComboBox = function (val)
{
var oThis = this;
if (null != val.LastValue) {
this.memory.WriteByte(c_oSerSdt.LastValue);
this.memory.WriteString2(val.LastValue);
}
if (null != val.List) {
for(var i = 0 ; i < val.List.length; ++i){
oThis.bs.WriteItem(c_oSerSdt.SdtListItem, function (){oThis.WriteSdtListItem(val.List[i]);});
}
}
};
this.WriteSdtListItem = function (val)
{
var oThis = this;
if (null != val.DisplayText) {
this.memory.WriteByte(c_oSerSdt.DisplayText);
this.memory.WriteString2(val.DisplayText);
}
if (null != val.Value) {
this.memory.WriteByte(c_oSerSdt.Value);
this.memory.WriteString2(val.Value);
}
};
this.WriteSdtPrDataBinding = function (val)
{
var oThis = this;
if (null != val.PrefixMappings) {
this.memory.WriteByte(c_oSerSdt.PrefixMappings);
this.memory.WriteString2(val.PrefixMappings);
}
if (null != val.StoreItemID) {
this.memory.WriteByte(c_oSerSdt.StoreItemID);
this.memory.WriteString2(val.StoreItemID);
}
if (null != val.XPath) {
this.memory.WriteByte(c_oSerSdt.XPath);
this.memory.WriteString2(val.XPath);
}
};
this.WriteSdtPrDate = function (val)
{
var oThis = this;
if (null != val.FullDate) {
this.memory.WriteByte(c_oSerSdt.FullDate);
this.memory.WriteString2(val.FullDate);
}
if (null != val.Calendar) {
oThis.bs.WriteItem(c_oSerSdt.Calendar, function (){oThis.memory.WriteByte(val.Calendar);});
}
if (null != val.DateFormat) {
this.memory.WriteByte(c_oSerSdt.DateFormat);
this.memory.WriteString2(val.DateFormat);
}
if (null != val.Lid) {
this.memory.WriteByte(c_oSerSdt.Lid);
this.memory.WriteString2(val.Lid);
}
if (null != val.StoreMappedDataAs) {
oThis.bs.WriteItem(c_oSerSdt.StoreMappedDataAs, function (){oThis.memory.WriteByte(val.StoreMappedDataAs);});
}
};
this.WriteDocPartList = function (val)
{
var oThis = this;
if (null != val.DocPartCategory) {
this.memory.WriteByte(c_oSerSdt.DocPartCategory);
this.memory.WriteString2(val.DocPartCategory);
}
if (null != val.DocPartGallery) {
this.memory.WriteByte(c_oSerSdt.DocPartGallery);
this.memory.WriteString2(val.DocPartGallery);
}
if (null != val.DocPartUnique) {
oThis.bs.WriteItem(c_oSerSdt.DocPartUnique, function (){oThis.memory.WriteBool(val.DocPartUnique);});
}
};
};
function BinaryOtherTableWriter(memory, doc)
{
......@@ -8714,6 +8918,19 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, curFoo
}
}
}
} else if ( c_oSerParType.Sdt === type) {
var oSdt = new AscCommonWord.CBlockLevelSdt(this.oReadResult.logicDocument, this.Document);
res = this.bcr.Read1(length, function(t, l){
return oThis.ReadSdt(t,l, oSdt, 0);
});
//Prev/Next
if(null != this.lastPar)
{
oSdt.Set_DocumentPrev(this.lastPar);
this.lastPar.Set_DocumentNext(oSdt);
}
this.lastPar = oSdt;
Content.push(oSdt);
// } else if ( c_oSerParType.Background === type ) {
// oThis.Document.Background = {Color: null, Unifill: null, shape: null};
// res = this.bcr.Read2(length, function(t, l){
......@@ -8929,8 +9146,11 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, curFoo
elem.Set_ReviewTypeWithInfo(reviewtype_Add, reviewInfo);
}
}
}
else
} else if ( c_oSerParType.Sdt === type) {
res = this.bcr.Read1(length, function(t, l) {
return oThis.ReadSdt(t, l, null, 1, oParStruct);
});
} else
res = c_oSerConstants.ReadUnknown;
return res;
};
......@@ -9917,8 +10137,11 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, curFoo
res = this.bcr.Read1(length, function(t, l){
return oThis.Read_Row(t, l, row);
});
}
else
} else if( c_oSerDocTableType.Sdt === type ) {
res = this.bcr.Read1(length, function(t, l){
return oThis.ReadSdt(t,l, null, 2, table);
});
} else
res = c_oSerConstants.ReadUnknown;
return res;
};
......@@ -9955,8 +10178,11 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, curFoo
res = this.bcr.Read1(length, function(t, l){
return oThis.ReadCell(t, l, oCell);
});
}
else
} else if( c_oSerDocTableType.Sdt === type ) {
res = this.bcr.Read1(length, function(t, l){
return oThis.ReadSdt(t,l, null, 3, row);
});
} else
res = c_oSerConstants.ReadUnknown;
return res;
};
......@@ -9985,7 +10211,7 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, curFoo
{
for(var i = 0; i < oCellContent.length; ++i)
{
if(i == length - 1)
if(i == oCellContent.length - 1)
cell.Content.Internal_Content_Add(i + 1, oCellContent[i], true);
else
cell.Content.Internal_Content_Add(i + 1, oCellContent[i], false);
......@@ -10000,6 +10226,205 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, curFoo
res = c_oSerConstants.ReadUnknown;
return res;
};
this.ReadSdt = function(type, length, oSdt, typeContainer, container) {
var res = c_oSerConstants.ReadOk;
var oThis = this;
if (c_oSerSdt.Pr === type) {
res = c_oSerConstants.ReadUnknown;
// if (0 === typeContainer) {
// oSdt.Pr = {};
// res = this.bcr.Read1(length, function(t, l) {
// return oThis.ReadSdtPr(t, l, oSdt.Pr);
// });
// } else {
// res = c_oSerConstants.ReadUnknown;
// }
} else if (c_oSerSdt.EndPr === type) {
res = c_oSerConstants.ReadUnknown;
// if (0 === typeContainer) {
// oSdt.EndPr = new CTextPr();
// res = this.brPrr.Read(length, oSdt.EndPr, null);
// } else {
// res = c_oSerConstants.ReadUnknown;
// }
} else if (c_oSerSdt.Content === type) {
if (0 === typeContainer) {
var oSdtContent = [];
var oSdtContentReader = new Binary_DocumentTableReader(oSdt.Content, this.oReadResult, this.openParams,
this.stream, this.curFootnote, this.oComments);
oSdtContentReader.aFields = this.aFields;
oSdtContentReader.nCurCommentsCount = this.nCurCommentsCount;
oSdtContentReader.oCurComments = this.oCurComments;
oSdtContentReader.Read(length, oSdtContent);
this.nCurCommentsCount = oSdtContentReader.nCurCommentsCount;
if (oSdtContent.length > 0) {
for (var i = 0; i < oSdtContent.length; ++i) {
if (i == oSdtContent.length - 1) {
oSdt.Content.Internal_Content_Add(i + 1, oSdtContent[i], true);
} else {
oSdt.Content.Internal_Content_Add(i + 1, oSdtContent[i], false);
}
}
oSdt.Content.Internal_Content_Remove(0, 1);
}
} else if (1 === typeContainer) {
res = this.bcr.Read1(length, function(t, l) {
return oThis.ReadParagraphContent(t, l, container);
});
} else if (2 === typeContainer) {
res = this.bcr.Read1(length, function(t, l) {
return oThis.Read_TableContent(t, l, container);
});
} else if (3 === typeContainer) {
res = this.bcr.Read1(length, function(t, l) {
return oThis.ReadRowContent(t, l, container);
});
}
} else {
res = c_oSerConstants.ReadUnknown;
}
return res;
};
this.ReadSdtPr = function(type, length, oSdtPr) {
var res = c_oSerConstants.ReadOk;
var oThis = this;
if (c_oSerSdt.Type === type) {
oSdtPr.Type = this.stream.GetByte();
} else if (c_oSerSdt.Alias === type) {
oSdtPr.Alias = this.stream.GetString2LE(length);
} else if (c_oSerSdt.ComboBox === type) {
oSdtPr.ComboBox = {};
res = this.bcr.Read1(length, function(t, l) {
return oThis.ReadSdtComboBox(t, l, oSdtPr.ComboBox);
});
} else if (c_oSerSdt.DataBinding === type) {
oSdtPr.DataBinding = {};
res = this.bcr.Read1(length, function(t, l) {
return oThis.ReadSdtPrDataBinding(t, l, oSdtPr.DataBinding);
});
} else if (c_oSerSdt.PrDate === type) {
oSdtPr.PrDate = {};
res = this.bcr.Read1(length, function(t, l) {
return oThis.ReadSdtPrDate(t, l, oSdtPr.PrDate);
});
} else if (c_oSerSdt.DocPartList === type) {
oSdtPr.DocPartList = {};
res = this.bcr.Read1(length, function(t, l) {
return oThis.ReadDocPartList(t, l, oSdtPr.DocPartList);
});
} else if (c_oSerSdt.DocPartObj === type) {
oSdtPr.DocPartObj = {};
res = this.bcr.Read1(length, function(t, l) {
return oThis.ReadDocPartList(t, l, oSdtPr.DocPartObj);
});
} else if (c_oSerSdt.DropDownList === type) {
oSdtPr.DropDownList = {};
res = this.bcr.Read1(length, function(t, l) {
return oThis.ReadSdtComboBox(t, l, oSdtPr.DropDownList);
});
} else if (c_oSerSdt.Id === type) {
oSdtPr.Id = this.stream.GetLongLE();
} else if (c_oSerSdt.Label === type) {
oSdtPr.Label = this.stream.GetLongLE();
} else if (c_oSerSdt.Lock === type) {
oSdtPr.Lock = this.stream.GetByte();
} else if (c_oSerSdt.PlaceHolder === type) {
oSdtPr.PlaceHolder = this.stream.GetString2LE(length);
} else if (c_oSerSdt.RPr === type) {
oSdtPr.RPr = new CTextPr();
res = this.brPrr.Read(length, oSdtPr.RPr, null);
} else if (c_oSerSdt.ShowingPlcHdr === type) {
oSdtPr.ShowingPlcHdr = (this.stream.GetUChar() != 0);
} else if (c_oSerSdt.TabIndex === type) {
oSdtPr.TabIndex = this.stream.GetLongLE();
} else if (c_oSerSdt.Tag === type) {
oSdtPr.Tag = this.stream.GetString2LE(length);
} else if (c_oSerSdt.Temporary === type) {
oSdtPr.Temporary = (this.stream.GetUChar() != 0);
} else if (c_oSerSdt.MultiLine === type) {
oSdtPr.MultiLine = (this.stream.GetUChar() != 0);
} else {
res = c_oSerConstants.ReadUnknown;
}
return res;
};
this.ReadSdtComboBox = function(type, length, val) {
var res = c_oSerConstants.ReadOk;
var oThis = this;
if (c_oSerSdt.LastValue === type) {
val.LastValue = this.stream.GetString2LE(length);
} else if (c_oSerSdt.SdtListItem === type) {
var listItem = {};
res = this.bcr.Read1(length, function(t, l) {
return oThis.ReadSdtListItem(t, l, listItem);
});
if (!val.List) {
val.List = [];
}
val.List.push(listItem);
} else {
res = c_oSerConstants.ReadUnknown;
}
return res;
};
this.ReadSdtListItem = function(type, length, val) {
var res = c_oSerConstants.ReadOk;
var oThis = this;
if (c_oSerSdt.DisplayText === type) {
val.DisplayText = this.stream.GetString2LE(length);
} else if (c_oSerSdt.Value === type) {
val.Value = this.stream.GetString2LE(length);
} else {
res = c_oSerConstants.ReadUnknown;
}
return res;
};
this.ReadSdtPrDataBinding = function(type, length, val) {
var res = c_oSerConstants.ReadOk;
var oThis = this;
if (c_oSerSdt.PrefixMappings === type) {
val.PrefixMappings = this.stream.GetString2LE(length);
} else if (c_oSerSdt.StoreItemID === type) {
val.StoreItemID = this.stream.GetString2LE(length);
} else if (c_oSerSdt.XPath === type) {
val.XPath = this.stream.GetString2LE(length);
} else {
res = c_oSerConstants.ReadUnknown;
}
return res;
};
this.ReadSdtPrDate = function(type, length, val) {
var res = c_oSerConstants.ReadOk;
var oThis = this;
if (c_oSerSdt.FullDate === type) {
val.FullDate = this.stream.GetString2LE(length);
} else if (c_oSerSdt.Calendar === type) {
val.Calendar = this.stream.GetUChar();
} else if (c_oSerSdt.DateFormat === type) {
val.DateFormat = this.stream.GetString2LE(length);
} else if (c_oSerSdt.Lid === type) {
val.Lid = this.stream.GetString2LE(length);
} else if (c_oSerSdt.StoreMappedDataAs === type) {
val.StoreMappedDataAs = this.stream.GetUChar();
} else {
res = c_oSerConstants.ReadUnknown;
}
return res;
};
this.ReadDocPartList = function(type, length, val) {
var res = c_oSerConstants.ReadOk;
var oThis = this;
if (c_oSerSdt.DocPartCategory === type) {
val.DocPartCategory = this.stream.GetString2LE(length);
} else if (c_oSerSdt.DocPartGallery === type) {
val.DocPartGallery = this.stream.GetString2LE(length);
} else if (c_oSerSdt.DocPartUnique === type) {
val.DocPartUnique = (this.stream.GetUChar() != 0);
} else {
res = c_oSerConstants.ReadUnknown;
}
return res;
};
};
function Binary_oMathReader(stream, oReadResult, curFootnote)
{
......
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