Commit ca0215b3 authored by Anna.Pavlova's avatar Anna.Pavlova Committed by Alexander.Trofimov

1. Ускорила перерасчет формул при добавление букв

2. Поправила баг : неправильно брались ctrPrp для дроби, когда из не inline формулы делали inline, а потом снова inline

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@58651 954022d7-b5bf-4e40-9824-e11837661b57
parent cb944de1
"use strict";
/*var Math_Draw_Time = false;
var Math_Date = 0;
var Math_NeedResize = true;
var Math_Date_Draw = 0;*/
/**
* Created by Ilja.Kirillov on 18.03.14.
*/
......@@ -40,6 +45,7 @@ function ParaMath()
//this.CurrentContent = this.RootComposition;
//this.SelectContent = this.RootComposition;
this.NeedResize = true;
this.bSelectionUse = false;
......@@ -155,6 +161,8 @@ ParaMath.prototype.Get_CompiledTextPr = function(Copy)
ParaMath.prototype.Add = function(Item)
{
this.NeedResize = true;
var Type = Item.Type;
var oContent = this.GetSelectContent();
var oStartContent = oContent.Content.content[oContent.Start];
......@@ -226,6 +234,7 @@ ParaMath.prototype.Add = function(Item)
ParaMath.prototype.Remove = function(Direction, bOnAddText)
{
this.NeedResize = true;
var oSelectedContent = this.GetSelectContent();
var nStartPos = oSelectedContent.Start;
......@@ -534,29 +543,37 @@ ParaMath.prototype.Recalculate_Range = function(PRS, ParaPr, Depth)
var ParaLine = PRS.Line;
var ParaRange = PRS.Range;
var TextPr = new CTextPr();
TextPr.Init_Default();
var RPI = new CRPI();
RPI.bInline = this.MathPara === false;
RPI.bChangeInline = this.MathPara != this.OldMathPara;
RPI.NeedResize = this.NeedResize;
var ArgSize = new CMathArgSize();
if(PRS.NewRange == false)
this.Root.Recalculate_Reset(PRS.Range, PRS.Line);
this.Root.Resize(g_oTextMeasurer, null, this, RPI/*recalculate properties info*/, ArgSize, TextPr);
if(RPI.NeedResize)
{
this.Root.Resize(g_oTextMeasurer, null, this, RPI/*recalculate properties info*/, ArgSize);
// когда формула будеат разбиваться на строки, Position придется перерасчитывать
var pos = new CMathPosition();
pos.x = 0;
pos.y = 0;
//this.Root.Resize(null, this, g_oTextMeasurer, RPI/*recalculate properties info*/, TextPr);
this.OldMathPara = this.MathPara;
this.Root.setPosition(pos);
}
else
this.Root.Resize_2(g_oTextMeasurer, null, this, RPI/*recalculate properties info*/, ArgSize);
var pos = new CMathPosition();
pos.x = 0;
pos.y = 0;
this.NeedResize = false;
this.OldMathPara = this.MathPara;
//this.Root.Resize(null, this, g_oTextMeasurer, RPI/*recalculate properties info*/, TextPr);
this.Root.setPosition(pos);
this.Width = this.Root.size.width;
this.Height = this.Root.size.height;
......@@ -662,6 +679,7 @@ ParaMath.prototype.Recalculate_Range = function(PRS, ParaPr, Depth)
}
this.protected_FillRange(CurLine, CurRange, RangeStartPos, RangeEndPos);
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
};
......@@ -908,6 +926,11 @@ ParaMath.prototype.Shift_Range = function(Dx, Dy, _CurLine, _CurRange)
// Функция для работы с формулой
// в тч с дефолтными текстовыми настройками и argSize
//-----------------------------------------------------------------------------------
ParaMath.prototype.SetInline = function(value)
{
this.bInline = value;
this.NeedResize = true;
};
ParaMath.prototype.MathToImageConverter= function()
{
window.IsShapeToImageConverter = true;
......@@ -975,23 +998,23 @@ ParaMath.prototype.ApplyArgSize = function(oWPrp, argSize)
oWPrp.Merge(tPrp);
};
ParaMath.prototype.ApplyArgSize_2 = function(oWPrp, argSize)
{
if(argSize == -1)
{
//FSize = 0.0009*FSize*FSize + 0.68*FSize + 0.26;
oWPrp.FontSize = 0.76*oWPrp.FontSize;
oWPrp.FontSizeCS = 0.76*oWPrp.FontSizeCS;
}
else if(argSize == -2)
{
//FSize = -0.0004*FSize*FSize + 0.66*FSize + 0.87;
oWPrp.FontSize = 0.76*0.855*oWPrp.FontSize;
oWPrp.FontSizeCS = 0.76*0.855*oWPrp.FontSizeCS;
}
/*ParaMath.prototype.GetDefaultTxtPrp= function()
{
var txtPrp = new CTextPr();
var defaultTxtPr =
{
FontFamily: {Name : "Cambria Math", Index : -1 },
FontSize: 11,
Italic: true,
Bold: false
};
txtPrp.Set_FromObject(defaultTxtPr);
return txtPrp;
};*/
};
ParaMath.prototype.GetFirstRPrp = function()
{
......@@ -1596,4 +1619,5 @@ ParaMath.prototype.Get_ContentSelection = function()
return null;
return {X : oContent.pos.x + this.X, Y : oContent.pos.y + this.Y, W : oContent.size.width, H : oContent.size.height};
};
\ No newline at end of file
};
......@@ -40,11 +40,12 @@ function ParaRun(Paragraph, bMathRun)
{
this.Type = para_Math_Run;
this.Parent = null;
this.ArgSize = 0;
this.bEqqArray = false;
this.size = new CMathSize();
this.MathPrp = new CMPrp();
this.Parent = null;
this.ArgSize = 0;
this.bEqqArray = false;
//this.UpdateMathPr = true;
this.size = new CMathSize();
this.MathPrp = new CMPrp();
}
this.StartState = null;
......@@ -1213,11 +1214,15 @@ ParaRun.prototype.Create_FontMap = function(Map, ArgSize)
if ( undefined !== this.Paragraph && null !== this.Paragraph )
{
var TextPr;
var FontSize, FontSizeCS;
if(this.Type === para_Math_Run)
{
TextPr = this.Get_CompiledPr(true);
TextPr = this.Get_CompiledPr(false);
FontSize = TextPr.FontSize;
FontSizeCS = TextPr.FontSizeCS;
if(this.Parent !== null)
this.Parent.ParaMath.ApplyArgSize(TextPr, ArgSize.value);
this.Parent.ParaMath.ApplyArgSize_2(TextPr, ArgSize.value);
}
else
TextPr = this.Get_CompiledPr(false);
......@@ -1231,6 +1236,12 @@ ParaRun.prototype.Create_FontMap = function(Map, ArgSize)
if ( para_Drawing === Item.Type )
Item.documentCreateFontMap( Map );
}
if(this.Type === para_Math_Run)
{
TextPr.FontSize = FontSize;
TextPr.FontSizeCS = FontSizeCS;
}
}
};
......@@ -1465,67 +1476,6 @@ ParaRun.prototype.Recalculate_MeasureContent = function()
this.RecalcInfo.Recalc = true;
this.RecalcInfo.Measure = false;
};
ParaRun.prototype.Recalculate_MeasureContent_2 = function(WidthPoints)
{
if ( false === this.RecalcInfo.Measure )
return;
var Pr = this.Get_CompiledPr(true);
this.Parent.ParaMath.ApplyArgSize(Pr, this.ArgSize);
if(!this.IsNormalText()) // выставляем false, чтобы не применился наклон к спец символам
{
Pr.Italic = false;
Pr.Bold = false;
var defaultTxtPrp = this.Parent.ParaMath.Get_Default_TPrp();
Pr.FontFamily = defaultTxtPrp.FontFamily;
Pr.RFonts.Set_All(defaultTxtPrp.FontFamily.Name, defaultTxtPrp.FontFamily.Index);
}
this.size.SetZero();
var widthCurr = 0,
ascent = 0, descent = 0;
var Theme = this.Paragraph.Get_Theme();
g_oTextMeasurer.SetTextPr(Pr, Theme);
g_oTextMeasurer.SetFontSlot(fontslot_ASCII);
var ContentLength = this.Content.length;
for ( var Pos = 0; Pos < ContentLength; Pos++ )
{
var Item = this.Content[Pos];
var ItemType = Item.Type;
Item.Parent = this;
Item.Resize(g_oTextMeasurer);
var oSize = Item.size;
widthCurr = oSize.width;
this.size.width += widthCurr;
var oDescent = oSize.height - oSize.ascent;
ascent = ascent > oSize.ascent ? ascent : oSize.ascent;
descent = descent < oDescent ? oDescent : descent;
if(this.bEqqArray)
{
if(ItemType !== para_Math_Ampersand)
WidthPoints.UpdatePoint(widthCurr);
else
WidthPoints.AddNewAlignRange();
}
}
this.RecalcInfo.Recalc = true;
this.RecalcInfo.Measure = false;
}
ParaRun.prototype.Recalculate_Measure2 = function(Metrics)
{
var TAscent = Metrics.Ascent;
......@@ -1571,10 +1521,9 @@ ParaRun.prototype.Recalculate_Range = function(PRS, ParaPr, Depth)
}
// Сначала измеряем элементы (можно вызывать каждый раз, внутри разруливается, чтобы измерялось 1 раз)
if(this.Type !== para_Math_Run)
this.Recalculate_MeasureContent();
else
this.Recalculate_MeasureContent_2(PRS.WidthPoints);
this.Recalculate_MeasureContent();
var CurLine = PRS.Line - this.StartLine;
var CurRange = ( 0 === CurLine ? PRS.Range - this.StartRange : PRS.Range );
......@@ -7803,8 +7752,13 @@ ParaRun.prototype.Math_Draw = function(x, y, pGraphics)
var X = x;
var Y = y + this.size.ascent;
var oWPrp = this.Get_CompiledPr(true);
this.Parent.ParaMath.ApplyArgSize(oWPrp, this.Parent.Compiled_ArgSz.value);
var oWPrp = this.Get_CompiledPr(false);
var Bold = oWPrp.Bold,
Italic = oWPrp.Italic,
FontSize = oWPrp.FontSize,
FontSizeCS = oWPrp.FontSizeCS;
this.Parent.ParaMath.ApplyArgSize_2(oWPrp, this.Parent.Compiled_ArgSz.value);
if(!this.IsNormalText()) // выставляем false, чтобы не применился наклон к спец символам
{
......@@ -7827,6 +7781,11 @@ ParaRun.prototype.Math_Draw = function(x, y, pGraphics)
for(var i=0; i < this.Content.length;i++)
this.Content[i].draw(X, Y, pGraphics);
oWPrp.Bold = Bold;
oWPrp.Italic = Italic;
oWPrp.FontSize = FontSize;
oWPrp.FontSizeCS = FontSizeCS;
}
ParaRun.prototype.Math_Recalculate = function(oMeasure, Parent, Paragraph, RPI, ArgSize, WidthPoints)
{
......@@ -7840,7 +7799,6 @@ ParaRun.prototype.Math_Recalculate = function(oMeasure, Parent, Paragraph, RPI,
// FontClassification.js
// Get_FontClass
var RangeStartPos = 0;
var RangeEndPos = this.Content.length;
......@@ -7853,67 +7811,88 @@ ParaRun.prototype.Math_Recalculate = function(oMeasure, Parent, Paragraph, RPI,
this.protected_AddRange(0, 0);
this.protected_FillRange(0, 0, RangeStartPos, RangeEndPos);
var oWPrp = this.Get_CompiledPr(true);
this.Parent.ParaMath.ApplyArgSize(oWPrp, ArgSize.value);
if(!this.IsNormalText()) // выставляем false, чтобы не применился наклон к спец символам
if(RPI.NeedResize)
{
oWPrp.Italic = false;
oWPrp.Bold = false;
//RPI.UpdateMathPr = this.UpdateMathPr;
var defaultTxtPrp = this.Parent.ParaMath.Get_Default_TPrp();
var oWPrp = this.Get_CompiledPr(false);
var Bold = oWPrp.Bold;
var Italic = oWPrp.Italic;
var FontSize = oWPrp.FontSize;
var FontSizeCS = oWPrp.FontSizeCS;
this.Parent.ParaMath.ApplyArgSize_2(oWPrp, this.Parent.Compiled_ArgSz.value);
oWPrp.FontFamily = defaultTxtPrp.FontFamily;
oWPrp.RFonts.Set_All(defaultTxtPrp.FontFamily.Name, defaultTxtPrp.FontFamily.Index);
}
g_oTextMeasurer.SetFont(oWPrp);
if(!this.IsNormalText()) // выставляем false, чтобы не применился наклон к спец символам
{
oWPrp.Italic = false;
oWPrp.Bold = false;
this.bEqqArray = RPI.bEqqArray;
var defaultTxtPrp = this.Parent.ParaMath.Get_Default_TPrp();
this.size.SetZero();
oWPrp.FontFamily = defaultTxtPrp.FontFamily;
oWPrp.RFonts.Set_All(defaultTxtPrp.FontFamily.Name, defaultTxtPrp.FontFamily.Index);
}
var widthCurr = 0,
ascent = 0, descent = 0;
g_oTextMeasurer.SetFont(oWPrp);
var Lng = this.Content.length;
this.bEqqArray = RPI.bEqqArray;
for (var i = 0 ; i < Lng; i++)
{
this.Content[i].Resize(oMeasure, this, RPI);
var oSize = this.Content[i].size;
this.size.SetZero();
widthCurr = oSize.width;
this.size.width += widthCurr;
var widthCurr = 0,
ascent = 0, descent = 0;
var oDescent = oSize.height - oSize.ascent;
var Lng = this.Content.length;
ascent = ascent > oSize.ascent ? ascent : oSize.ascent;
descent = descent < oDescent ? oDescent : descent;
if(RPI.bEqqArray)
for (var i = 0 ; i < Lng; i++)
{
if(this.Content[i].Type !== para_Math_Ampersand)
WidthPoints.UpdatePoint(widthCurr);
else
WidthPoints.AddNewAlignRange();
this.Content[i].Resize(oMeasure, this, RPI);
var oSize = this.Content[i].size;
widthCurr = oSize.width;
this.size.width += widthCurr;
var oDescent = oSize.height - oSize.ascent;
ascent = ascent > oSize.ascent ? ascent : oSize.ascent;
descent = descent < oDescent ? oDescent : descent;
if(RPI.bEqqArray)
{
if(this.Content[i].Type !== para_Math_Ampersand)
WidthPoints.UpdatePoint(widthCurr);
else
WidthPoints.AddNewAlignRange();
}
}
}
this.size.ascent = ascent;
this.size.height = ascent + descent;
this.size.ascent = ascent;
this.size.height = ascent + descent;
oWPrp.Bold = Bold;
oWPrp.Italic = Italic;
oWPrp.FontSize = FontSize;
oWPrp.FontSizeCS = FontSizeCS;
//this.UpdateMathPr = false;
}
}
ParaRun.prototype.Math_Update_Cursor = function(X, Y, CurPage, UpdateTarget)
{
// TODO
// поставить заглушку на плейсхолдер, когда при перемещении всегда будет отрисовываться селект на плейсхолдере
var runPrp = this.Get_CompiledPr(true);
var runPrp = this.Get_CompiledPr(false);
//this.Parent.ParaMath.ApplyArgSize(runPrp, this.Parent.argSize);
var sizeCursor = runPrp.FontSize*g_dKoef_pt_to_mm;
......@@ -7934,10 +7913,6 @@ ParaRun.prototype.Math_Update_Cursor = function(X, Y, CurPage, UpdateTarget)
return {X: X, Y: Y, Height: sizeCursor};
}
ParaRun.prototype.Set_MathPrp = function(props)
{
this.MathPrp.setMathProps(props);
}
ParaRun.prototype.Math_Apply_Style = function(Value)
{
if(Value !== this.MathPrp.sty)
......@@ -7966,7 +7941,8 @@ ParaRun.prototype.Math_SetGaps = function(GapsInfo)
{
this.Parent = GapsInfo.Parent;
this.Paragraph = GapsInfo.ParaMath.Paragraph;
var oWPrp = this.Get_CompiledPr(true);
var oWPrp = this.Get_CompiledPr(false);
for (var Pos = 0 ; Pos < this.Content.length; Pos++ )
{
......@@ -7999,6 +7975,8 @@ ParaRun.prototype.Set_MathPr = function(MPrp)
History.Add( this, { Type : historyitem_ParaRun_MathPrp, New : MPrp, Old : OldValue } );
this.Recalc_CompiledPr(true);
//this.UpdateMathPr = true;
}
ParaRun.prototype.IsAccent = function()
{
......
......@@ -2,7 +2,6 @@
function CMathBase(bInside)
{
//this.typeObj = MATH_COMP;
this.Type = para_Math_Composition;
this.pos = new CMathPosition();
......@@ -37,7 +36,6 @@ function CMathBase(bInside)
};
this.bSelectionUse = false;
this.bInsideUpperSelect = false;
this.nRow = 0;
this.nCol = 0;
......@@ -384,6 +382,13 @@ CMathBase.prototype =
this.recalculateSize(oMeasure, RPI);
},
Resize_2: function(oMeasure, Parent, ParaMath, RPI, ArgSize)
{
for(var i=0; i < this.nRow; i++)
for(var j = 0; j < this.nCol; j++)
if(!this.elements[i][j].IsJustDraw())
this.elements[i][j].Resize_2(oMeasure, this, ParaMath, RPI, ArgSize);
},
Set_CompiledCtrPrp: function(ParaMath)
{
if(this.RecalcInfo.bCtrPrp == true)
......
......@@ -456,17 +456,6 @@ CBox.prototype.fillContent = function()
this.setDimension(1, 1);
this.setContent();
}
CBox.prototype.Resize = function(oMeasure, Parent, ParaMath, RPI, ArgSize)
{
//this.Set_CompiledCtrPrp(ParaMath);
var ArgSizeBox = ArgSize.Copy();
/*if(this.Pr.opEmu)
ArgSizeBox.decrease();*/
CBox.superclass.Resize.call(this, oMeasure, Parent, ParaMath, RPI, ArgSizeBox);
}
CBox.prototype.setProperties = function(props)
{
if(props.opEmu === true || props.opEmu === false)
......
......@@ -225,6 +225,10 @@ CFraction.prototype.Resize = function(oMeasure, Parent, ParaMath, RPI, ArgSize)
{
this.ArgSize.SetValue(-1); // для CtrPrp
}
else
{
this.ArgSize.SetValue(0);
}
if(this.Pr.type == NO_BAR_FRACTION)
{
......
......@@ -37,6 +37,8 @@ var historyitem_Math_CtrPrpFSize = 3; // CtrPrp
function CRPI()
{
//this.UpdateMathPr = true;
this.NeedResize = true;
this.bInsideFraction = false;
this.bInline = false;
this.bChangeInline = false;
......@@ -4030,6 +4032,17 @@ CMathContent.prototype =
this.size.height = SizeDescent < oDescent ? oDescent + this.size.ascent : SizeDescent + this.size.ascent;
}
},
Resize_2: function(oMeasure, Parent, ParaMath, RPI, ArgSize) // особый случай: вызываем, когда пересчет всей формулы не нужен, а нужно выставить только Lines (Реализована, чтобы не править Resize у каждого элемента)
{
var lng = this.content.length;
for(var i = 0; i < lng; i++)
{
if(this.content[i].Type == para_Math_Composition)
this.content[i].Resize_2(oMeasure, this, ParaMath, RPI, ArgSize);
else
this.content[i].Math_Recalculate(oMeasure, this, ParaMath.Paragraph, RPI, ArgSize, null);
}
},
M_Resize: function(oMeasure, Parent, ParaMath, RPI, ArgSize) // если делать один цикл for для Resize, то надо избавиться от WidthToElement,
// т.к. корректно рассчитывать не получается, либо выставлять WidthToElement для пустыx Run (которые идут после мат объекта) на recalculateSize_2 мат объекта
{
......@@ -5062,7 +5075,6 @@ CMathContent.prototype =
var len = this.content.length - 1;
this.CurPos = len;
this.content[len].Cursor_MoveToEndPos(SelectFromEnd);
}
},
......
......@@ -38,15 +38,30 @@ CMathSize.prototype.SetZero = function()
this.ascent = 0;
}
function CMathRecalcTextInfo()
{
this.StyleCode = null;
this.bAccentIJ = false;
}
function CMathText(bJDraw)
{
// для Para_Run
this.Type = para_Math_Text;
this.bJDraw = bJDraw;
this.size = new CMathSize();
this.value = null;
this.RecalcInfo =
{
//NewLetter: true,
StyleCode: null,
bAccentIJ: false
};
this.Parent = null;
this.size = new CMathSize();
this.pos = new CMathPosition();
this.rasterOffsetX = 0;
......@@ -547,10 +562,19 @@ CMathText.prototype =
var letter = this.getCode();
var bAccentIJ = this.bJDraw ? false : this.Parent.IsAccent();
/*if(this.bJDraw)
letter = this.code;
else if(RPI.UpdateMathPr || Math_NeedResize == false || this.RecalcInfo.NewLetter == true)
letter = this.getCode();
else
letter = this.RecalcInfo.StyleCode;*/
var bAccentIJ = this.bJDraw ? false : this.Parent.IsAccent();
bAccentIJ = bAccentIJ && (this.value == 0x69 || this.value == 0x6A);
this.RecalcInfo.StyleCode = letter;
this.RecalcInfo.bAccentIJ = bAccentIJ;
if(bAccentIJ)
oMeasure.SetStringGid(true);
......@@ -576,17 +600,14 @@ CMathText.prototype =
if(this.bJDraw)
width = metricsTxt.WidthG;
//width = metricsTxt.WidthG + this.GapLeft + this.GapRight;
else
width = metricsTxt.Width;
//width = metricsTxt.Width + this.GapLeft + this.GapRight;
this.size.width = this.GapLeft + this.GapRight + width;
this.size.height = height;
this.size.ascent = ascent;
//this.size = {width: width, widthG: width, height: height, ascent: ascent};
//this.RecalcInfo.NewLetter = false;
},
Get_WidthVisible: function()
{
......@@ -622,12 +643,12 @@ CMathText.prototype =
pGraphics.transform(sx, shy, shx, sy, 0, 0);*/
var bAccent = this.bJDraw ? false : this.Parent.IsAccent();
if(bAccent && (this.value == 0x69 || this.value == 0x6A))
pGraphics.tg(this.getCode(), X, Y);
if(this.RecalcInfo.bAccentIJ)
pGraphics.tg(this.RecalcInfo.StyleCode, X, Y);
else
pGraphics.FillTextCode(X, Y, this.getCode()); //на отрисовку символа отправляем положение baseLine
pGraphics.FillTextCode(X, Y, this.RecalcInfo.StyleCode); //на отрисовку символа отправляем положение baseLine
},
setPosition: function(pos)
......
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