Skip to content

Commit

Permalink
[de] Rework recalculation states for paragraph
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillovIlya committed Sep 20, 2023
1 parent 89c079c commit 64a250b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 80 deletions.
23 changes: 8 additions & 15 deletions word/Editor/Paragraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,6 @@ function Paragraph(DrawingDocument, Parent, bFromPresentation)

this.Content[0] = EndRun;

this.m_oPRSW = null;//g_PRSW;//new CParagraphRecalculateStateWrap(this);
this.m_oPRSC = null;//g_PRSC;//new CParagraphRecalculateStateCounter();
this.m_oPRSA = null;//g_PRSA;//new CParagraphRecalculateStateAlign();
this.m_oPDSE = g_PDSE;//new CParagraphDrawStateElements();

this.StartState = null;

this.CollPrChange = false;
Expand Down Expand Up @@ -1463,7 +1458,7 @@ Paragraph.prototype.RecalculateEndInfo = function(isFast)
if (prevEndInfo && !prevEndInfo.CheckRecalcId(recalcId))
return;

let prsi = AscWord.ParagraphRecalculateStateManager.getEndInfo();
let prsi = AscWord.ParagraphRecalculateStateManager.getEndInfoState();
prsi.Reset(prevEndInfo);
prsi.setFast(!!isFast);

Expand Down Expand Up @@ -1505,7 +1500,7 @@ Paragraph.prototype.Recalculate_PageEndInfo = function(PRSW, CurPage)
{
var PrevInfo = ( 0 === CurPage ? this.Parent.GetPrevElementEndInfo(this) : this.Pages[CurPage - 1].EndInfo.Copy() );

var PRSI = AscWord.ParagraphRecalculateStateManager.getEndInfo();
var PRSI = AscWord.ParagraphRecalculateStateManager.getEndInfoState();

PRSI.Reset(PrevInfo);

Expand Down Expand Up @@ -2106,7 +2101,7 @@ Paragraph.prototype.Internal_Draw_3 = function(CurPage, pGraphics, Pr)
if (true === bDrawBorders && 0 === CurPage && true === this.private_IsEmptyPageWithBreak(CurPage))
bDrawBorders = false;

var PDSH = g_oPDSH;
var PDSH = g_PDSH;

PDSH.ComplexFields.ResetPage(this, CurPage);

Expand Down Expand Up @@ -2823,7 +2818,7 @@ Paragraph.prototype.Internal_Draw_3 = function(CurPage, pGraphics, Pr)
};
Paragraph.prototype.Internal_Draw_4 = function(CurPage, pGraphics, Pr, BgColor, Theme, ColorMap)
{
var PDSE = this.m_oPDSE;
var PDSE = g_PDSE;
PDSE.Reset(this, pGraphics, BgColor, Theme, ColorMap);
PDSE.ComplexFields.ResetPage(this, CurPage);

Expand Down Expand Up @@ -3129,7 +3124,7 @@ Paragraph.prototype.Internal_Draw_4 = function(CurPage, pGraphics, Pr, BgColor,
};
Paragraph.prototype.Internal_Draw_5 = function(CurPage, pGraphics, Pr, BgColor)
{
var PDSL = g_oPDSL;
var PDSL = g_PDSL;
PDSL.Reset(this, pGraphics, BgColor);
PDSL.ComplexFields.ResetPage(this, CurPage);

Expand Down Expand Up @@ -19545,8 +19540,6 @@ CParagraphDrawStateElements.prototype =
}
};

let g_PDSE = new CParagraphDrawStateElements();

function CParagraphDrawStateLines()
{
this.Paragraph = undefined;
Expand Down Expand Up @@ -19662,9 +19655,9 @@ CParagraphDrawStateLines.prototype.IsUnderlineTrailSpace = function()
return this.UlTrailSpace;
};

var g_oPDSH = new CParagraphDrawStateHighlights();
//var g_oPDSE = new CParagraphDrawStateElements();
var g_oPDSL = new CParagraphDrawStateLines();
let g_PDSH = new CParagraphDrawStateHighlights();
let g_PDSE = new CParagraphDrawStateElements();
let g_PDSL = new CParagraphDrawStateLines();

//----------------------------------------------------------------------------------------------------------------------
// Классы для работы с курсором
Expand Down
99 changes: 42 additions & 57 deletions word/Editor/Paragraph_Recalculate.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,10 @@ Paragraph.prototype.StartFromNewPage = function()
*/
Paragraph.prototype.recalculateRangeFast = function(iRange, iLine)
{
this.m_oPRSW = AscWord.ParagraphRecalculateStateManager.getWrap();

let result = this.private_RecalculateFastRange(this.m_oPRSW, iRange, iLine);

AscWord.ParagraphRecalculateStateManager.release(this.m_oPRSW);
let wrapState = AscWord.ParagraphRecalculateStateManager.getWrapState();
wrapState.SetFast(true);
let result = this.private_RecalculateFastRange(wrapState, iRange, iLine);
AscWord.ParagraphRecalculateStateManager.release(wrapState);
return result;
};
Paragraph.prototype.private_RecalculateFastRange = function(PRS, CurRange, CurLine)
Expand Down Expand Up @@ -661,26 +660,15 @@ Paragraph.prototype.private_RecalculateFastRange = function(PRS, CurRange,
};
Paragraph.prototype.private_RecalculatePage = function(CurPage, isFast)
{
this.m_oPRSW = AscWord.ParagraphRecalculateStateManager.getWrap();
this.m_oPRSC = AscWord.ParagraphRecalculateStateManager.getCounter();
this.m_oPRSA = AscWord.ParagraphRecalculateStateManager.getAlign();

this.m_oPRSW.SetFast(isFast);

let result = this.private_RecalculatePageInternal(this.m_oPRSW, CurPage, true);

AscWord.ParagraphRecalculateStateManager.release(this.m_oPRSW);
AscWord.ParagraphRecalculateStateManager.release(this.m_oPRSC);
AscWord.ParagraphRecalculateStateManager.release(this.m_oPRSA);
let wrapState = AscWord.ParagraphRecalculateStateManager.getWrapState();
wrapState.SetFast(isFast);
let result = this.private_RecalculatePageInternal(wrapState, CurPage, true);
AscWord.ParagraphRecalculateStateManager.release(wrapState);
return result;
};
Paragraph.prototype.private_RecalculatePageInternal = function(PRS, CurPage, bFirstRecalculate)
{
PRS.Reset_Page(this, CurPage);

this.m_oPRSW.ComplexFields.ResetPage(this, CurPage);
this.m_oPRSC.ComplexFields.ResetPage(this, CurPage);
this.m_oPRSA.ComplexFields.ResetPage(this, CurPage);

var Pr = this.Get_CompiledPr();
var ParaPr = Pr.ParaPr;
Expand Down Expand Up @@ -1913,8 +1901,8 @@ Paragraph.prototype.private_RecalculateLineAlign = function(CurLine, CurPa
// промежутке, увеличиваем их на столько, чтобы правая граница последнего
// слова совпала с правой границей промежутка
var PRSW = PRS;
var PRSC = this.m_oPRSC;
var PRSA = this.m_oPRSA;
var PRSC = PRS.getCounterState();
var PRSA = PRS.getAlignState();
PRSA.Paragraph = this;
PRSA.LastW = 0;
PRSA.RecalcFast = Fast;
Expand Down Expand Up @@ -2259,10 +2247,8 @@ Paragraph.prototype.private_RecalculateRangeEndPos = function(PRS, PRP, Dept
this.Lines[CurLine].Set_RangeEndPos( CurRange, CurPos );
};

Paragraph.prototype.private_RecalculateGetTabPos = function(X, ParaPr, CurPage, NumTab)
Paragraph.prototype.private_RecalculateGetTabPos = function(PRS, X, ParaPr, CurPage, NumTab)
{
var PRS = this.m_oPRSW;

var PageStart = this.Parent.Get_PageContentStartPos2(this.PageNum, this.ColumnNum, CurPage, this.Index);
if ( undefined != this.Get_FramePr() )
PageStart.X = 0;
Expand Down Expand Up @@ -3168,8 +3154,6 @@ ParagraphRecalculateStateBase.prototype.unlock = function()
function ParagraphRecalculateStateManager()
{
this.wrap = [];
this.counter = [];
this.align = [];
this.endInfo = [];
}
ParagraphRecalculateStateManager.prototype.getInstance = function(pool, className)
Expand Down Expand Up @@ -3197,19 +3181,11 @@ ParagraphRecalculateStateManager.prototype.release = function(instance)
{
instance.unlock();
};
ParagraphRecalculateStateManager.prototype.getWrap = function()
ParagraphRecalculateStateManager.prototype.getWrapState = function()
{
return this.getInstance(this.wrap, CParagraphRecalculateStateWrap);
};
ParagraphRecalculateStateManager.prototype.getCounter = function()
{
return this.getInstance(this.counter, CParagraphRecalculateStateCounter);
};
ParagraphRecalculateStateManager.prototype.getAlign = function()
{
return this.getInstance(this.align, CParagraphRecalculateStateAlign);
};
ParagraphRecalculateStateManager.prototype.getEndInfo = function()
ParagraphRecalculateStateManager.prototype.getEndInfoState = function()
{
return this.getInstance(this.endInfo, CParagraphRecalculateStateInfo);
};
Expand All @@ -3232,6 +3208,9 @@ function CParagraphRecalculateStateWrap()
this.BalanceSBDB = false; // BalanceSingleByteDoubleByteWidth

this.Fast = false; // Быстрый ли пересчет

this.alignState = new CParagraphRecalculateStateAlign(this);
this.counterState = new CParagraphRecalculateStateCounter(this);

//
this.Page = 0;
Expand Down Expand Up @@ -3356,6 +3335,14 @@ function CParagraphRecalculateStateWrap()
CParagraphRecalculateStateWrap.prototype = Object.create(ParagraphRecalculateStateBase.prototype);
CParagraphRecalculateStateWrap.prototype.constructor = CParagraphRecalculateStateWrap;

CParagraphRecalculateStateWrap.prototype.getAlignState = function()
{
return this.alignState;
};
CParagraphRecalculateStateWrap.prototype.getCounterState = function()
{
return this.counterState;
};
CParagraphRecalculateStateWrap.prototype.Reset_Page = function(Paragraph, CurPage)
{
this.Paragraph = Paragraph;
Expand All @@ -3372,6 +3359,10 @@ CParagraphRecalculateStateWrap.prototype.Reset_Page = function(Paragraph, CurPag
this.Page = CurPage;
this.RunRecalcInfoLast = (0 === CurPage ? null : Paragraph.Pages[CurPage - 1].EndInfo.RunRecalcInfo);
this.RunRecalcInfoBreak = this.RunRecalcInfoLast;

this.ComplexFields.ResetPage(Paragraph, CurPage);
this.alignState.ComplexFields.ResetPage(Paragraph, CurPage);
this.counterState.ComplexFields.ResetPage(Paragraph, CurPage);
};
CParagraphRecalculateStateWrap.prototype.Reset_Line = function()
{
Expand Down Expand Up @@ -3721,7 +3712,7 @@ CParagraphRecalculateStateWrap.prototype.Recalculate_Numbering = function(Item,
}
case Asc.c_oAscNumberingSuff.Tab:
{
var NewX = Para.private_RecalculateGetTabPos(X, ParaPr, CurPage, true).NewX;
var NewX = Para.private_RecalculateGetTabPos(this, X, ParaPr, CurPage, true).NewX;

NumberingItem.WidthSuff = NewX - X;

Expand Down Expand Up @@ -3862,6 +3853,10 @@ CParagraphRecalculateStateWrap.prototype.IsFastRecalculate = function()
{
return this.Fast;
};
CParagraphRecalculateStateWrap.prototype.isFastRecalculation = function()
{
return this.Fast;
};
CParagraphRecalculateStateWrap.prototype.GetPageAbs = function()
{
return this.PageAbs;
Expand Down Expand Up @@ -4070,13 +4065,9 @@ CParagraphRecalculateStateWrap.prototype.IsLastElementInWord = function(oRun, nP
return (!oNextItem || !oNextItem.IsText());
};


const g_PRSW = new CParagraphRecalculateStateWrap();

function CParagraphRecalculateStateCounter()
function CParagraphRecalculateStateCounter(wrapState)
{
ParagraphRecalculateStateBase.call(this);

this.wrapState = wrapState;
this.Paragraph = undefined;
this.Range = undefined;
this.Word = false;
Expand All @@ -4091,9 +4082,6 @@ function CParagraphRecalculateStateCounter()

this.ComplexFields = new CParagraphComplexFieldsInfo();
}
CParagraphRecalculateStateCounter.prototype = Object.create(ParagraphRecalculateStateBase.prototype);
CParagraphRecalculateStateCounter.prototype.constructor = CParagraphRecalculateStateCounter;

CParagraphRecalculateStateCounter.prototype.Reset = function(Paragraph, Range)
{
this.Paragraph = Paragraph;
Expand All @@ -4108,12 +4096,14 @@ CParagraphRecalculateStateCounter.prototype.Reset = function(Paragraph, Range)
this.SpacesSkip = 0;
this.LettersSkip = 0;
};
CParagraphRecalculateStateCounter.prototype.isFastRecalculation = function()
{
return this.wrapState.isFastRecalculation();
};

const g_PRSC = new CParagraphRecalculateStateCounter();

function CParagraphRecalculateStateAlign()
function CParagraphRecalculateStateAlign(wrapState)
{
ParagraphRecalculateStateBase.call(this);
this.wrapState = wrapState;
this.X = 0; // Текущая позиция по горизонтали
this.Y = 0; // Текущая позиция по вертикали
this.XEnd = 0; // Предельная позиция по горизонтали
Expand All @@ -4138,16 +4128,11 @@ function CParagraphRecalculateStateAlign()

this.ComplexFields = new CParagraphComplexFieldsInfo();
}
CParagraphRecalculateStateAlign.prototype = Object.create(ParagraphRecalculateStateBase.prototype);
CParagraphRecalculateStateAlign.prototype.constructor = CParagraphRecalculateStateAlign;
CParagraphRecalculateStateAlign.prototype.IsFastRangeRecalc = function()
{
return this.RecalcFast;
};


const g_PRSA = new CParagraphRecalculateStateAlign();

function CParagraphRecalculateStateInfo()
{
ParagraphRecalculateStateBase.call(this);
Expand All @@ -4161,7 +4146,7 @@ CParagraphRecalculateStateInfo.prototype.setFast = function(isFast)
{
this.fast = isFast;
};
CParagraphRecalculateStateInfo.prototype.isFast = function()
CParagraphRecalculateStateInfo.prototype.isFastRecalculation = function()
{
return this.fast;
};
Expand Down
13 changes: 5 additions & 8 deletions word/Editor/Run.js
Original file line number Diff line number Diff line change
Expand Up @@ -4499,7 +4499,7 @@ ParaRun.prototype.Recalculate_Range = function(PRS, ParaPr, Depth)
SpaceLen = 0;
WordLen = 0;

var TabPos = Para.private_RecalculateGetTabPos(X, ParaPr, PRS.Page, false);
var TabPos = Para.private_RecalculateGetTabPos(PRS, X, ParaPr, PRS.Page, false);
var NewX = TabPos.NewX;
var TabValue = TabPos.TabValue;

Expand Down Expand Up @@ -5242,7 +5242,7 @@ ParaRun.prototype.Recalculate_Range_Width = function(PRSC, _CurLine, _CurRange)
}
case para_FieldChar:
{
if (this.Paragraph && this.Paragraph.m_oPRSW.IsFastRecalculate())
if (PRSC.isFastRecalculation())
PRSC.ComplexFields.ProcessFieldChar(Item);
else
PRSC.ComplexFields.ProcessFieldCharAndCollectComplexField(Item);
Expand Down Expand Up @@ -5270,14 +5270,11 @@ ParaRun.prototype.Recalculate_Range_Width = function(PRSC, _CurLine, _CurRange)
}
case para_InstrText:
{
if (this.Paragraph && this.Paragraph.m_oPRSW.IsFastRecalculate())
break;

if (reviewtype_Remove === this.GetReviewType())
if (PRSC.isFastRecalculation()
|| reviewtype_Remove === this.GetReviewType())
break;

PRSC.ComplexFields.ProcessInstruction(Item);

break;
}
}
Expand Down Expand Up @@ -5702,7 +5699,7 @@ ParaRun.prototype.RecalculateEndInfo = function(PRSI)
{
var isRemovedInReview = (reviewtype_Remove === this.GetReviewType());

if (PRSI.isFast() || (this.Paragraph && this.Paragraph.bFromDocument === false))
if (PRSI.isFastRecalculation() || (this.Paragraph && this.Paragraph.bFromDocument === false))
return;

for (var nCurPos = 0, nCount = this.Content.length; nCurPos < nCount; ++nCurPos)
Expand Down

0 comments on commit 64a250b

Please sign in to comment.