Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/improve memory performance #3686

Merged
merged 7 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 6 additions & 52 deletions word/Editor/Paragraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -977,22 +977,7 @@ Paragraph.prototype.Internal_Content_Add = function(Pos, Item)
if (ContentPos.Data[0] >= Pos)
ContentPos.Data[0]++;
}

// Передвинем все метки слов для проверки орфографии
for (var nIndex = 0, nCount = this.SpellChecker.Elements.length; nIndex < nCount; ++nIndex)
{
var Element = this.SpellChecker.Elements[nIndex];
var ContentPos = Element.StartPos;

if (ContentPos.Data[0] >= Pos)
ContentPos.Data[0]++;

ContentPos = Element.EndPos;

if (ContentPos.Data[0] >= Pos)
ContentPos.Data[0]++;
}


if (Item.SetParent)
Item.SetParent(this);

Expand Down Expand Up @@ -1106,20 +1091,6 @@ Paragraph.prototype.Internal_Content_Remove = function(Pos)
if (true === this.DeleteCommentOnRemove && para_Comment === Item.Type && this.LogicDocument)
this.LogicDocument.RemoveComment(Item.CommentId, true, false);

for (var nIndex = 0, nCount = this.SpellChecker.Elements.length; nIndex < nCount; ++nIndex)
{
var Element = this.SpellChecker.Elements[nIndex];
var ContentPos = Element.StartPos;

if (ContentPos.Data[0] > Pos)
ContentPos.Data[0]--;

ContentPos = Element.EndPos;

if (ContentPos.Data[0] > Pos)
ContentPos.Data[0]--;
}

this.OnContentChange();
};
/**
Expand Down Expand Up @@ -14488,20 +14459,6 @@ Paragraph.prototype.private_CheckDropCapForSpellCheck = function()

oElement.SetCorrect();
};
Paragraph.prototype.AddSpellCheckerElement = function(oElement)
{
let oRun = this.GetClassByPos(oElement.GetStartPos());
if (!oRun || !oRun.IsRun())
return;

oRun.AddSpellCheckerElement(oElement, true);

oRun = this.GetClassByPos(oElement.GetEndPos());
if (!oRun || !oRun.IsRun())
return;

oRun.AddSpellCheckerElement(oElement, false);
};
Paragraph.prototype.ReplaceMisspelledWord = function(Word, oElement)
{
var Element = null;
Expand Down Expand Up @@ -14531,16 +14488,13 @@ Paragraph.prototype.ReplaceMisspelledWord = function(Word, oElement)
Word = Word.substr(1);

// Сначала вставим новое слово
var Class = Element.StartRun;
if (para_Run !== Class.Type || Element.StartPos.Data.Depth <= 0)
return;

var RunPos = Element.StartPos.Data[Element.StartPos.Depth - 1];
Class.AddText(Word, RunPos);
var startRun = Element.GetStartRun();
var inRunPos = Element.GetStartInRunPos();
startRun.AddText(Word, inRunPos);

// Удалим старое слово
var StartPos = Element.StartPos;
var EndPos = Element.EndPos;
var StartPos = Element.GetStartPos();
var EndPos = Element.GetEndPos();

// Если комментарии попадают в текст, тогда сначала их надо отдельно удалить
var CommentsToDelete = {};
Expand Down
116 changes: 58 additions & 58 deletions word/Editor/Paragraph/RunContent/Tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ var tab_Symbol = 0x0022;//0x2192;

(function(window)
{
let tabWidth = null;

function getTabActualWidth()
{
if (null !== tabWidth)
return tabWidth;

g_oTextMeasurer.SetFont({FontFamily : {Name : "ASCW3", Index : -1}, FontSize : 10, Italic : false, Bold : false});
tabWidth = g_oTextMeasurer.Measure(String.fromCharCode(tab_Symbol)).Width;
return tabWidth;
}

// TODO: Реализовать табы по точке и с чертой (tab_Bar tab_Decimal)

Expand All @@ -56,15 +67,10 @@ var tab_Symbol = 0x0022;//0x2192;
function CRunTab()
{
AscWord.CRunElementBase.call(this);

this.Width = 0;
this.WidthVisible = 0;
this.RealWidth = 0;

this.DotWidth = 0;
this.UnderscoreWidth = 0;
this.HyphenWidth = 0;
this.Leader = Asc.c_oAscTabLeader.None;

this.Width = 0;
this.LeaderCode = 0x00;
this.LeaderWidth = 0;
}
CRunTab.prototype = Object.create(AscWord.CRunElementBase.prototype);
CRunTab.prototype.constructor = CRunTab;
Expand All @@ -76,83 +82,75 @@ var tab_Symbol = 0x0022;//0x2192;
};
CRunTab.prototype.Draw = function(X, Y, Context)
{
if (this.WidthVisible > 0.01)
if (this.Width > 0.01 && 0 !== this.LeaderCode)
{
var sChar = null, nCharWidth = 0;
switch (this.Leader)
{
case Asc.c_oAscTabLeader.Dot:
sChar = '.';
nCharWidth = this.DotWidth;
break;
case Asc.c_oAscTabLeader.Heavy:
case Asc.c_oAscTabLeader.Underscore:
sChar = '_';
nCharWidth = this.UnderscoreWidth;
break;
case Asc.c_oAscTabLeader.Hyphen:
sChar = '-';
nCharWidth = this.HyphenWidth;
break;
case Asc.c_oAscTabLeader.MiddleDot:
sChar = '·';
nCharWidth = this.MiddleDotWidth;
break;
}

if (null !== sChar && nCharWidth > 0.001)
{
Context.SetFontSlot(AscWord.fontslot_ASCII, 1);
var nCharsCount = Math.floor(this.WidthVisible / nCharWidth);

var _X = X + (this.WidthVisible - nCharsCount * nCharWidth) / 2;
for (var nIndex = 0; nIndex < nCharsCount; ++nIndex, _X += nCharWidth)
Context.FillText(_X, Y, sChar);
}
Context.SetFontSlot(AscWord.fontslot_ASCII, 1);
var nCharsCount = Math.floor(this.Width / this.LeaderWidth);

var _X = X + (this.Width - nCharsCount * this.LeaderWidth) / 2;
for (var nIndex = 0; nIndex < nCharsCount; ++nIndex, _X += this.LeaderWidth)
Context.FillTextCode(_X, Y, this.LeaderCode);
}

if (editor && editor.ShowParaMarks)
{
Context.p_color(0, 0, 0, 255);
Context.b_color1(0, 0, 0, 255);

var X0 = this.Width / 2 - this.RealWidth / 2;
let tabActualWidth = getTabActualWidth();
var X0 = this.Width / 2 - tabActualWidth / 2;

Context.SetFont({FontFamily : {Name : "ASCW3", Index : -1}, FontSize : 10, Italic : false, Bold : false});

if (X0 > 0)
Context.FillText2(X + X0, Y, String.fromCharCode(tab_Symbol), 0, this.Width);
else
Context.FillText2(X, Y, String.fromCharCode(tab_Symbol), this.RealWidth - this.Width, this.Width);
Context.FillText2(X, Y, String.fromCharCode(tab_Symbol), tabActualWidth - this.Width, this.Width);
}
};
CRunTab.prototype.Measure = function(Context)
{
Context.SetFontSlot(AscWord.fontslot_ASCII, 1);

this.DotWidth = Context.Measure(".").Width;
this.UnderscoreWidth = Context.Measure("_").Width;
this.HyphenWidth = Context.Measure("-").Width * 1.5;
this.MiddleDotWidth = Context.Measure("·").Width;

Context.SetFont({FontFamily : {Name : "ASCW3", Index : -1}, FontSize : 10, Italic : false, Bold : false});
this.RealWidth = Context.Measure(String.fromCharCode(tab_Symbol)).Width;
};
CRunTab.prototype.SetLeader = function(nLeaderType)
CRunTab.prototype.SetLeader = function(leaderType, textPr)
{
this.Leader = nLeaderType;
g_oTextMeasurer.SetTextPr(textPr);
g_oTextMeasurer.SetFontSlot(AscWord.fontslot_ASCII, 1);

switch (leaderType)
{
case Asc.c_oAscTabLeader.Dot: // "."
this.LeaderCode = 0x002E;
this.LeaderWidth = g_oTextMeasurer.MeasureCode(0x002E).Width;
break;
case Asc.c_oAscTabLeader.Heavy: // "_"
case Asc.c_oAscTabLeader.Underscore:
this.LeaderCode = 0x005F;
this.LeaderWidth = g_oTextMeasurer.MeasureCode(0x005F).Width;
break;
case Asc.c_oAscTabLeader.Hyphen: // "-"
this.LeaderCode = 0x002D;
this.LeaderWidth = g_oTextMeasurer.MeasureCode(0x002D).Width * 1.5;
break;
case Asc.c_oAscTabLeader.MiddleDot: // "·"
this.LeaderCode = 0x00B7;
this.LeaderWidth = g_oTextMeasurer.MeasureCode(0x00B7).Width;
break;
default:
this.LeaderCode = 0x00;
this.LeaderWidth = 0;
break;
}
};
CRunTab.prototype.GetWidth = function()
{
return this.Width;
};
CRunTab.prototype.GetWidthVisible = function()
{
return this.WidthVisible;
return this.Width;
};
CRunTab.prototype.SetWidthVisible = function(WidthVisible)
{
this.WidthVisible = WidthVisible;
};
CRunTab.prototype.Copy = function()
{
Expand All @@ -166,13 +164,15 @@ var tab_Symbol = 0x0022;//0x2192;
{
return {
Width : this.Width,
WidthVisible : this.WidthVisible
LeaderCode : this.LeaderCode,
LeaderWidth : this.LeaderWidth
};
};
CRunTab.prototype.LoadRecalculateObject = function(RecalcObj)
{
this.Width = RecalcObj.Width;
this.WidthVisible = RecalcObj.WidthVisible;
this.LeaderCode = RecalcObj.LeaderCode;
this.LeaderWidth = RecalcObj.LeaderWidth;
};
CRunTab.prototype.PrepareRecalculateObject = function()
{
Expand Down
Loading
Loading