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

копирование части таблиц через бинарник, Bug 19642 - [Copy&Paste] Таблица не...

копирование части таблиц через бинарник, Bug 19642 - [Copy&Paste] Таблица не копируются в колонтитул, стили списков в бинарнике для копирования.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@48802 954022d7-b5bf-4e40-9824-e11837661b57
parent 3306f88e
...@@ -1176,7 +1176,7 @@ CopyProcessor.prototype = ...@@ -1176,7 +1176,7 @@ CopyProcessor.prototype =
oDomTarget.appendChild(tr); oDomTarget.appendChild(tr);
}, },
CopyTable : function(oDomTarget, table, oRowElems) CopyTable : function(oDomTarget, table, aRowElems)
{ {
this.CommitList(oDomTarget); this.CommitList(oDomTarget);
var DomTable = document.createElement( "table" ); var DomTable = document.createElement( "table" );
...@@ -1257,7 +1257,7 @@ CopyProcessor.prototype = ...@@ -1257,7 +1257,7 @@ CopyProcessor.prototype =
DomTable.setAttribute("style", tblStyle); DomTable.setAttribute("style", tblStyle);
//rows //rows
if(null == oRowElems) if(null == aRowElems)
{ {
for(var i = 0, length = table.Content.length; i < length; i++) for(var i = 0, length = table.Content.length; i < length; i++)
this.CopyRow(DomTable, table, i , null, table.Content.length - 1); this.CopyRow(DomTable, table, i , null, table.Content.length - 1);
...@@ -1265,14 +1265,17 @@ CopyProcessor.prototype = ...@@ -1265,14 +1265,17 @@ CopyProcessor.prototype =
else else
{ {
var nMaxRow = 0; var nMaxRow = 0;
for(var i in oRowElems) for(var i = 0, length = aRowElems.length; i < length; ++i)
{ {
var nCurRow = i - 0; var elem = aRowElems[i];
if(nCurRow > nMaxRow) if(elem.row > nMaxRow)
nMaxRow = nCurRow; nMaxRow = elem.row;
}
for(var i = 0, length = aRowElems.length; i < length; ++i)
{
var elem = aRowElems[i];
this.CopyRow(DomTable, table, elem.row, elem, nMaxRow);
} }
for(var i in oRowElems)
this.CopyRow(DomTable, table, i - 0, oRowElems[i], nMaxRow);
} }
oDomTarget.appendChild(DomTable); oDomTarget.appendChild(DomTable);
...@@ -1350,9 +1353,9 @@ CopyProcessor.prototype = ...@@ -1350,9 +1353,9 @@ CopyProcessor.prototype =
var rowElem = oRowElems[elem.Row]; var rowElem = oRowElems[elem.Row];
if(null == rowElem) if(null == rowElem)
{ {
rowElem = {gridStart: null, gridEnd: null, indexStart: null, indexEnd: null, after: null, before: null, cells: {}}; rowElem = {row: elem.Row, gridStart: null, gridEnd: null, indexStart: null, indexEnd: null, after: null, before: null, cells: {}};
oRowElems[elem.Row] = rowElem; oRowElems[elem.Row] = rowElem;
aSelectedRows.push(elem.Row); aSelectedRows.push(rowElem);
} }
if(null == rowElem.indexEnd || elem.Cell > rowElem.indexEnd) if(null == rowElem.indexEnd || elem.Cell > rowElem.indexEnd)
rowElem.indexEnd = elem.Cell; rowElem.indexEnd = elem.Cell;
...@@ -1361,7 +1364,9 @@ CopyProcessor.prototype = ...@@ -1361,7 +1364,9 @@ CopyProcessor.prototype =
rowElem.cells[elem.Cell] = 1; rowElem.cells[elem.Cell] = 1;
} }
} }
aSelectedRows.sort(fSortAscending); aSelectedRows.sort(function(a,b){
return a.row - b.row;
});
var nMinGrid = null; var nMinGrid = null;
var nMaxGrid = null; var nMaxGrid = null;
var nPrevStartGrid = null; var nPrevStartGrid = null;
...@@ -1369,7 +1374,8 @@ CopyProcessor.prototype = ...@@ -1369,7 +1374,8 @@ CopyProcessor.prototype =
var nPrevRowIndex = null; var nPrevRowIndex = null;
for(var i = 0, length = aSelectedRows.length; i < length; ++i) for(var i = 0, length = aSelectedRows.length; i < length; ++i)
{ {
var nRowIndex = aSelectedRows[i]; var elem = aSelectedRows[i];
var nRowIndex = elem.row;
if(null != nPrevRowIndex) if(null != nPrevRowIndex)
{ {
if(nPrevRowIndex + 1 != nRowIndex) if(nPrevRowIndex + 1 != nRowIndex)
...@@ -1380,7 +1386,6 @@ CopyProcessor.prototype = ...@@ -1380,7 +1386,6 @@ CopyProcessor.prototype =
} }
} }
nPrevRowIndex = nRowIndex; nPrevRowIndex = nRowIndex;
var elem = oRowElems[nRowIndex];
var row = Item.Content[nRowIndex]; var row = Item.Content[nRowIndex];
var cellFirst = row.Get_Cell(elem.indexStart); var cellFirst = row.Get_Cell(elem.indexStart);
var cellLast = row.Get_Cell(elem.indexEnd); var cellLast = row.Get_Cell(elem.indexEnd);
...@@ -1398,7 +1403,10 @@ CopyProcessor.prototype = ...@@ -1398,7 +1403,10 @@ CopyProcessor.prototype =
{ {
var nCurGridCol = cellCur.Metrics.StartGridCol; var nCurGridCol = cellCur.Metrics.StartGridCol;
if(nCurGridCol >= nPrevStartGrid) if(nCurGridCol >= nPrevStartGrid)
{
nCurStartGrid = nCurGridCol; nCurStartGrid = nCurGridCol;
elem.indexStart = j;
}
else else
break; break;
} }
...@@ -1415,7 +1423,10 @@ CopyProcessor.prototype = ...@@ -1415,7 +1423,10 @@ CopyProcessor.prototype =
{ {
var nCurGridCol = cellCur.Metrics.StartGridCol + cellCur.Get_GridSpan() - 1; var nCurGridCol = cellCur.Metrics.StartGridCol + cellCur.Get_GridSpan() - 1;
if(nCurGridCol <= nPrevEndGrid) if(nCurGridCol <= nPrevEndGrid)
{
nCurEndGrid = nCurGridCol; nCurEndGrid = nCurGridCol;
elem.indexEnd = j;
}
else else
break; break;
} }
...@@ -1434,15 +1445,15 @@ CopyProcessor.prototype = ...@@ -1434,15 +1445,15 @@ CopyProcessor.prototype =
if(null != nMinGrid && null != nMaxGrid) if(null != nMinGrid && null != nMaxGrid)
{ {
//выставляем after, before //выставляем after, before
for(var i in oRowElems) for(var i = 0 ,length = aSelectedRows.length; i < length; ++i)
{ {
var elem = oRowElems[i]; var elem = aSelectedRows[i];
elem.before = elem.gridStart - nMinGrid; elem.before = elem.gridStart - nMinGrid;
elem.after = nMaxGrid - elem.gridEnd; elem.after = nMaxGrid - elem.gridEnd;
} }
this.oBinaryFileWriter.CopyTable(Item, oRowElems); this.oBinaryFileWriter.CopyTable(Item, aSelectedRows, nMinGrid, nMaxGrid);
this.oBinaryFileWriter.copyParams.bLockCopyPar = true; this.oBinaryFileWriter.copyParams.bLockCopyPar = true;
this.CopyTable(oDomTarget, Item, oRowElems); this.CopyTable(oDomTarget, Item, aSelectedRows);
this.oBinaryFileWriter.copyParams.bLockCopyPar = null; this.oBinaryFileWriter.copyParams.bLockCopyPar = null;
} }
} }
...@@ -2343,7 +2354,8 @@ PasteProcessor.prototype = ...@@ -2343,7 +2354,8 @@ PasteProcessor.prototype =
} }
//обрабатываем стили //обрабатываем стили
var isUsuallyContainsStyle; var isUsuallyContainsStyle;
var fParseStyle = function(aStyles, oDocumentStyles, oReadResult, bParaStyle) var oStyleTypes = {par: 1, table: 2, lvl: 3};
var fParseStyle = function(aStyles, oDocumentStyles, oReadResult, nStyleType)
{ {
for(var i = 0, length = aStyles.length; i < length; ++i) for(var i = 0, length = aStyles.length; i < length; ++i)
{ {
...@@ -2357,18 +2369,21 @@ PasteProcessor.prototype = ...@@ -2357,18 +2369,21 @@ PasteProcessor.prototype =
isUsuallyContainsStyle = styleDoc.isEqual(stylePaste.style); isUsuallyContainsStyle = styleDoc.isEqual(stylePaste.style);
if(isUsuallyContainsStyle) if(isUsuallyContainsStyle)
{ {
if(bParaStyle) if(oStyleTypes.par == nStyleType)
elem.pPr.PStyle = j; elem.pPr.PStyle = j;
else else if(oStyleTypes.table == nStyleType)
elem.pPr.TableStyle = j; elem.pPr.TableStyle = j;
else
elem.pPr.PStyle = j;
break; break;
} }
} }
} }
} }
} }
fParseStyle(oBinaryFileReader.oReadResult.paraStyles, this.oDocument.Styles.Style, oBinaryFileReader.oReadResult, true); fParseStyle(oBinaryFileReader.oReadResult.paraStyles, this.oDocument.Styles.Style, oBinaryFileReader.oReadResult, oStyleTypes.par);
fParseStyle(oBinaryFileReader.oReadResult.tableStyles, this.oDocument.Styles.Style, oBinaryFileReader.oReadResult, false); fParseStyle(oBinaryFileReader.oReadResult.tableStyles, this.oDocument.Styles.Style, oBinaryFileReader.oReadResult, oStyleTypes.table);
fParseStyle(oBinaryFileReader.oReadResult.lvlStyles, this.oDocument.Styles.Style, oBinaryFileReader.oReadResult, oStyleTypes.lvl);
var aContent = oBinaryFileReader.oReadResult.DocumentContent; var aContent = oBinaryFileReader.oReadResult.DocumentContent;
if(aContent.length > 0) if(aContent.length > 0)
{ {
...@@ -2391,6 +2406,7 @@ PasteProcessor.prototype = ...@@ -2391,6 +2406,7 @@ PasteProcessor.prototype =
Start : function(node) Start : function(node)
{ {
var oThis = this; var oThis = this;
this.oDocument = this._GetTargetDocument(this.oDocument);
// var oPasteContent = this.ReadFromBinary(node.innerText); // var oPasteContent = this.ReadFromBinary(node.innerText);
// this.aContent = oPasteContent.content; // this.aContent = oPasteContent.content;
// oThis.api.pre_Paste(oPasteContent.fonts, oPasteContent.images, function(){ // oThis.api.pre_Paste(oPasteContent.fonts, oPasteContent.images, function(){
...@@ -2443,7 +2459,6 @@ PasteProcessor.prototype = ...@@ -2443,7 +2459,6 @@ PasteProcessor.prototype =
this._Prepeare(node, this._Prepeare(node,
function(){ function(){
oThis.aContent = new Array(); oThis.aContent = new Array();
oThis.oDocument = oThis._GetTargetDocument(oThis.oDocument);
//�� ����� ���������� �������� ��� ������� ��������� ������� //�� ����� ���������� �������� ��� ������� ��������� �������
oThis._Execute(node, {}, true, true, false); oThis._Execute(node, {}, true, true, false);
......
...@@ -630,6 +630,14 @@ function BinaryFileWriter(doc) ...@@ -630,6 +630,14 @@ function BinaryFileWriter(doc)
{ {
this.copyParams.oUsedNumIdMap[oNumPr.NumId] = this.copyParams.nNumIdIndex; this.copyParams.oUsedNumIdMap[oNumPr.NumId] = this.copyParams.nNumIdIndex;
this.copyParams.nNumIdIndex++; this.copyParams.nNumIdIndex++;
//проверяем PStyle уровней списка
var aNum = this.Document.Numbering.Get_AbstractNum(oNumPr.NumId);
for(var i = 0, length = aNum.Lvl.length; i < length; ++i)
{
var oLvl = aNum.Lvl[i];
if(null != oLvl.PStyle)
this.copyParams.oUsedStyleMap[oLvl.PStyle] = 1;
}
} }
} }
//сами параграфы скопируются в методе CopyTable, нужно только проанализировать стили //сами параграфы скопируются в методе CopyTable, нужно только проанализировать стили
...@@ -638,14 +646,14 @@ function BinaryFileWriter(doc) ...@@ -638,14 +646,14 @@ function BinaryFileWriter(doc)
this.bs.WriteItem(c_oSerParType.Par, function(){oThis.copyParams.bdtw.WriteParapraph(Item, bUseSelection);}); this.bs.WriteItem(c_oSerParType.Par, function(){oThis.copyParams.bdtw.WriteParapraph(Item, bUseSelection);});
this.copyParams.itemCount++; this.copyParams.itemCount++;
} }
this.CopyTable = function(Item, oRowElems) this.CopyTable = function(Item, aRowElems, nMinGrid, nMaxGrid)
{ {
var oThis = this; var oThis = this;
//анализируем используемые списки и стили //анализируем используемые списки и стили
var sTableStyle = Item.Get_TableStyle(); var sTableStyle = Item.Get_TableStyle();
if(null != sTableStyle) if(null != sTableStyle)
this.copyParams.oUsedStyleMap[sTableStyle] = 1; this.copyParams.oUsedStyleMap[sTableStyle] = 1;
this.bs.WriteItem(c_oSerParType.Table, function(){oThis.copyParams.bdtw.WriteDocTable(Item);}); this.bs.WriteItem(c_oSerParType.Table, function(){oThis.copyParams.bdtw.WriteDocTable(Item, aRowElems, nMinGrid, nMaxGrid);});
this.copyParams.itemCount++; this.copyParams.itemCount++;
} }
this.CopyEnd = function() this.CopyEnd = function()
...@@ -2549,7 +2557,7 @@ function BinaryDocumentTableWriter(memory, doc, oMapCommentId, oNumIdMap) ...@@ -2549,7 +2557,7 @@ function BinaryDocumentTableWriter(memory, doc, oMapCommentId, oNumIdMap)
this.memory.WriteDouble(oPoint.y); this.memory.WriteDouble(oPoint.y);
} }
} }
this.WriteDocTable = function(table) this.WriteDocTable = function(table, aRowElems, nMinGrid, nMaxGrid)
{ {
var oThis = this; var oThis = this;
//tblPr //tblPr
...@@ -2558,10 +2566,15 @@ function BinaryDocumentTableWriter(memory, doc, oMapCommentId, oNumIdMap) ...@@ -2558,10 +2566,15 @@ function BinaryDocumentTableWriter(memory, doc, oMapCommentId, oNumIdMap)
this.bs.WriteItem(c_oSerDocTableType.tblPr, function(){oThis.btblPrs.WriteTbl(table);}); this.bs.WriteItem(c_oSerDocTableType.tblPr, function(){oThis.btblPrs.WriteTbl(table);});
//tblGrid //tblGrid
if(null != table.TableGrid) if(null != table.TableGrid)
this.bs.WriteItem(c_oSerDocTableType.tblGrid, function(){oThis.WriteTblGrid(table.TableGrid);}); {
var aGrid = table.TableGrid;
if(null != nMinGrid && null != nMaxGrid && 0 != nMinGrid && aGrid.length - 1 != nMaxGrid)
aGrid = aGrid.slice( nMinGrid, nMaxGrid + 1);
this.bs.WriteItem(c_oSerDocTableType.tblGrid, function(){oThis.WriteTblGrid(aGrid);});
}
//Content //Content
if(null != table.Content && table.Content.length > 0) if(null != table.Content && table.Content.length > 0)
this.bs.WriteItem(c_oSerDocTableType.Content, function(){oThis.WriteTableContent(table.Content);}); this.bs.WriteItem(c_oSerDocTableType.Content, function(){oThis.WriteTableContent(table.Content, aRowElems);});
}; };
this.WriteTblGrid = function(grid) this.WriteTblGrid = function(grid)
{ {
...@@ -2573,30 +2586,64 @@ function BinaryDocumentTableWriter(memory, doc, oMapCommentId, oNumIdMap) ...@@ -2573,30 +2586,64 @@ function BinaryDocumentTableWriter(memory, doc, oMapCommentId, oNumIdMap)
this.memory.WriteDouble(grid[i]); this.memory.WriteDouble(grid[i]);
} }
}; };
this.WriteTableContent = function(Content) this.WriteTableContent = function(Content, aRowElems)
{ {
var oThis = this; var oThis = this;
for(var i = 0, length = Content.length; i < length; ++i) var nStart = 0;
this.bs.WriteItem(c_oSerDocTableType.Row, function(){oThis.WriteRow(Content[i], i);}); var nEnd = Content.length - 1;
if(null != aRowElems && aRowElems.length > 0)
{
nStart = aRowElems[0].row;
nEnd = aRowElems[aRowElems.length - 1].row;
}
for(var i = nStart; i <= nEnd; ++i)
{
var oRowElem = null;
if(null != aRowElems)
oRowElem = aRowElems[i - nStart];
this.bs.WriteItem(c_oSerDocTableType.Row, function(){oThis.WriteRow(Content[i], i, oRowElem);});
}
}; };
this.WriteRow = function(Row, nRowIndex) this.WriteRow = function(Row, nRowIndex, oRowElem)
{ {
var oThis = this; var oThis = this;
//Pr //Pr
if(null != Row.Pr) if(null != Row.Pr)
{ {
this.bs.WriteItem(c_oSerDocTableType.Row_Pr, function(){oThis.btblPrs.WriteRowPr(Row.Pr);}); var oRowPr = Row.Pr;
if(null != oRowElem)
{
oRowPr = oRowPr.Copy();
oRowPr.WAfter = null;
oRowPr.WBefore = null;
if(null != oRowElem.after)
oRowPr.GridAfter = oRowElem.after;
else
oRowPr.GridAfter = null;
if(null != oRowElem.before)
oRowPr.GridBefore = oRowElem.before;
else
oRowPr.GridBefore = null;
}
this.bs.WriteItem(c_oSerDocTableType.Row_Pr, function(){oThis.btblPrs.WriteRowPr(oRowPr);});
} }
//Content //Content
if(null != Row.Content) if(null != Row.Content)
{ {
this.bs.WriteItem(c_oSerDocTableType.Row_Content, function(){oThis.WriteRowContent(Row.Content, nRowIndex);}); this.bs.WriteItem(c_oSerDocTableType.Row_Content, function(){oThis.WriteRowContent(Row.Content, nRowIndex, oRowElem);});
} }
}; };
this.WriteRowContent = function(Content, nRowIndex) this.WriteRowContent = function(Content, nRowIndex, oRowElem)
{ {
var oThis = this; var oThis = this;
for(var i = 0, length = Content.length; i < length; i++) var nStart = 0;
var nEnd = Content.length - 1;
if(null != oRowElem)
{
nStart = oRowElem.indexStart;
nEnd = oRowElem.indexEnd;
}
for(var i = nStart; i <= nEnd; i++)
{ {
this.bs.WriteItem(c_oSerDocTableType.Cell, function(){oThis.WriteCell(Content[i], nRowIndex, i);}); this.bs.WriteItem(c_oSerDocTableType.Cell, function(){oThis.WriteCell(Content[i], nRowIndex, i);});
} }
...@@ -2910,6 +2957,7 @@ function BinaryFileReader(doc, openParams) ...@@ -2910,6 +2957,7 @@ function BinaryFileReader(doc, openParams)
styles: null, styles: null,
paraStyles: null, paraStyles: null,
tableStyles: null, tableStyles: null,
lvlStyles: null,
DefpPr: null, DefpPr: null,
DefrPr: null, DefrPr: null,
DocumentContent: null DocumentContent: null
...@@ -3071,6 +3119,7 @@ function BinaryFileReader(doc, openParams) ...@@ -3071,6 +3119,7 @@ function BinaryFileReader(doc, openParams)
this.oReadResult.styles = []; this.oReadResult.styles = [];
this.oReadResult.paraStyles = []; this.oReadResult.paraStyles = [];
this.oReadResult.tableStyles = []; this.oReadResult.tableStyles = [];
this.oReadResult.lvlStyles = [];
this.oReadResult.DocumentContent = []; this.oReadResult.DocumentContent = [];
var res = c_oSerConstants.ReadOk; var res = c_oSerConstants.ReadOk;
...@@ -3263,22 +3312,26 @@ function BinaryFileReader(doc, openParams) ...@@ -3263,22 +3312,26 @@ function BinaryFileReader(doc, openParams)
} }
styles[oNewId.id] = oNewStyle; styles[oNewId.id] = oNewStyle;
} }
var fParseStyle = function(aStyles, oDocumentStyles, bParaStyle) var oStyleTypes = {par: 1, table: 2, lvl: 3};
var fParseStyle = function(aStyles, oDocumentStyles, nStyleType)
{ {
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]) if(null != oDocumentStyles[elem.style])
{ {
if(bParaStyle) if(oStyleTypes.par == nStyleType)
elem.pPr.PStyle = elem.style; elem.pPr.PStyle = elem.style;
else else if(oStyleTypes.table == nStyleType)
elem.pPr.TableStyle = elem.style; elem.pPr.TableStyle = elem.style;
else
elem.pPr.PStyle = elem.style;
} }
} }
} }
fParseStyle(this.oReadResult.paraStyles, this.Document.Styles.Style, true); fParseStyle(this.oReadResult.paraStyles, this.Document.Styles.Style, oStyleTypes.par);
fParseStyle(this.oReadResult.tableStyles, this.Document.Styles.Style, false); fParseStyle(this.oReadResult.tableStyles, this.Document.Styles.Style, oStyleTypes.table);
fParseStyle(this.oReadResult.lvlStyles, this.Document.Styles.Style, oStyleTypes.lvl);
var stDefault = this.Document.Styles.Default; var stDefault = this.Document.Styles.Default;
var nStId = styles.length; var nStId = styles.length;
if(null == stDefault.Numbering) if(null == stDefault.Numbering)
...@@ -4848,7 +4901,7 @@ function Binary_NumberingTableReader(doc, oReadResult, stream) ...@@ -4848,7 +4901,7 @@ function Binary_NumberingTableReader(doc, oReadResult, stream)
} }
else if ( c_oSerNumTypes.lvl_PStyle === type ) else if ( c_oSerNumTypes.lvl_PStyle === type )
{ {
oNewLvl.PStyle = this.stream.GetString2LE(length); this.oReadResult.lvlStyles.push({pPr: oNewLvl, style: this.stream.GetString2LE(length)});
} }
else if ( c_oSerNumTypes.lvl_ParaPr === type ) else if ( c_oSerNumTypes.lvl_ParaPr === type )
{ {
......
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