Commit d51719cc authored by Ilya Kirillov's avatar Ilya Kirillov

Fixed a very important issue. Sometimes unnecessary changes could be saved in...

Fixed a very important issue. Sometimes unnecessary changes could be saved in time of calculating of table.
parent 172f53f3
......@@ -9425,8 +9425,7 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, bAllow
res = this.bcr.Read2(length, function(t, l){
return oThis.Read_tblGrid(t,l, aNewGrid);
});
table.Internal_SaveTableGridInHistory(aNewGrid, table.TableGrid);
table.TableGrid = aNewGrid;
table.SetTableGrid(aNewGrid);
}
else if( c_oSerDocTableType.Content === type )
{
......
......@@ -128,7 +128,7 @@ function CTable(DrawingDocument, Parent, Inline, PageNum, X, Y, XLimit, YLimit,
this.TableSumGrid = []; // данный массив будет заполнен после private_RecalculateGrid
this.TableGrid = TableGrid;
this.TableGridCalc = this.Internal_Copy_Grid(TableGrid);
this.TableGridCalc = this.private_CopyTableGrid();
this.RecalcInfo = new CTableRecalcInfo();
......@@ -904,15 +904,12 @@ CTable.prototype =
GridKoeff[Math.max( GridKoeff.length - 1 - GridAfter, 0 )] = 1.5;
}
var TableGrid_old = this.TableGrid;
this.TableGrid = [];
var arrNewGrid = [];
for ( var Index = 0; Index < ColsCount; Index++ )
{
this.TableGrid[Index] = this.TableGridCalc[Index] + GridKoeff[Index] * Diff;
arrNewGrid[Index] = this.TableGridCalc[Index] + GridKoeff[Index] * Diff;
}
History.Add( this, { Type : AscDFH.historyitem_Table_TableGrid, Old : TableGrid_old, New : this.TableGrid } );
this.SetTableGrid(arrNewGrid);
}
}
......@@ -2494,12 +2491,7 @@ CTable.prototype =
Copy : function(Parent)
{
var TableGrid = [];
for ( var Index = 0; Index < this.TableGrid.length; Index++ )
{
TableGrid[Index] = this.TableGrid[Index];
}
var TableGrid = this.private_CopyTableGrid();
var Table = new CTable( this.DrawingDocument, Parent, this.Inline, 0, 0, 0, 0, 0, 0, 0, TableGrid, this.bPresentation);
Table.Set_Distance(this.Distance.L, this.Distance.T, this.Distance.R, this.Distance.B);
......@@ -2888,7 +2880,7 @@ CTable.prototype =
{
var MinMargin = [], MinContent = [], MaxContent = [], MaxFlags = [];
var GridCount = this.TableGrid.length;
var GridCount = this.TableGridCalc.length;
for (var CurCol = 0; CurCol < GridCount; CurCol++)
{
MinMargin[CurCol] = 0;
......@@ -8124,7 +8116,7 @@ CTable.prototype =
}
var TableGrid = this.Internal_Copy_Grid( this.TableGrid );
var TableGrid = this.Internal_Copy_Grid( this.TableGridCalc );
// Посчитаем сколько слева и справа пустых спанов
var MinBefore = -1;
......@@ -9658,7 +9650,7 @@ CTable.prototype =
if ( 0 === CurRow )
return null;
var NewTable = new CTable(this.DrawingDocument, this.Parent, this.Inline, 0, 0, 0, 0, 0, 0, 0, this.Internal_Copy_Grid(this.TableGrid) );
var NewTable = new CTable(this.DrawingDocument, this.Parent, this.Inline, 0, 0, 0, 0, 0, 0, 0, this.private_CopyTableGrid());
var Len = this.Content.length;
for ( var RowIndex = CurRow; RowIndex < Len; RowIndex++ )
......@@ -10240,13 +10232,10 @@ CTable.prototype =
}
}
var TableGrid_old = [];
for ( var Index = 0; Index < this.TableGrid.length; Index++ )
TableGrid_old[Index] = this.TableGrid[Index];
var OldTableGridLen = this.TableGridCalc.length;
var arrNewGrid = this.private_CopyTableGrid();
// Добавим новые колонки в TableGrid
// Добавим новые колонки в TableGrid
// начинаем с конца, чтобы не пересчитывать номера
for ( var Index = OldTableGridLen - 1; Index >= 0; Index-- )
{
......@@ -10254,7 +10243,7 @@ CTable.prototype =
if ( Grid_Info[Index] > 0 )
{
this.TableGrid[Index] = Grid_Info_start[Index];
arrNewGrid[Index] = Grid_Info_start[Index];
Summary -= Grid_Info_start[Index] - Grid_width;
for ( var NewIndex = 0; NewIndex < Grid_Info[Index]; NewIndex++ )
......@@ -10262,14 +10251,13 @@ CTable.prototype =
Summary -= Grid_width;
if ( NewIndex != Grid_Info[Index] - 1 )
this.TableGrid.splice( Index + NewIndex + 1, 0, Grid_width );
arrNewGrid.splice( Index + NewIndex + 1, 0, Grid_width );
else
this.TableGrid.splice( Index + NewIndex + 1, 0, Summary );
arrNewGrid.splice( Index + NewIndex + 1, 0, Summary );
}
}
}
History.Add( this, { Type : AscDFH.historyitem_Table_TableGrid, Old : TableGrid_old, New : this.TableGrid } );
this.SetTableGrid(arrNewGrid);
// Проходим по всем строкам и изменяем у ячеек GridSpan, в
// соответствии со значениями массива Grid_Info
......@@ -11089,10 +11077,6 @@ CTable.prototype =
var TablePr = this.Get_CompiledPr(false).TablePr;
if ( true === bCol )
{
var TableGrid_old = [];
for ( var TempIndex = 0; TempIndex < this.TableGrid.length; TempIndex++ )
TableGrid_old[TempIndex] = this.TableGrid[TempIndex];
var RowIndex = NewMarkup.Internal.RowIndex;
var Row = this.Content[RowIndex];
var Col = 0;
......@@ -11140,7 +11124,8 @@ CTable.prototype =
{
this.Set_TableAlign( align_Left );
this.Set_TableInd( TablePr.TableInd - Dx );
this.private_SetTableLayoutFixedAndUpdateGrid(-1);
this.private_SetTableLayoutFixedAndUpdateCellsWidth(-1);
this.SetTableGrid(this.private_CopyTableGridCalc());
}
else
{
......@@ -11163,9 +11148,10 @@ CTable.prototype =
GridSpan = GridAfter;
}
this.TableGrid[Col - 1] = this.TableGridCalc[Col - 1] + Dx;
this.TableGridCalc[Col - 1] = this.TableGridCalc[Col - 1] + Dx;
this.Internal_UpdateCellW(Col - 1);
this.private_SetTableLayoutFixedAndUpdateGrid(Col - 1);
this.private_SetTableLayoutFixedAndUpdateCellsWidth(Col - 1);
this.SetTableGrid(this.private_CopyTableGridCalc());
}
else
{
......@@ -11183,9 +11169,10 @@ CTable.prototype =
if ( 1 === GridSpan || -Dx < this.TableSumGrid[Col - 1] - this.TableSumGrid[Col - 2] )
{
this.TableGrid[Col - 1] = this.TableGridCalc[Col - 1] + Dx;
this.TableGridCalc[Col - 1] = this.TableGridCalc[Col - 1] + Dx;
this.Internal_UpdateCellW(Col - 1);
this.private_SetTableLayoutFixedAndUpdateGrid(Col - 1);
this.private_SetTableLayoutFixedAndUpdateCellsWidth(Col - 1);
this.SetTableGrid(this.private_CopyTableGridCalc());
}
else
{
......@@ -11243,8 +11230,6 @@ CTable.prototype =
this.private_RecalculateGrid();
}
History.Add( this, { Type : AscDFH.historyitem_Table_TableGrid, Old : TableGrid_old, New : this.TableGrid } );
}
else
{
......@@ -11307,7 +11292,7 @@ CTable.prototype =
var CurPage = Math.min(this.Pages.length - 1, Math.max(0, PageIndex));
var Page = this.Pages[CurPage];
var ColsCount = this.TableGrid.length;
var ColsCount = this.TableGridCalc.length;
if (X >= Page.X)
{
for (CurGrid = 0; CurGrid < ColsCount; CurGrid++)
......@@ -11867,10 +11852,7 @@ CTable.prototype =
Row.Set_After( 0 );
}
}
History.Add( this, { Type : AscDFH.historyitem_Table_TableGrid, Old : this.TableGrid, New : TableGrid } );
this.TableGrid = TableGrid;
this.SetTableGrid(TableGrid);
return TableGrid;
},
......@@ -11894,7 +11876,7 @@ CTable.prototype =
{
var W = 0;
for ( var CurSpan = CurGridCol; CurSpan < CurGridCol + GridSpan; CurSpan++ )
W += this.TableGrid[CurSpan];
W += this.TableGridCalc[CurSpan];
Cell.Set_W( new CTableMeasurement( tblwidth_Mm, W ) );
}
......@@ -12581,7 +12563,7 @@ CTable.prototype =
Internal_Get_MinSumGrid : function()
{
var ColsCount = this.TableGrid.length;
var ColsCount = this.TableGridCalc.length;
var SumGrid = [];
for (var Index = -1; Index < ColsCount; Index++ )
SumGrid[Index] = 0;
......@@ -12695,31 +12677,6 @@ CTable.prototype =
return SumGrid_new;
},
Internal_SaveTableGridInHistory : function(TableGrid_new, TableGrid_old)
{
var NeedSave = false;
if ( TableGrid_new.length != TableGrid_old.length )
NeedSave = true;
if ( false === NeedSave )
{
for ( var Index = 0; Index < TableGrid_new.length; Index++ )
{
if ( Math.abs(TableGrid_new[Index] - TableGrid_old[Index]) > 0.001 )
{
NeedSave = true;
break;
}
}
}
if ( true === NeedSave )
{
History.Add( this, { Type : AscDFH.historyitem_Table_TableGrid, Old : TableGrid_old, New : TableGrid_new } );
}
},
Internal_Get_NextCell : function(Pos)
{
var Cell_Index = Pos.Cell;
......@@ -12776,20 +12733,12 @@ CTable.prototype =
return [];
},
private_SetTableLayoutFixedAndUpdateGrid : function(nExceptColNum)
private_SetTableLayoutFixedAndUpdateCellsWidth : function(nExceptColNum)
{
if (tbllayout_AutoFit === this.Get_CompiledPr(false).TablePr.TableLayout)
{
this.Set_TableLayout(tbllayout_Fixed);
// Обновляем сетку таблицы
var nColsCount = this.TableGrid.length;
for (var nColIndex = 0; nColIndex < nColsCount; nColIndex++)
{
if (nColIndex != nExceptColNum)
this.TableGrid[nColIndex] = this.TableGridCalc[nColIndex];
}
// Обновляем ширины ячеек
for (var nColIndex = 0; nColIndex < nColsCount; nColIndex++)
{
......@@ -13353,6 +13302,7 @@ CTable.prototype.Correct_BadTable = function()
// сделать нормальный обсчет для случая, когда у нас есть "пустые" строки (составленные
// из вертикально объединенных ячеек).
this.Internal_Check_TableRows(false);
this.CorrectBadGrid();
};
CTable.prototype.Get_NumberingInfo = function(NumberingEngine)
{
......@@ -13448,6 +13398,117 @@ CTable.prototype.IncDec_Indent = function(bIncrease)
this.CurCell.Content.Paragraph_IncDecIndent(bIncrease);
}
};
CTable.prototype.SetTableGrid = function(arrGrid)
{
History.Add(this, {
Type : AscDFH.historyitem_Table_TableGrid,
Old : this.TableGrid,
New : arrGrid
});
this.TableGrid = arrGrid;
console.log("SetTableGrid");
};
CTable.prototype.private_CopyTableGrid = function()
{
var arrGrid = [];
for (var nIndex = 0, nCount = this.TableGrid.length; nIndex < nCount; ++nIndex)
{
arrGrid[nIndex] = this.TableGrid[nIndex];
}
return arrGrid;
};
CTable.prototype.private_CopyTableGridCalc = function()
{
var arrGrid = [];
for (var nIndex = 0, nCount = this.TableGridCalc.length; nIndex < nCount; ++nIndex)
{
arrGrid[nIndex] = this.TableGridCalc[nIndex];
}
return arrGrid;
};
CTable.prototype.CorrectBadGrid = function()
{
// HACK: При загрузке мы запрещаем компилировать стили, но нам все-таки это здесь нужно
var bLoad = AscCommon.g_oIdCounter.m_bLoad;
var bRead = AscCommon.g_oIdCounter.m_bRead;
AscCommon.g_oIdCounter.m_bLoad = false;
AscCommon.g_oIdCounter.m_bRead = false;
// Сначала пробежимся по всем ячейкам и посмотрим, чтобы у них были корректные GridSpan (т.е. >= 1)
for (var Index = 0; Index < this.Content.length; Index++)
{
var Row = this.Content[Index];
var CellsCount = Row.Get_CellsCount();
for (var CellIndex = 0; CellIndex < CellsCount; CellIndex++)
{
var Cell = Row.Get_Cell(CellIndex);
var GridSpan = Cell.Get_GridSpan();
if (GridSpan <= 0)
Cell.Set_GridSpan(1);
}
}
var RowGrid = [];
var GridCount = 0;
for (var Index = 0; Index < this.Content.length; Index++)
{
var Row = this.Content[Index];
Row.Set_Index(Index);
// Смотрим на ширину пропущенных колонок сетки в начале строки
var BeforeInfo = Row.Get_Before();
var CurGridCol = BeforeInfo.GridBefore;
var CellsCount = Row.Get_CellsCount();
for (var CellIndex = 0; CellIndex < CellsCount; CellIndex++)
{
var Cell = Row.Get_Cell(CellIndex);
var GridSpan = Cell.Get_GridSpan();
CurGridCol += GridSpan;
}
// Смотрим на ширину пропущенных колонок сетки в конце строки
var AfterInfo = Row.Get_After();
CurGridCol += AfterInfo.GridAfter;
if (GridCount < CurGridCol)
GridCount = CurGridCol;
RowGrid[Index] = CurGridCol;
}
for (var Index = 0; Index < this.Content.length; Index++)
{
var Row = this.Content[Index];
var AfterInfo = Row.Get_After();
if (RowGrid[Index] < GridCount)
{
Row.Set_After(AfterInfo.GridAfter + GridCount - RowGrid[Index], AfterInfo.WAfter);
}
}
var arrGrid = this.private_CopyTableGrid();
if (arrGrid.length != GridCount)
{
if (arrGrid.length < GridCount)
{
for (var nIndex = 0; nIndex < GridCount; ++nIndex)
arrGrid[nIndex] = 20;
}
else
{
arrGrid.splice(GridCount, arrGrid.length - GridCount);
}
this.SetTableGrid(arrGrid);
}
// HACK: Восстанавливаем флаги и выставляем, что стиль всей таблицы нужно пересчитать
AscCommon.g_oIdCounter.m_bLoad = bLoad;
AscCommon.g_oIdCounter.m_bRead = bRead;
this.Recalc_CompiledPr2();
};
//----------------------------------------------------------------------------------------------------------------------
// Класс CTableLook
//----------------------------------------------------------------------------------------------------------------------
......
......@@ -233,14 +233,12 @@ CTable.prototype.private_RecalculateGrid = function()
if ( this.Content.length <= 0 )
return;
this.private_RecalculateGridOpen();
//---------------------------------------------------------------------------
// 1 часть пересчета ширины таблицы : Рассчитываем фиксированную ширину
//---------------------------------------------------------------------------
var TablePr = this.Get_CompiledPr(false).TablePr;
var Grid = this.TableGrid;
var Grid = this.TableGrid;
var SumGrid = [];
var TempSum = 0;
......@@ -354,18 +352,11 @@ CTable.prototype.private_RecalculateGrid = function()
else if ( MinWidth > SumGrid[SumGrid.length - 1] )
SumGrid = this.Internal_ScaleTableWidth( SumGrid, SumGrid[SumGrid.length - 1] );
var TableGrid_old = [];
for ( var Index = 0; Index < this.TableGrid.length; Index++ )
TableGrid_old[Index] = this.TableGrid[Index];
// По массиву SumGrid восстанавливаем ширины самих колонок
this.TableGrid[0] = SumGrid[0];
this.TableGridCalc = [];
this.TableGridCalc[0] = SumGrid[0];
for ( var Index = 1; Index < SumGrid.length; Index++ )
this.TableGrid[Index] = SumGrid[Index] - SumGrid[Index - 1];
this.Internal_SaveTableGridInHistory( this.TableGrid, TableGrid_old );
this.TableGridCalc = this.Internal_Copy_Grid(this.TableGrid);
this.TableGridCalc[Index] = SumGrid[Index] - SumGrid[Index - 1];
this.TableSumGrid = SumGrid;
......@@ -437,13 +428,13 @@ CTable.prototype.private_RecalculateGrid = function()
{
SumSpanMinContent += MinContent[CurSpan];
SumSpanMaxContent += MaxContent[CurSpan];
SumSpanCurContent += this.TableGrid[CurSpan];
SumSpanCurContent += this.TableGridCalc[CurSpan];
}
if (null !== WBeforeW && SumSpanMinContent < WBeforeW)
{
for ( var CurSpan = CurGridCol; CurSpan < CurGridCol + GridSpan; CurSpan++ )
MinContent[CurSpan] = WBeforeW * this.TableGrid[CurSpan] / SumSpanCurContent;
MinContent[CurSpan] = WBeforeW * this.TableGridCalc[CurSpan] / SumSpanCurContent;
}
// Если у нас в объединении несколько колонок, тогда явно записанная ширина ячейки не
......@@ -454,7 +445,7 @@ CTable.prototype.private_RecalculateGrid = function()
// TODO: На самом деле, распределение здесь идет в каком-то отношении.
// Неплохо было бы выяснить как именно.
for ( var CurSpan = CurGridCol; CurSpan < CurGridCol + GridBefore; CurSpan++ )
MaxContent[CurSpan] = WBeforeW * this.TableGrid[CurSpan] / SumSpanCurContent;
MaxContent[CurSpan] = WBeforeW * this.TableGridCalc[CurSpan] / SumSpanCurContent;
}
}
......@@ -546,13 +537,13 @@ CTable.prototype.private_RecalculateGrid = function()
{
SumSpanMinContent += MinContent[CurSpan];
SumSpanMaxContent += MaxContent[CurSpan];
SumSpanCurContent += this.TableGrid[CurSpan];
SumSpanCurContent += this.TableGridCalc[CurSpan];
}
if ( SumSpanMinContent < CellMin )
{
for ( var CurSpan = CurGridCol; CurSpan < CurGridCol + GridSpan; CurSpan++ )
MinContent[CurSpan] = CellMin * this.TableGrid[CurSpan] / SumSpanCurContent;
MinContent[CurSpan] = CellMin * this.TableGridCalc[CurSpan] / SumSpanCurContent;
}
// Если у нас в объединении несколько колонок, тогда явно записанная ширина ячейки не
......@@ -566,7 +557,7 @@ CTable.prototype.private_RecalculateGrid = function()
// TODO: На самом деле, распределение здесь идет в каком-то отношении.
// Неплохо было бы выяснить как именно.
for ( var CurSpan = CurGridCol; CurSpan < CurGridCol + GridSpan; CurSpan++ )
MaxContent[CurSpan] = CellMax * this.TableGrid[CurSpan] / SumSpanCurContent;
MaxContent[CurSpan] = CellMax * this.TableGridCalc[CurSpan] / SumSpanCurContent;
}
}
......@@ -616,13 +607,13 @@ CTable.prototype.private_RecalculateGrid = function()
{
SumSpanMinContent += MinContent[CurSpan];
SumSpanMaxContent += MaxContent[CurSpan];
SumSpanCurContent += this.TableGrid[CurSpan];
SumSpanCurContent += this.TableGridCalc[CurSpan];
}
if (null !== WAfterW && SumSpanMinContent < WAfterW)
{
for ( var CurSpan = CurGridCol; CurSpan < CurGridCol + GridSpan; CurSpan++ )
MinContent[CurSpan] = WAfterW * this.TableGrid[CurSpan] / SumSpanCurContent;
MinContent[CurSpan] = WAfterW * this.TableGridCalc[CurSpan] / SumSpanCurContent;
}
// Если у нас в объединении несколько колонок, тогда явно записанная ширина ячейки не
......@@ -633,7 +624,7 @@ CTable.prototype.private_RecalculateGrid = function()
// TODO: На самом деле, распределение здесь идет в каком-то отношении.
// Неплохо было бы выяснить как именно.
for ( var CurSpan = CurGridCol; CurSpan < CurGridCol + GridAfter; CurSpan++ )
MaxContent[CurSpan] = WAfterW * this.TableGrid[CurSpan] / SumSpanCurContent;
MaxContent[CurSpan] = WAfterW * this.TableGridCalc[CurSpan] / SumSpanCurContent;
}
}
}
......@@ -895,80 +886,6 @@ CTable.prototype.private_RecalculateGrid = function()
this.RecalcInfo.TableGrid = false;
};
CTable.prototype.private_RecalculateGridOpen = function()
{
if ( true != this.RecalcInfo.TableGridOpen )
return;
// Сначала пробежимся по всем ячейкам и посмотрим, чтобы у них были корректные GridSpan (т.е. >= 1)
for ( var Index = 0; Index < this.Content.length; Index++ )
{
var Row = this.Content[Index];
var CellsCount = Row.Get_CellsCount();
for ( var CellIndex = 0; CellIndex < CellsCount; CellIndex++ )
{
var Cell = Row.Get_Cell( CellIndex );
var GridSpan = Cell.Get_GridSpan();
if ( GridSpan <= 0 )
Cell.Set_GridSpan( 1 );
}
}
var RowGrid = [];
var GridCount = 0;
for ( var Index = 0; Index < this.Content.length; Index++ )
{
var Row = this.Content[Index];
Row.Set_Index( Index );
// Смотрим на ширину пропущенных колонок сетки в начале строки
var BeforeInfo = Row.Get_Before();
var CurGridCol = BeforeInfo.GridBefore;
var CellsCount = Row.Get_CellsCount();
for ( var CellIndex = 0; CellIndex < CellsCount; CellIndex++ )
{
var Cell = Row.Get_Cell( CellIndex );
var GridSpan = Cell.Get_GridSpan();
CurGridCol += GridSpan;
}
// Смотрим на ширину пропущенных колонок сетки в конце строки
var AfterInfo = Row.Get_After();
CurGridCol += AfterInfo.GridAfter;
if ( GridCount < CurGridCol )
GridCount = CurGridCol;
RowGrid[Index] = CurGridCol;
}
for ( var Index = 0; Index < this.Content.length; Index++ )
{
var Row = this.Content[Index];
var AfterInfo = Row.Get_After();
if ( RowGrid[Index] < GridCount )
{
Row.Set_After( AfterInfo.GridAfter + GridCount - RowGrid[Index], AfterInfo.WAfter );
}
}
if ( this.TableGrid.length != GridCount )
{
if (this.TableGrid.length < GridCount)
{
for (var Index = 0; Index < GridCount; Index++)
this.TableGrid[Index] = 20;
}
else
{
this.TableGrid.splice(GridCount, this.TableGrid.length - GridCount);
}
}
this.RecalcInfo.TableGridOpen = false;
};
CTable.prototype.private_RecalculateBorders = function()
{
if ( true != this.RecalcInfo.TableBorders )
......@@ -3094,7 +3011,6 @@ CTablePage.prototype.Shift = function(Dx, Dy)
//----------------------------------------------------------------------------------------------------------------------
function CTableRecalcInfo()
{
this.TableGridOpen = true;
this.TableGrid = true;
this.TableBorders = true;
......
......@@ -553,6 +553,7 @@
return null;
var oTable = new CTable(private_GetDrawingDocument(), private_GetLogicDocument(), true, 0, 0, 0, 0, 0, nRows, nCols, [], false);
oTable.CorrectBadGrid();
oTable.Set_TableStyle2(undefined);
return new ApiTable(oTable);
};
......
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