Commit 0f52b44e authored by Ilya Kirillov's avatar Ilya Kirillov

Fixed issue with adding a template through a plugin. Reworking footnotes.

parent bf2e73df
......@@ -1664,16 +1664,17 @@ CDocument.prototype.Get_PageContentStartPos2 = function(StartPageIndex, St
var SectPr = this.SectionsInfo.Get_SectPr(ElementIndex).SectPr;
var FootnotesHeight = this.Footnotes.Get_Height(StartPageIndex);
var ColumnsCount = SectPr.Get_ColumnsCount();
var ColumnAbs = (StartColumnIndex + ElementPageIndex) - ((StartColumnIndex + ElementPageIndex) / ColumnsCount | 0) * ColumnsCount;
var PageAbs = StartPageIndex + ((StartColumnIndex + ElementPageIndex) / ColumnsCount | 0);
var FootnotesHeight = this.Footnotes.GetHeight(StartPageIndex, ColumnAbs);
var Y = SectPr.Get_PageMargin_Top();
var YLimit = SectPr.Get_PageHeight() - SectPr.Get_PageMargin_Bottom() - FootnotesHeight;
var X = SectPr.Get_PageMargin_Left();
var XLimit = SectPr.Get_PageWidth() - SectPr.Get_PageMargin_Right();
var ColumnsCount = SectPr.Get_ColumnsCount();
var ColumnAbs = (StartColumnIndex + ElementPageIndex) - ((StartColumnIndex + ElementPageIndex) / ColumnsCount | 0) * ColumnsCount;
var PageAbs = StartPageIndex + ((StartColumnIndex + ElementPageIndex) / ColumnsCount | 0);
var SectionIndex = this.FullRecalc.SectionIndex;
if (this.Pages[PageAbs] && this.Pages[PageAbs].Sections[SectionIndex])
......@@ -2251,8 +2252,10 @@ CDocument.prototype.Recalculate_Page = function()
//console.log( "Regular Recalc " + PageIndex );
var StartPos = this.Get_PageContentStartPos(PageIndex, StartIndex);
this.Footnotes.Reset(PageIndex);
this.private_RecalculatePageFootnotes(PageIndex);
this.Footnotes.Reset(PageIndex, this.SectionsInfo.Get_SectPr(StartIndex).SectPr);
//this.private_RecalculatePageFootnotes(PageIndex);
this.Pages[PageIndex].ResetStartElement = this.FullRecalc.ResetStartElement;
this.Pages[PageIndex].X = StartPos.X;
......@@ -2459,7 +2462,7 @@ CDocument.prototype.Recalculate_PageColumn = function()
if (RecalcResult & recalcresultflags_Footnotes)
{
this.private_RecalculatePageFootnotes(PageIndex);
this.private_RecalculatePageFootnotes(PageIndex, ColumnIndex);
}
break;
......@@ -2753,9 +2756,9 @@ CDocument.prototype.Recalculate_PageColumn = function()
//console.log("LastRecalc: " + ((new Date().getTime() - this.StartTime) / 1000));
}
if (Index >= Count || _PageIndex > PageIndex)
if (Index >= Count || _PageIndex > PageIndex || _ColumnIndex > ColumnIndex)
{
this.private_RecalculateShiftFootnotes(PageIndex);
this.private_RecalculateShiftFootnotes(PageIndex, ColumnIndex);
}
if (true === bReDraw)
......@@ -2851,16 +2854,15 @@ CDocument.prototype.private_RecalculateIsNewSection = function(nPageAbs, nConten
return bNewSection;
};
CDocument.prototype.private_RecalculatePageFootnotes = function(PageIndex)
CDocument.prototype.private_RecalculatePageFootnotes = function(nPageAbs, nColumnAbs)
{
var PageMetrics = this.Get_PageContentStartPos(PageIndex);
this.Footnotes.Recalculate(PageIndex, PageMetrics.X, PageMetrics.XLimit, 0, 10000);
this.Footnotes.Recalculate(nPageAbs, nColumnAbs, 0, 10000);
};
CDocument.prototype.private_RecalculateShiftFootnotes = function(PageIndex)
CDocument.prototype.private_RecalculateShiftFootnotes = function(nPageAbs, nColumnAbs)
{
var FootnotesHeight = this.Footnotes.Get_Height(PageIndex);
var PageMetrics = this.Get_PageContentStartPos(PageIndex);
this.Footnotes.Shift(PageIndex, 0, PageMetrics.YLimit - FootnotesHeight);
var dFootnotesHeight = this.Footnotes.GetHeight(nPageAbs, nColumnAbs);
var oPageMetrics = this.Get_PageContentStartPos(nPageAbs);
this.Footnotes.Shift(nPageAbs, 0, oPageMetrics.YLimit - dFootnotesHeight);
};
CDocument.prototype.private_RecalculateFlowTable = function(RecalcInfo)
{
......@@ -6764,6 +6766,10 @@ CDocument.prototype.OnKeyDown = function(e)
bUpdateSelection = false;
bRetValue = keydownresult_PreventAll;
}
// else if (e.KeyCode === 113)
// {
// this.AddFootnote();
// }
else if (e.KeyCode == 121 && true === e.ShiftKey) // Shift + F10 - контекстное меню
{
var X_abs, Y_abs, oPosition, ConvertedPos;
......@@ -7400,7 +7406,7 @@ CDocument.prototype.Internal_Content_Add = function(Position, NewObject, bCheckT
// Запоминаем, что нам нужно произвести переиндексацию элементов
this.private_ReindexContent(Position);
};
CDocument.prototype.Internal_Content_Remove = function(Position, Count)
CDocument.prototype.Internal_Content_Remove = function(Position, Count, bCorrectionCheck)
{
var ChangePos = -1;
......@@ -7436,7 +7442,7 @@ CDocument.prototype.Internal_Content_Remove = function(Position, Count)
NextObj.Set_DocumentPrev(PrevObj);
// Проверим, что последний элемент не таблица
if (type_Table == this.Content[this.Content.length - 1].GetType())
if (false !== bCorrectionCheck && (this.Content.length <= 0 || type_Table == this.Content[this.Content.length - 1].GetType()))
this.Internal_Content_Add(this.Content.length, new Paragraph(this.DrawingDocument, this, 0, 0, 0, 0, 0));
// Обновим информацию о секциях
......
......@@ -68,6 +68,10 @@ function CDocumentContent(Parent, DrawingDocument, X, Y, XLimit, YLimit, Split,
this.XLimit = XLimit;
this.YLimit = YLimit;
this.StartPage = 0;
this.StartColumn = 0;
this.ColumnsCount = 1;
this.Parent = Parent;
this.DrawingDocument = null;
......@@ -8339,7 +8343,7 @@ CDocumentContent.prototype.Internal_Content_Add = function(Position, NewOb
this.private_ReindexContent(Position);
};
CDocumentContent.prototype.Internal_Content_Remove = function(Position, Count)
CDocumentContent.prototype.Internal_Content_Remove = function(Position, Count, bCorrectionCheck)
{
if (Position < 0 || Position >= this.Content.length || Count <= 0)
return;
......@@ -8371,7 +8375,7 @@ CDocumentContent.prototype.Internal_Content_Remove = function(Position, Count
NextObj.Set_DocumentPrev(PrevObj);
// Проверим, что последний элемент не таблица
if (type_Table == this.Content[this.Content.length - 1].GetType())
if (false !== bCorrectionCheck && (this.Content.length <= 0 || type_Table == this.Content[this.Content.length - 1].GetType()))
this.Internal_Content_Add(this.Content.length, new Paragraph(this.DrawingDocument, this, 0, 50, 50, this.XLimit, this.YLimit, this.bPresentation === true));
this.private_ReindexContent(Position);
......@@ -8418,11 +8422,13 @@ CDocumentContent.prototype.Get_AbsolutePage = function(CurPage)
};
CDocumentContent.prototype.Get_AbsoluteColumn = function(CurPage)
{
return this.Parent.Get_AbsoluteColumn(this.StartPage + CurPage);
return (this.StartColumn + CurPage) - (((this.StartColumn + CurPage) / this.ColumnsCount | 0) * this.ColumnsCount);
};
CDocumentContent.prototype.Set_StartPage = function(StartPage)
CDocumentContent.prototype.Set_StartPage = function(StartPage, StartColumn, ColumnsCount)
{
this.StartPage = StartPage;
this.StartColumn = undefined !== StartColumn ? StartColumn : 0;
this.ColumnsCount = undefined !== ColumnsCount ? ColumnsCount : 1;
};
// Приходит абсолютное значение страницы(по отношению к родительскому классу), на выходе - относительное
CDocumentContent.prototype.Get_Page_Relative = function(AbsPage)
......@@ -8431,7 +8437,7 @@ CDocumentContent.prototype.Get_Page_Relative = function(AbsPage)
};
CDocumentContent.prototype.Get_ColumnsCount = function()
{
return 1;
return this.ColumnsCount;
};
//-----------------------------------------------------------------------------------
// Undo/Redo функции
......
......@@ -111,25 +111,55 @@ CFootnotesController.prototype.Create_Footnote = function()
/**
* Сбрасываем рассчетные данный для заданной страницы.
* @param {number} nPageIndex
* @param {CSectionPr} oSectPr
*/
CFootnotesController.prototype.Reset = function(nPageIndex)
CFootnotesController.prototype.Reset = function(nPageIndex, oSectPr)
{
if (!this.Pages[nPageIndex])
this.Pages[nPageIndex] = new CFootEndnotePage();
this.Pages[nPageIndex].Reset();
var oPage = this.Pages[nPageIndex];
oPage.Reset();
var X = oSectPr.Get_PageMargin_Left();
var XLimit = oSectPr.Get_PageWidth() - oSectPr.Get_PageMargin_Right();
var nColumnsCount = oSectPr.Get_ColumnsCount();
for (var nColumnIndex = 0; nColumnIndex < nColumnsCount; ++nColumnIndex)
{
var _X = X;
for (var nTempColumnIndex = 0; nTempColumnIndex < nColumnIndex; ++nTempColumnIndex)
{
_X += oSectPr.Get_ColumnWidth(nTempColumnIndex);
_X += oSectPr.Get_ColumnSpace(nTempColumnIndex);
}
var _XLimit = (nColumnsCount - 1 !== nColumnIndex ? X + oSectPr.Get_ColumnWidth(nColumnIndex) : XLimit);
var oColumn = new CFootEndnotePageColumn();
oColumn.X = _X;
oColumn.XLimit = _XLimit;
oPage.AddColumn(oColumn);
}
oPage.X = X;
oPage.XLimit = XLimit;
};
/**
* Пересчитываем сноски на заданной странице.
*/
CFootnotesController.prototype.Recalculate = function(nPageIndex, X, XLimit, Y, YLimit)
CFootnotesController.prototype.Recalculate = function(nPageAbs, nColumnAbs, Y, YLimit)
{
if (!this.Pages[nPageIndex])
this.Pages[nPageIndex] = new CFootEndnotePage();
if (true === this.Is_EmptyPage(nPageIndex))
if (true === this.IsEmptyPageColumn(nPageAbs, nColumnAbs))
return;
var oPage = this.Pages[nPageAbs];
var oColumn = oPage.Columns[nColumnAbs];
var nColumnsCount = oPage.Columns.length;
var X = oColumn.X;
var XLimit = oColumn.XLimit;
// Мы пересчет начинаем с 0, потом просто делаем сдвиг, через функцию Shift.
var CurY = Y;
......@@ -138,19 +168,19 @@ CFootnotesController.prototype.Recalculate = function(nPageIndex, X, XLimit, Y,
{
this.SeparatorFootnote.Prepare_RecalculateObject();
this.SeparatorFootnote.Reset(X, CurY, XLimit, 10000);
this.SeparatorFootnote.Set_StartPage(nPageIndex);
this.SeparatorFootnote.Set_StartPage(nPageAbs, nColumnAbs, nColumnsCount);
this.SeparatorFootnote.Recalculate_Page(0, true);
this.Pages[nPageIndex].SeparatorRecalculateObject = this.SeparatorFootnote.Save_RecalculateObject();
oColumn.SeparatorRecalculateObject = this.SeparatorFootnote.Save_RecalculateObject();
var Bounds = this.SeparatorFootnote.Get_PageBounds(0);
CurY += Bounds.Bottom - Bounds.Top;
}
for (var nIndex = 0; nIndex < this.Pages[nPageIndex].Elements.length; ++nIndex)
for (var nIndex = 0; nIndex < oColumn.Elements.length; ++nIndex)
{
var Footnote = this.Pages[nPageIndex].Elements[nIndex];
var Footnote = oColumn.Elements[nIndex];
Footnote.Reset(X, CurY, XLimit, 10000);
Footnote.Set_StartPage(nPageIndex);
Footnote.Set_StartPage(nPageAbs, nColumnAbs, nColumnCount);
var CurPage = 0;
var RecalcResult = recalcresult2_NextPage;
......@@ -163,25 +193,28 @@ CFootnotesController.prototype.Recalculate = function(nPageIndex, X, XLimit, Y,
};
/**
* Получаем суммарную высоту, занимаемую сносками на заданной странице.
* @param {number} nPageIndex
* @param {number} nPageAbs
* @param {number} nColumnAbs
* @returns {number}
*/
CFootnotesController.prototype.Get_Height = function(nPageIndex)
CFootnotesController.prototype.GetHeight = function(nPageAbs, nColumnAbs)
{
if (true === this.Is_EmptyPage(nPageIndex))
if (true === this.IsEmptyPageColumn(nPageAbs, nColumnAbs))
return 0;
var nHeight = 0;
var oColumn = this.Pages[nPageAbs].Columns[nColumnAbs];
if (null !== this.SeparatorFootnote)
var nHeight = 0;
if (null !== oColumn.SeparatorRecalculateObject)
{
this.SeparatorFootnote.Load_RecalculateObject(oColumn.SeparatorRecalculateObject);
var Bounds = this.SeparatorFootnote.Get_PageBounds(0);
nHeight += Bounds.Bottom - Bounds.Top;
}
for (var nIndex = 0; nIndex < this.Pages[nPageIndex].Elements.length; ++nIndex)
for (var nIndex = 0, nCount = oColumn.Element.length; nIndex < nCount; ++nIndex)
{
var Footnote = this.Pages[nPageIndex].Elements[nIndex];
var Footnote = oColumn.Elements[nIndex];
var Bounds = Footnote.Get_PageBounds(0);
nHeight += Bounds.Bottom - Bounds.Top;
}
......@@ -237,10 +270,12 @@ CFootnotesController.prototype.Shift = function(nPageIndex, dX, dY)
/**
* Добавляем заданную сноску на страницу для пересчета.
* @param {number} nPageAbs
* @param {number} nColumnAbs
* @param {CFootEndnote} oFootnote
*/
CFootnotesController.prototype.AddFootnoteToPage = function(nPageAbs, oFootnote)
CFootnotesController.prototype.AddFootnoteToPage = function(nPageAbs, nColumnAbs, oFootnote)
{
if (!this.Pages[nPageAbs])
this.Pages[nPageAbs] = new CFootEndnotePage();
......@@ -331,7 +366,22 @@ CFootnotesController.prototype.OnContentReDraw = function(StartPageAbs, EndPageA
*/
CFootnotesController.prototype.Is_EmptyPage = function(nPageIndex)
{
if (!this.Pages[nPageIndex] || this.Pages[nPageIndex].Elements.length <= 0)
var oPage = this.Pages[nPageIndex];
if (!oPage)
return true;
for (var nColumnIndex = 0, nColumnsCount = oPage.Columns.length; nColumnIndex < nColumnsCount; ++nColumnIndex)
{
if (true !== this.IsEmptyPageColumn(nPageIndex, nColumnIndex))
return false;
}
return true;
};
CFootnotesController.prototype.IsEmptyPageColumn = function(nPageIndex, nColumnIndex)
{
var oColumn = this.private_GetPageColumn(nPageIndex, nColumnIndex);
if (!oColumn || oColumn.Elements.length <= 0)
return true;
return false;
......@@ -658,6 +708,18 @@ CFootnotesController.prototype.AddFootnoteRef = function()
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Private area
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CFootnotesController.prototype.private_GetPageColumn = function(nPageAbs, nColumnAbs)
{
var oPage = this.Pages[nPageAbs];
if (!oPage)
return null;
var oColumn = oPage.Columns[nColumnAbs]
if (!oColumn)
return null;
return oColumn;
};
CFootnotesController.prototype.private_GetFootnoteOnPageByXY = function(X, Y, PageAbs)
{
if (true === this.Is_EmptyPage(PageAbs))
......@@ -2663,6 +2725,33 @@ CFootnotesController.prototype.GetColumnSize = function()
};
function CFootEndnotePageColumn()
{
this.X = 0;
this.Y = 0;
this.XLimit = 0;
this.YLimit = 0;
this.Elements = [];
this.SeparatorRecalculateObject = null;
this.ContinuationSeparatorRecalculateObject = null;
this.ContinuationNoticeRecalculateObject = null;
}
CFootEndnotePageColumn.prototype.Reset = function()
{
this.X = 0;
this.Y = 0;
this.XLimit = 0;
this.YLimit = 0;
this.Elements = [];
this.SeparatorRecalculateObject = null;
this.ContinuationSeparatorRecalculateObject = null;
this.ContinuationNoticeRecalculateObject = null;
};
function CFootEndnotePage()
{
this.X = 0;
......@@ -2675,6 +2764,8 @@ function CFootEndnotePage()
this.SeparatorRecalculateObject = null;
this.ContinuationSeparatorRecalculateObject = null;
this.ContinuationNoticeRecalculateObject = null;
this.Columns = [];
}
CFootEndnotePage.prototype.Reset = function()
{
......@@ -2688,4 +2779,10 @@ CFootEndnotePage.prototype.Reset = function()
this.SeparatorRecalculateObject = null;
this.ContinuationSeparatorRecalculateObject = null;
this.ContinuationNoticeRecalculateObject = null;
this.Columns = [];
};
CFootEndnotePage.prototype.AddColumn = function(oColumn)
{
this.Columns.push(oColumn);
};
\ No newline at end of file
......@@ -1853,7 +1853,7 @@ Paragraph.prototype.private_RecalculateLineCheckFootnotes = function(CurLine, Cu
var PageAbs = this.Get_AbsolutePage(CurPage);
RecalcInfo.Set_FootnoteReference(oFootnote, PageAbs);
this.Parent.Footnotes.AddFootnoteToPage(PageAbs, oFootnote);
PRS.RecalcResult = recalcresult_CurPage | recalcresultflags_Page | recalcresultflags_Footnotes;
PRS.RecalcResult = recalcresult_CurPage | recalcresultflags_Column | recalcresultflags_Footnotes;
return false;
}
else if (true === RecalcInfo.Check_FootnoteReference(oFootnote))
......@@ -1874,7 +1874,7 @@ Paragraph.prototype.private_RecalculateLineCheckFootnotes = function(CurLine, Cu
// TODO: Реализовать
RecalcInfo.Set_PageBreaFlowObjectPageBreakBefore(true);
this.Parent.Footnotes.RemoveFootnoteFromPage(PageAbs, oFootnote);
PRS.RecalcResult = recalcresult_CurPage | recalcresultflags_Page | recalcresultflags_Footnotes;
PRS.RecalcResult = recalcresult_CurPage | recalcresultflags_Column | recalcresultflags_Footnotes;
return false;
}
}
......
......@@ -1106,7 +1106,7 @@
*/
ApiDocumentContent.prototype.RemoveAllElements = function()
{
this.Document.Content = [];
this.Document.Internal_Content_Remove(0, this.Document.Content.length, false);
};
/**
* Remove element by specified position.
......
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