Commit 658338ad authored by Sergey.Konovalov's avatar Sergey.Konovalov Committed by Alexander.Trofimov

на открытие Document.Styles.Add/Remove вместо присваивания

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@62131 954022d7-b5bf-4e40-9824-e11837661b57
parent c6685110
...@@ -4917,6 +4917,7 @@ function BinaryFileReader(doc, openParams) ...@@ -4917,6 +4917,7 @@ function BinaryFileReader(doc, openParams)
else else
numPr.NumId = 0; numPr.NumId = 0;
} }
var oDocStyle = this.Document.Styles;
var styles = this.Document.Styles.Style; var styles = this.Document.Styles.Style;
var stDefault = this.Document.Styles.Default; var stDefault = this.Document.Styles.Default;
if(g_nCurFileVersion < 2){ if(g_nCurFileVersion < 2){
...@@ -4933,12 +4934,15 @@ function BinaryFileReader(doc, openParams) ...@@ -4933,12 +4934,15 @@ function BinaryFileReader(doc, openParams)
} }
//запоминаем default стили имена или id которых совпали с стилями открываемого документа и ссылки на них надо подменить //запоминаем default стили имена или id которых совпали с стилями открываемого документа и ссылки на них надо подменить
var oIdRenameMap = {}; var oIdRenameMap = {};
var oIdMap = {};
//Удаляем стили с тем же именем //Удаляем стили с тем же именем
for(var i in this.oReadResult.styles) for(var i in this.oReadResult.styles)
{ {
var elem = this.oReadResult.styles[i]; var elem = this.oReadResult.styles[i];
var oNewStyle = elem.style; var oNewStyle = elem.style;
var sNewStyleId = oNewStyle.Get_Id();
var oNewId = elem.param; var oNewId = elem.param;
oIdMap[oNewId.id] = sNewStyleId;
//такой код для сранения имен есть в DrawingDocument.js //такой код для сранения имен есть в DrawingDocument.js
// как только меняется DrawingDocument - меняется и код здесь. // как только меняется DrawingDocument - меняется и код здесь.
var sNewStyleName = oNewStyle.Name.toLowerCase().replace(/\s/g,""); var sNewStyleName = oNewStyle.Name.toLowerCase().replace(/\s/g,"");
...@@ -4947,29 +4951,8 @@ function BinaryFileReader(doc, openParams) ...@@ -4947,29 +4951,8 @@ function BinaryFileReader(doc, openParams)
{ {
var stId = oStartDocStyle.Get_Id(); var stId = oStartDocStyle.Get_Id();
oNewStyle.Set_Name(oStartDocStyle.Name); oNewStyle.Set_Name(oStartDocStyle.Name);
oIdRenameMap[stId] = {id: oNewId.id, def: oNewId.def, type: oNewStyle.Type, newName: sNewStyleName}; oIdRenameMap[stId] = {id: sNewStyleId, def: oNewId.def, type: oNewStyle.Type, newName: sNewStyleName};
delete styles[stId]; oDocStyle.Remove(stId);
}
}
//заменяем id стилей по умолчанию если они, если они совпали со стилями открываемого документа
for(var i in this.oReadResult.styles)
{
var elem = this.oReadResult.styles[i];
var oNewStyle = elem.style;
var oNewId = elem.param;
var oCollisionStyle = styles[oNewId.id];
if(oCollisionStyle)
{
var sOldId = oCollisionStyle.Get_Id();
var nCounter = 1;
var sNewId = g_oIdCounter.Get_NewId();
var oNewId = {id: sNewId, def: false, type: oCollisionStyle.Type, newName: oCollisionStyle.Name.toLowerCase().replace(/\s/g,"")};
oIdRenameMap[sOldId] = oNewId;
if(stDefault.Character == sOldId || stDefault.Numbering == sOldId || stDefault.Paragraph == sOldId || stDefault.Table == sOldId)
oNewId.def = true;
oCollisionStyle.Set_Id(sNewId);
delete styles[sOldId];
styles[sNewId] = oCollisionStyle;
} }
} }
//меняем BasedOn и Next //меняем BasedOn и Next
...@@ -5036,27 +5019,28 @@ function BinaryFileReader(doc, openParams) ...@@ -5036,27 +5019,28 @@ function BinaryFileReader(doc, openParams)
{ {
var elem = this.oReadResult.styles[i]; var elem = this.oReadResult.styles[i];
var oNewStyle = elem.style; var oNewStyle = elem.style;
var sNewStyleId = oNewStyle.Get_Id();
var oNewId = elem.param; var oNewId = elem.param;
var sNewStyleName = oNewStyle.Name.toLowerCase().replace(/\s/g,""); var sNewStyleName = oNewStyle.Name.toLowerCase().replace(/\s/g,"");
if(true == oNewId.def) if(true == oNewId.def)
{ {
switch(oNewStyle.Type) switch(oNewStyle.Type)
{ {
case styletype_Character:stDefault.Character = oNewId.id;break; case styletype_Character:stDefault.Character = sNewStyleId;break;
case styletype_Numbering:stDefault.Numbering = oNewId.id;break; case styletype_Numbering:stDefault.Numbering = sNewStyleId;break;
case styletype_Paragraph:stDefault.Paragraph = oNewId.id;break; case styletype_Paragraph:stDefault.Paragraph = sNewStyleId;break;
case styletype_Table:stDefault.Table = oNewId.id;break; case styletype_Table:stDefault.Table = sNewStyleId;break;
} }
} }
if("header" == sNewStyleName) if("header" == sNewStyleName)
stDefault.Header = oNewId.id; stDefault.Header = sNewStyleId;
if("footer" == sNewStyleName) if("footer" == sNewStyleName)
stDefault.Footer = oNewId.id; stDefault.Footer = sNewStyleId;
if("hyperlink" == sNewStyleName) if("hyperlink" == sNewStyleName)
stDefault.Hyperlink = oNewId.id; stDefault.Hyperlink = sNewStyleId;
if("table grid" == sNewStyleName) if("table grid" == sNewStyleName)
stDefault.TableGrid = oNewId.id; stDefault.TableGrid = sNewStyleId;
styles[oNewId.id] = oNewStyle; oDocStyle.Add(oNewStyle);
} }
var oStyleTypes = {par: 1, table: 2, lvl: 3}; var oStyleTypes = {par: 1, table: 2, lvl: 3};
var fParseStyle = function(aStyles, oDocumentStyles, nStyleType) var fParseStyle = function(aStyles, oDocumentStyles, nStyleType)
...@@ -5064,52 +5048,48 @@ function BinaryFileReader(doc, openParams) ...@@ -5064,52 +5048,48 @@ function BinaryFileReader(doc, openParams)
for(var i = 0, length = aStyles.length; i < length; ++i) for(var i = 0, length = aStyles.length; i < length; ++i)
{ {
var elem = aStyles[i]; var elem = aStyles[i];
if(null != oDocumentStyles[elem.style]) var sStyleId = oIdMap[elem.style];
if(null != sStyleId && null != oDocumentStyles[sStyleId])
{ {
if(oStyleTypes.par == nStyleType) if(oStyleTypes.par == nStyleType)
elem.pPr.PStyle = elem.style; elem.pPr.PStyle = sStyleId;
else if(oStyleTypes.table == nStyleType) else if(oStyleTypes.table == nStyleType)
elem.pPr.TableStyle = elem.style; elem.pPr.TableStyle = sStyleId;
else else
elem.pPr.PStyle = elem.style; elem.pPr.PStyle = sStyleId;
} }
} }
} }
fParseStyle(this.oReadResult.paraStyles, styles, oStyleTypes.par); fParseStyle(this.oReadResult.paraStyles, styles, oStyleTypes.par);
fParseStyle(this.oReadResult.tableStyles, styles, oStyleTypes.table); fParseStyle(this.oReadResult.tableStyles, styles, oStyleTypes.table);
fParseStyle(this.oReadResult.lvlStyles, styles, oStyleTypes.lvl); fParseStyle(this.oReadResult.lvlStyles, styles, oStyleTypes.lvl);
var nStId = styles.length;
if(null == stDefault.Character) if(null == stDefault.Character)
{ {
var oNewStyle = new CStyle( "GenStyleDefChar", null, null, styletype_Character ); var oNewStyle = new CStyle( "GenStyleDefChar", null, null, styletype_Character );
//oNewStyle.Create_Default_Character(); //oNewStyle.Create_Default_Character();
stDefault.Character = nStId.toString(); stDefault.Character = oNewStyle.Get_Id();
styles[nStId] = oNewStyle; oDocStyle.Add(oNewStyle);
nStId++;
} }
if(null == stDefault.Numbering) if(null == stDefault.Numbering)
{ {
var oNewStyle = new CStyle( "GenStyleDefNum", null, null, styletype_Numbering ); var oNewStyle = new CStyle( "GenStyleDefNum", null, null, styletype_Numbering );
//oNewStyle.Create_Default_Numbering(); //oNewStyle.Create_Default_Numbering();
stDefault.Numbering = nStId.toString(); stDefault.Numbering = oNewStyle.Get_Id();
styles[nStId] = oNewStyle; oDocStyle.Add(oNewStyle);
nStId++;
} }
if(null == stDefault.Paragraph) if(null == stDefault.Paragraph)
{ {
var oNewStyle = new CStyle( "GenStyleDefPar", null, null, styletype_Paragraph ); var oNewStyle = new CStyle( "GenStyleDefPar", null, null, styletype_Paragraph );
//oNewStyle.Create_Default_Paragraph(); //oNewStyle.Create_Default_Paragraph();
stDefault.Paragraph = nStId.toString(); stDefault.Paragraph = oNewStyle.Get_Id();
styles[nStId] = oNewStyle; oDocStyle.Add(oNewStyle);
nStId++;
} }
if(null == stDefault.Table) if(null == stDefault.Table)
{ {
var oNewStyle = new CStyle( "GenStyleDefTable", null, null, styletype_Table ); var oNewStyle = new CStyle( "GenStyleDefTable", null, null, styletype_Table );
//oNewStyle.Create_NormalTable(); //oNewStyle.Create_NormalTable();
stDefault.Table = nStId.toString(); stDefault.Table = oNewStyle.Get_Id();
styles[nStId] = oNewStyle; oDocStyle.Add(oNewStyle);
nStId++;
} }
//проверяем циклы в styles по BasedOn //проверяем циклы в styles по BasedOn
var aStylesGrey = {}; var aStylesGrey = {};
......
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