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

Yормальный расчет для выравнивания в EqqArray с несколькими Run в контенте и...

Yормальный расчет для выравнивания в EqqArray с несколькими Run в контенте и мат объектами, без случая с Last элементом

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@57987 954022d7-b5bf-4e40-9824-e11837661b57
parent f202badb
......@@ -1235,7 +1235,7 @@ ParaMath.prototype =
// this.absPos.x ~> this.X
// this.absPos.y ~> this.Y
if(this.NotDraw == false)
//if(this.NotDraw == false)
this.Root.draw( PDSE.X, PDSE.Y - this.Ascent, PDSE.Graphics);
PDSE.X += this.Width;
......
......@@ -53,7 +53,7 @@ function ParaRun(Paragraph, bMathRun)
this.MathPrp = new CMPrp();
this.Parent = null;
this.bEqqArray = false;
this.WidthsPoints = [];
//this.WidthsPoints = [];
this.size = new CMathSize();
}
this.StartState = null;
......@@ -7563,44 +7563,106 @@ function CRunCollaborativeRange(PosS, PosE, Color)
this.PosE = PosE;
this.Color = Color;
}
ParaRun.prototype.Math_SetPosition = function(pos, PosInfo)
ParaRun.prototype.old_Math_SetPosition = function(pos, PosInfo, CurrWPoints)
{
var NewPos = new CMathPosition();
NewPos.x = pos.x;
NewPos.y = pos.y - this.size.ascent;
if(this.bEqqArray)
{
var alignEven = 0;
var align = 0;
// нечетным точкам соответствуют четные индексы в массиве
var Len = CurrWPoints.Widths.length,
Amp = CurrWPoints.Amp,
CurrPoint = CurrWPoints.CurrPoint;
var Pos = 0,
lng = this.Content.length,
Amp = 1;
Point;
var W = 0;
var WPointsLng = this.WidthsPoints.length;
var widthCurrPoint = 0;
var GWidth, GPoint;
if(WPointsLng > 0) // есть точки выравнивания
if(Len > 0) // есть точки выравнивания
{
for(var j = 0; j < WPointsLng; j++)
while(Pos < this.Content.length)
{
Point = CurrWPoints.Widths[CurrPoint];
GWidth = PosInfo.Widths[CurrPoint];
GPoint = PosInfo.Points[CurrPoint];
if(CurrPoint == Len - 1 && Point.odd == -1) // то есть последняя точка четная, выравнивание по центру
{
align = (GWidth - Point.even)/2;
alignEven = 0;
}
else
{
alignEven = (GWidth - GPoint.even - GPoint.odd)/2;
align = GPoint.even - Point.even;
}
if(Amp == 0 || (Amp == 1 && CurrPoint === 0))
NewPos.x += align + alignEven;
while(Pos < this.Content.length && Amp < 3)
{
if(this.Content[Pos].Type == para_Math_Ampersand)
{
Amp++;
if(Amp < 3)
{
this.Content[Pos].setPosition(NewPos);
Pos++;
}
}
else
{
this.Content[Pos].setPosition(NewPos);
NewPos.x += this.Content[Pos].size.width;
//widthCurrPoint += this.Content[Pos].size.width;
//W += this.Content[Pos].size.width;
Pos++;
}
}
if(Amp == 3)
{
CurrPoint++;
pos.x += GWidth;
NewPos.x = pos.x;
}
else
pos.x = NewPos.x;
Amp = 0;
}
CurrWPoints.CurrPoint = CurrPoint;
CurrWPoints.Amp = Amp;
/*for(var j = 0; j < WPointsLng; j++)
{
widthCurrPoint = 0;
if(j == WPointsLng - 1 && this.WidthsPoints[j].odd == -1) // то есть последняя точка четная, выравнивание по центру
if(j == WPointsLng - 1 && CurrWPoints[j].odd == -1) // то есть последняя точка четная, выравнивание по центру
{
align = (PosInfo.Widths[j] - this.WidthsPoints[j].even)/2;
align = (PosInfo.Widths[CurrPoint] - CurrWPoints[j].even)/2;
alignEven = 0;
}
else
{
alignEven = (PosInfo.Widths[j] - PosInfo.Points[j].even - PosInfo.Points[j].odd)/2;
align = PosInfo.Points[j].even - this.WidthsPoints[j].even;
alignEven = (PosInfo.Widths[CurrPoint] - PosInfo.Points[CurrPoint].even - PosInfo.Points[CurrPoint].odd)/2;
align = PosInfo.Points[CurrPoint].even - CurrWPoints[j].even;
}
NewPos.x += align + alignEven;
......@@ -7626,14 +7688,17 @@ ParaRun.prototype.Math_SetPosition = function(pos, PosInfo)
}
}
NewPos.x += PosInfo.Widths[j] - widthCurrPoint - align - alignEven; // выравнивание справа
NewPos.x += PosInfo.Widths[CurrPoint] - widthCurrPoint - align - alignEven; // выравнивание справа
Amp = 0;
}
CurrPoint++;
}*/
}
else // точки выравнивания отсутсвуют
{
align = (PosInfo.Widths[0] - this.size.width)/2;
align = (PosInfo.Widths[CurrPoint] - this.size.width)/2;
NewPos.x += align;
for(var i = 0; i < this.Content.length; i++)
......@@ -7641,35 +7706,204 @@ ParaRun.prototype.Math_SetPosition = function(pos, PosInfo)
this.Content[i].setPosition(NewPos);
NewPos.x += this.Content[i].size.width;
}
pos.x += PosInfo.Widths[CurrPoint];
}
}
else
{
for(var i = 0; i < this.Content.length; i++)
{
this.Content[i].setPosition(NewPos);
NewPos.x += this.Content[i].size.width;
}
pos.x += this.size.width;
}
}
ParaRun.prototype.Math_SetPosition = function(PosInfo)
{
var NewPos = new CMathPosition();
var x = PosInfo.x,
y = PosInfo.y - this.size.ascent;
/*if(Pos < lng)
if(this.bEqqArray)
{
for(var Pos = 0; Pos < this.Content.length; Pos++)
{
var Index = this.WidthsPoints.length/2;
align = (PosInfo.Widths[Index] - (this.size.width - W))/2;
NewPos.x += align;
var CurrElem = this.Content[Pos];
if(this.Content[Pos].Type == para_Math_Ampersand)
{
PosInfo.UpdatePoint();
PosInfo.ApplyAlign();
while(Pos < lng)
CurrElem.setPosition(PosInfo.x, y);
}
else
{
CurrElem.setPosition(PosInfo.x, y);
}
PosInfo.UpdateX(CurrElem.size.width);
}
/*var alignEven = 0;
var align = 0;
// нечетным точкам соответствуют четные индексы в массиве
var Len = CurrWPoints.Widths.length,
Amp = CurrWPoints.Amp,
CurrPoint = CurrWPoints.CurrPoint;
var Pos = 0,
Point;
var GWidth, GPoint;
if(Len > 0) // есть точки выравнивания
{
while(Pos < this.Content.length)
{
Point = CurrWPoints.Widths[CurrPoint];
GWidth = PosInfo.Widths[CurrPoint];
GPoint = PosInfo.Points[CurrPoint];
if(CurrPoint == Len - 1 && Point.odd == -1) // то есть последняя точка четная, выравнивание по центру
{
this.Content[Pos].setPosition(NewPos);
NewPos.x += this.Content[Pos].size.width;
Pos++;
align = (GWidth - Point.even)/2;
alignEven = 0;
}
else
{
alignEven = (GWidth - GPoint.even - GPoint.odd)/2;
align = GPoint.even - Point.even;
}
if(Amp == 0 || (Amp == 1 && CurrPoint === 0))
NewPos.x += align + alignEven;
while(Pos < this.Content.length && Amp < 3)
{
if(this.Content[Pos].Type == para_Math_Ampersand)
{
Amp++;
if(Amp < 3)
{
this.Content[Pos].setPosition(NewPos);
Pos++;
}
}
else
{
this.Content[Pos].setPosition(NewPos);
NewPos.x += this.Content[Pos].size.width;
//widthCurrPoint += this.Content[Pos].size.width;
//W += this.Content[Pos].size.width;
Pos++;
}
}
if(Amp == 3)
{
CurrPoint++;
pos.x += GWidth;
NewPos.x = pos.x;
}
else
pos.x = NewPos.x;
Amp = 0;
}
CurrWPoints.CurrPoint = CurrPoint;
CurrWPoints.Amp = Amp;
*//*for(var j = 0; j < WPointsLng; j++)
{
widthCurrPoint = 0;
if(j == WPointsLng - 1 && CurrWPoints[j].odd == -1) // то есть последняя точка четная, выравнивание по центру
{
align = (PosInfo.Widths[CurrPoint] - CurrWPoints[j].even)/2;
alignEven = 0;
}
else
{
alignEven = (PosInfo.Widths[CurrPoint] - PosInfo.Points[CurrPoint].even - PosInfo.Points[CurrPoint].odd)/2;
align = PosInfo.Points[CurrPoint].even - CurrWPoints[j].even;
}
NewPos.x += align + alignEven;
while(Pos < lng && Amp < 3)
{
if(this.Content[Pos].Type == para_Math_Ampersand)
{
Amp++;
if(Amp < 3)
{
this.Content[Pos].setPosition(NewPos);
Pos++;
}
}
else
{
this.Content[Pos].setPosition(NewPos);
NewPos.x += this.Content[Pos].size.width;
widthCurrPoint += this.Content[Pos].size.width;
W += this.Content[Pos].size.width;
Pos++;
}
}
NewPos.x += PosInfo.Widths[CurrPoint] - widthCurrPoint - align - alignEven; // выравнивание справа
Amp = 0;
CurrPoint++;
}*//*
}
else // точки выравнивания отсутсвуют
{
align = (PosInfo.Widths[CurrPoint] - this.size.width)/2;
NewPos.x += align;
for(var i = 0; i < this.Content.length; i++)
{
this.Content[i].setPosition(NewPos);
NewPos.x += this.Content[i].size.width;
}
pos.x += PosInfo.Widths[CurrPoint];
}*/
//
}
else
{
for(var i = 0; i < this.Content.length; i++)
{
this.Content[i].setPosition(NewPos);
NewPos.x += this.Content[i].size.width;
this.Content[i].setPosition(PosInfo.x, y);
PosInfo.x += this.Content[i].size.width;
}
//pos.x += this.size.width;
}
}
ParaRun.prototype.Math_Draw = function(x, y, pGraphics)
{
......@@ -7701,7 +7935,7 @@ ParaRun.prototype.Math_Draw = function(x, y, pGraphics)
this.Content[i].draw(X, Y, pGraphics);
}
ParaRun.prototype.Math_Recalculate = function(oMeasure, Parent, Paragraph, RPI, ArgSize)
ParaRun.prototype.Math_Recalculate = function(oMeasure, Parent, Paragraph, RPI, ArgSize, WidthPoints)
{
// пересчет элементов контента в Run
// Recalculate_MeasureContent
......@@ -7725,7 +7959,6 @@ ParaRun.prototype.Math_Recalculate = function(oMeasure, Parent, Paragraph, RPI,
this.Lines[0].Add_Range(0, RangeStartPos, RangeEndPos);
var oWPrp = this.Get_CompiledPr(true);
this.Parent.ParaMath.ApplyArgSize(oWPrp, ArgSize.value);
......@@ -7743,16 +7976,8 @@ ParaRun.prototype.Math_Recalculate = function(oMeasure, Parent, Paragraph, RPI,
g_oTextMeasurer.SetFont(oWPrp);
this.WidthsPoints.length = 0;
this.bEqqArray = RPI.bEqqArray;
var Widths, PosW = 0;
if(RPI.bEqqArray)
{
Widths = RPI.AmperWPoints.GetWidths();
Widths[0] = 0;
}
this.size.SetZero();
......@@ -7760,7 +7985,7 @@ ParaRun.prototype.Math_Recalculate = function(oMeasure, Parent, Paragraph, RPI,
ascent = 0, descent = 0;
var Lng = this.Content.length;
var len, NewPoint;
for (var i = 0 ; i < Lng; i++)
{
......@@ -7776,77 +8001,15 @@ ParaRun.prototype.Math_Recalculate = function(oMeasure, Parent, Paragraph, RPI,
ascent = ascent > oSize.ascent ? ascent : oSize.ascent;
descent = descent < oDescent ? oDescent : descent;
/*if(this.Content[i].Type == para_Math_Ampersand && RPI.bEqqArray)
{
if(PosW == lng)
{
RPI.Widths[PosW] = W;
RPI.SingleAmpEnd = true;
}
else
{
RPI.Widths[PosW] = RPI.Widths[PosW] > W ? RPI.Widths[PosW] : W;
if(PosW == lng -1)
RPI.SingleAmpEnd = false;
}
PosW++;
W = 0;
}
else
W += width;*/
if(RPI.bEqqArray)
{
if(this.Content[i].Type == para_Math_Ampersand)
{
if(PosW % 2 == 0)
{
NewPoint = new CMathPoint();
NewPoint.even = Widths[PosW];
this.WidthsPoints.push(NewPoint);
}
else
{
len = this.WidthsPoints.length;
this.WidthsPoints[len-1].odd = Widths[PosW];
}
PosW++;
Widths[PosW] = 0;
}
if(this.Content[i].Type !== para_Math_Ampersand)
WidthPoints.UpdatePoint(widthCurr);
else
Widths[PosW] += widthCurr;
WidthPoints.AddNewAlignRange();
}
}
len = this.WidthsPoints.length;
if(RPI.bEqqArray && len > 0)
{
if(PosW%2 == 0)
{
NewPoint = new CMathPoint();
NewPoint.even = Widths[PosW];
NewPoint.odd = -1;
this.WidthsPoints.push(NewPoint);
}
else
{
this.WidthsPoints[len-1].odd = Widths[PosW];
}
}
this.size.ascent = ascent;
this.size.height = ascent + descent;
}
......
......@@ -42,8 +42,7 @@ function CRPI()
this.bChangeInline = false;
this.bNaryInline = false; /*для CDegreeSupSub внутри N-арного оператора, этот флаг необходим, чтобы итераторы максимально близко друг к другу расположить*/
this.bEqqArray = false; /*для амперсанда*/
this.AmperWPoints = null;
this.bManyRuns = false;
}
CRPI.prototype.Copy = function()
{
......@@ -53,16 +52,165 @@ CRPI.prototype.Copy = function()
RPI.bInsideFraction = this.bInsideFraction;
RPI.bChangeInline = this.bChangeInline;
RPI.bNaryInline = this.bNaryInline;
RPI.bManyRuns = false;
RPI.bEqqArray = this.bEqqArray;
return RPI;
}
function CMathPosInfo()
/*function CMathPosInfo()
{
this.CurrPoint = 0;
this.Widths = [];
this.Points = [];
}*/
function CMathPosInfo()
{
this.x = 0;
this.y = 0;
this.bEven = true;
this.CurrPoint = 0;
this.GWidths = null;
this.GPoints = null;
this.ContentPoints = null;
this.GMaxDimWidths = null;
}
CMathPosInfo.prototype.UpdateX = function(value)
{
this.x += value;
}
CMathPosInfo.prototype.UpdatePoint = function()
{
if(this.bEven)
this.bEven = false;
else
{
this.CurrPoint++;
this.bEven = true;
}
}
CMathPosInfo.prototype.old_old_ApplyAlign = function()
{
var align = 0;
if(this.bEven)
{
var alignEven, alignGeneral;
var Len = this.ContentPoints.length,
Point = this.ContentPoints[this.CurrPoint];
var GWidth = this.GWidths[this.CurrPoint],
GPoint = this.GPoints[this.CurrPoint];
if(this.CurrPoint == Len - 1 && Point.odd == -1) // то есть последняя точка четная, выравнивание по центру
{
alignGeneral = (GWidth - Point.even)/2;
alignEven = 0;
}
else
{
alignEven = (GWidth - GPoint.even - GPoint.odd)/2;
alignGeneral = GPoint.even - Point.even;
}
align = alignGeneral + alignEven;
}
this.x += align;
}
CMathPosInfo.prototype.old_ApplyAlign = function() // нормальный расчет, без случая с Last элементом
{
var align = 0;
if(this.bEven)
{
var alignEven, alignGeneral, alignOdd;
var Len = this.ContentPoints.length,
Point = this.ContentPoints[this.CurrPoint];
var GWidth = this.GWidths[this.CurrPoint],
GPoint = this.GPoints[this.CurrPoint];
if(this.CurrPoint == Len - 1 && Point.odd == -1) // то есть последняя точка четная, выравнивание по центру
{
alignGeneral = (GWidth - Point.even)/2;
alignEven = 0;
}
else
{
alignGeneral = (GWidth - GPoint.even - GPoint.odd)/2;
alignEven = GPoint.even - Point.even;
}
if(this.CurrPoint > 0)
{
var PrevGenPoint = this.GPoints[this.CurrPoint-1],
PrevGenWidth = this.GWidths[this.CurrPoint-1],
PrevPoint = this.ContentPoints[this.CurrPoint-1];
var alignPrevGen = (PrevGenWidth - PrevGenPoint.even - PrevGenPoint.odd)/2;
alignOdd = alignPrevGen + PrevGenPoint.odd - PrevPoint.odd;
}
else
alignOdd = 0;
align = alignGeneral + alignEven + alignOdd;
}
this.x += align;
}
CMathPosInfo.prototype.new_ApplyAlign = function()
{
var align = 0;
if(this.bEven)
{
var alignEven, alignGeneral, alignOdd;
var Len = this.ContentPoints.length,
Point = this.ContentPoints[this.CurrPoint];
var GWidth = this.GWidths[this.CurrPoint],
GPoint = this.GPoints[this.CurrPoint];
if(this.CurrPoint == Len - 1 && Point.odd == -1) // то есть последняя точка четная, выравнивание по центру
{
var GMaxDimWidth = this.GMaxDimWidths[this.CurrPoint];
alignGeneral = (GMaxDimWidth - Point.even)/2; // для Last элемента
alignEven = 0;
}
else
{
alignGeneral = (GWidth - GPoint.even - GPoint.odd)/2; // для случая, когда у Last элемента максимальная ширина для данного отрезка выравнивания
//alignGeneral = (GWidth - Point.even - Point.odd)/2;
alignEven = GPoint.even - Point.even;
}
if(this.CurrPoint > 0)
{
var PrevGenPoint = this.GPoints[this.CurrPoint-1],
PrevGenWidth = this.GWidths[this.CurrPoint-1],
PrevPoint = this.ContentPoints[this.CurrPoint-1];
var alignPrevGen = (PrevGenWidth - PrevPoint.even - PrevPoint.odd)/2;
alignOdd = alignPrevGen + PrevGenPoint.odd - PrevPoint.odd;
}
else
alignOdd = 0;
align = alignGeneral + alignEven + alignOdd;
}
this.x += align;
}
function CMathPosition()
......@@ -74,17 +222,96 @@ function CMathPosition()
function AmperWidths()
{
this.CurrRow = -1;
this.Widths = [];
/*this.Amp = 0;
this.CurrPoint = -1;*/
this.bEven = true; // является ли текущая точка нечетной
this.Widths = [];
}
AmperWidths.prototype.GetWidths = function()
/*AmperWidths.prototype.UpdatePoints = function(value)
{
return this.Widths[this.CurrRow];
if(this.bEven)
{
this.CurrPoint++;
var NewPoint = new CMathPoint();
NewPoint.even = value;
this.Widths.push(NewPoint);
this.bEven = false;
}
else
{
var len = this.Widths.length;
this.Widths[len-1].odd = value;
this.bEven = true;
}
}
AmperWidths.prototype.AddWRow = function()
AmperWidths.prototype.AddToCurrentPoint = function(value)
{
var len = this.Widths.length;
if(len == 0)
{
this.UpdatePoints(value);
this.bEven = true;
}
else
{
if(this.bEven) // текущая точка нечетная
{
if(this.Widths[len-1].even != -1)
this.Widths[len-1].even += value;
else
this.Widths[len-1].even = value;
}
else // текущая точка четная
{
if(this.Widths[len-1].odd != -1)
this.Widths[len-1].odd += value;
else
this.Widths[len-1].odd = value;
}
}
}*/
AmperWidths.prototype.UpdatePoint = function(value)
{
this.CurrRow++;
this.Widths[this.CurrRow] = new Array();
var len = this.Widths.length;
if(len == 0)
{
// дефолтное значение bEven true, для случая если первый элемент в контенте будет Ampersand
var NewPoint = new CMathPoint();
NewPoint.even = value;
this.Widths.push(NewPoint);
this.bEven = true;
}
else
{
if(this.bEven)
this.Widths[len-1].even += value;
else
this.Widths[len-1].odd += value;
}
}
AmperWidths.prototype.AddNewAlignRange = function()
{
var len = this.Widths.length;
if(!this.bEven || len == 0)
{
var NewPoint = new CMathPoint();
NewPoint.even = 0;
this.Widths.push(NewPoint);
}
if(this.bEven)
{
len = this.Widths.length;
this.Widths[len-1].odd = 0;
}
this.bEven = !this.bEven;
}
......@@ -747,6 +974,7 @@ function CMathContent()
this.CurPos = 0;
this.WidthToElement = [];
this.WidthPoints = []; /// for EqqArray Runs
this.pos = new CMathPosition(); // относительная позиция
// Properties
......@@ -3885,27 +4113,26 @@ CMathContent.prototype =
this.WidthToElement.length = 0;
this.bEqqArray = RPI.bEqqArray;
var lng = this.content.length;
this.size.SetZero();
var bManyRuns = RPI.bEqqArray == true && this.content.length > 1;
/*var bManyRuns = RPI.bEqqArray == true && this.content.length > 1;
if(bManyRuns)
RPI.bManyRuns = true;
var temp = true;*/
this.WidthPoints = new AmperWidths();
for(var pos = 0; pos < lng; pos++)
{
if(this.content[pos].Type == para_Math_Composition)
{
// обнуляем Gaps, чтобы при расчете ширины они не участвовалиу
/*this.content[pos].GapLeft = 0;
this.content[pos].GapRight = 0;*/
this.content[pos].Set_CompiledCtrPrp(this.ParaMath);
this.content[pos].SetGaps(GapsInfo);
}
else if(this.content[pos].Type == para_Math_Run /*&& !this.content[pos].Is_Empty()*/)
else if(this.content[pos].Type == para_Math_Run)
this.content[pos].Math_SetGaps(GapsInfo);
......@@ -3920,14 +4147,21 @@ CMathContent.prototype =
if(lng > 0)
this.recalculateSize_2(lng-1, oMeasure, Parent, ParaMath, RPI);
},
recalculateSize_2: function(pos, oMeasure, Parent, ParaMath, RPI)
{
if(this.content[pos].Type == para_Math_Composition)
this.content[pos].Resize(oMeasure, this, ParaMath, RPI, this.Compiled_ArgSz);
{
var NewRPI = RPI.Copy();
NewRPI.bEqqArray = false;
this.content[pos].Resize(oMeasure, this, ParaMath, NewRPI, this.Compiled_ArgSz);
if(RPI.bEqqArray)
this.WidthPoints.UpdatePoint(this.content[pos].size.width);
}
else if(this.content[pos].Type == para_Math_Run)
this.content[pos].Math_Recalculate(oMeasure, this, ParaMath.Paragraph, RPI, this.Compiled_ArgSz);
this.content[pos].Math_Recalculate(oMeasure, this, ParaMath.Paragraph, RPI, this.Compiled_ArgSz, this.WidthPoints);
this.WidthToElement[pos] = this.size.width;
......@@ -4066,26 +4300,54 @@ CMathContent.prototype =
{
return false;
},
setPosition: function(pos, PosInfo)
setPosition: function(PosInfo)
{
this.pos.x = pos.x;
this.pos.y = pos.y;
this.pos.x = PosInfo.x;
this.pos.y = PosInfo.y ;
var x = pos.x,
y = pos.y + this.size.ascent; // y по baseline;
/*var x = pos.x,
y = pos.y + this.size.ascent; */
for(var i=0; i < this.content.length; i++)
//this.WidthPoints.CurrPoint = 0;
//this.WidthPoints.Amp = 1;
/*var NewPos = new CMathPosition();
NewPos.x = pos.x;
NewPos.y = pos.y + this.size.ascent; // y по baseline;*/
var NewPosInfo = new CMathPosInfo();
NewPosInfo.x = this.pos.x;
NewPosInfo.y = this.pos.y + this.size.ascent;
if(this.bEqqArray)
{
var NewPos = new CMathPosition();
NewPos.x = x;
NewPos.y = y;
NewPosInfo.GWidths = this.Parent.WidthsPoints;
NewPosInfo.GPoints = this.Parent.Points;
NewPosInfo.ContentPoints = this.WidthPoints.Widths;
NewPosInfo.GMaxDimWidths = this.Parent.MaxDimWidths;
NewPosInfo.ApplyAlign();
}
for(var i=0; i < this.content.length; i++)
{
if(this.content[i].Type == para_Math_Run)
this.content[i].Math_SetPosition(NewPos, PosInfo);
{
this.content[i].Math_SetPosition(NewPosInfo);
}
else
this.content[i].setPosition(NewPos, PosInfo);
{
/*var NewPos = new CMathPosition();
NewPos.x = pos.x;
NewPos.y = pos.y + this.size.ascent; // y по baseline;*/
this.content[i].setPosition(NewPosInfo);
NewPosInfo.UpdateX(this.content[i].size.width);
}
x += this.content[i].size.width;
}
},
///// properties /////
......
......@@ -559,19 +559,19 @@ CMathText.prototype =
pGraphics.FillTextCode(X, Y, this.getCode()); //на отрисовку символа отправляем положение baseLine
},
setPosition: function(pos)
setPosition: function(X, Y)
{
try
{
if (!this.bJDraw) // for text
{
this.pos.x = pos.x + this.GapLeft;
this.pos.y = pos.y;
this.pos.x = X + this.GapLeft;
this.pos.y = Y;
}
else // for symbol only drawing
{
this.pos.x = pos.x - this.rasterOffsetX;
this.pos.y = pos.y - this.rasterOffsetY + this.size.ascent;
this.pos.x = X - this.rasterOffsetX;
this.pos.y = Y - this.rasterOffsetY + this.size.ascent;
}
}
catch(e)
......@@ -751,13 +751,13 @@ CMathAmp.prototype =
};
}
},
setPosition: function(pos)
setPosition: function(X, Y)
{
this.pos.x = pos.x;
this.pos.y = pos.y;
this.pos.x = X;
this.pos.y = Y;
if(this.bEqqArray==false)
this.AmpText.setPosition(pos);
this.AmpText.setPosition(X, Y);
},
draw: function(x, y, pGraphics)
{
......
......@@ -649,8 +649,8 @@ CMathMatrix.prototype.Get_Id = function()
function CMathPoint()
{
this.even = 0;
this.odd = 0;
this.even = -1;
this.odd = -1;
}
////
......@@ -686,7 +686,8 @@ function CEqArray(props)
// for ampersand in Run
this.WidthsPoints = [];
this.Points = [];
this.Points = [];
this.MaxDimWidths = [];
//
//// special for "read" ////
......@@ -710,32 +711,30 @@ CEqArray.prototype.init = function(props)
}
CEqArray.prototype.Resize = function(oMeasure, Parent, ParaMath, RPI, ArgSize)
{
var CurrAmperWPoints = RPI.AmperWPoints,
CurrEqqArray = RPI.bEqqArray;
// на случай, чтобы не затереть массив
//var CurrAmperWPoints = RPI.AmperWPoints,
// CurrEqqArray = RPI.bEqqArray;
RPI.bEqqArray = true;
this.Parent = Parent;
this.ParaMath = ParaMath;
RPI.AmperWPoints = new AmperWidths();
for(var i = 0; i < this.nRow; i++)
{
RPI.AmperWPoints.AddWRow();
this.elements[i][0].Resize(oMeasure, this, ParaMath, RPI, ArgSize);
}
this.recalculateSize(oMeasure, RPI);
RPI.AmperWPoints = CurrAmperWPoints;
RPI.bEqqArray = CurrEqqArray;
RPI.bEqqArray = false;
//RPI.AmperWPoints = CurrAmperWPoints;
//RPI.bEqqArray = CurrEqqArray;
//CEqArray.superclass.Resize.call(this, oMeasure, Parent, ParaMath, RPI, ArgSize);
}
CEqArray.prototype.getMetrics = function(RPI)
CEqArray.prototype._getMetrics = function(RPI)
{
var AscentsMetrics = [];
var DescentsMetrics = [];
......@@ -750,6 +749,8 @@ CEqArray.prototype.getMetrics = function(RPI)
odd, // нечетная точка
last;
var maxDim, maxDimWidth;
var Pos = 0;
this.WidthsPoints.length = 0;
......@@ -763,24 +764,284 @@ CEqArray.prototype.getMetrics = function(RPI)
odd = 0;
last = 0;
maxDim = 0;
maxDimWidth = 0;
for(var i = 0; i < this.nRow; i++)
{
var W = RPI.AmperWPoints.Widths[i],
len = RPI.AmperWPoints.Widths[i].length;
var WidthsRow = this.elements[i][0].WidthPoints.Widths,
len = WidthsRow.length;
if(Pos < len && Pos + 1 < len)
if(Pos < len)
{
even = even > W[Pos] ? even : W[Pos]; // before "odd"
odd = odd > W[Pos+1] ? odd : W[Pos+1]; // after "odd"
if(WidthsRow[Pos].odd !== -1)
{
if(maxDim < WidthsRow[Pos].even || maxDim < WidthsRow[Pos].odd)
{
maxDim = WidthsRow[Pos].even < WidthsRow[Pos].odd ? WidthsRow[Pos].odd : WidthsRow[Pos].even;
maxDimWidth = WidthsRow[Pos].even + WidthsRow[Pos].odd;
//this.WidthsPoints[Pos] = WidthsRow[Pos].even + WidthsRow[Pos].odd;
}
even = even > WidthsRow[Pos].even ? even : WidthsRow[Pos].even; // before "odd"
odd = odd > WidthsRow[Pos].odd ? odd : WidthsRow[Pos].odd; // after "odd"
}
else
{
if(maxDim < WidthsRow[Pos].even)
{
maxDim = WidthsRow[Pos].even;
maxDimWidth = maxDim;
//this.WidthsPoints[Pos] = maxDim;
}
last = last > WidthsRow[Pos].even ? last: WidthsRow[Pos].even;
}
if(Pos == len - 1)
EndWidths++;
}
/*if(Pos == len && len == 0) // для контентов без точек выравнивания
{
last =
EndWidths++;
}*/
}
var w = even + odd > last ? even + odd : last;
var NewPoint = new CMathPoint();
NewPoint.even = even;
NewPoint.odd = odd;
this.WidthsPoints.push(w);
this.MaxDimWidths.push(maxDimWidth);
this.Points.push(NewPoint);
WidthsMetrics[0] += w;
Pos++;
}
/*if(true)
{
var str = "";
for(var i = 0; i < this.WidthsPoints.length; i++)
{
var num = this.WidthsPoints[i].toFixed(3);
str += num + " ";
}
console.log(str);
}*/
for(var i = 0; i < this.nRow; i++)
{
var size = this.elements[i][0].size;
AscentsMetrics[i] = size.ascent;
DescentsMetrics[i] = size.height - size.ascent;
}
/*for(var tt = 0; tt < this.nCol; tt++ )
Widths[tt] = 0;
for(var i=0; i < this.nRow; i++)
{
Ascents[i] = 0;
Descents[i] = 0;
for(var j = 0; j < this.nCol ; j++)
{
var size = this.elements[i][j].size;
Widths[j] = i > 0 && ( Widths[j] > size.width ) ? Widths[j] : size.width;
Ascents[i] = (Ascents[i] > size.ascent ) ? Ascents[i] : size.ascent;
Descents[i] = (Descents[i] > size.height - size.ascent ) ? Descents[i] : size.height - size.ascent;
}
}*/
return {ascents: AscentsMetrics, descents: DescentsMetrics, widths: WidthsMetrics};
}
CEqArray.prototype.old_getMetrics = function(RPI) // нормальный расчет, без случая с Last элементом
{
var AscentsMetrics = [];
var DescentsMetrics = [];
var WidthsMetrics = [];
// нумерация начинается с нуля, поэтому все четные точки идут с нечетными номерами в массиве
//var lngW = RPI.Widths.length; // this.nRow
var EndWidths = 0;
var even, // четная точка
odd, // нечетная точка
last;
var Pos = 0;
this.WidthsPoints.length = 0;
this.Points.length = 0;
WidthsMetrics[0] = 0;
while(EndWidths < this.nRow)
{
even = 0;
odd = 0;
last = 0;
for(var i = 0; i < this.nRow; i++)
{
var WidthsRow = this.elements[i][0].WidthPoints.Widths,
len = WidthsRow.length;
if(Pos < len)
{
if(WidthsRow[Pos].odd !== -1)
{
even = even > WidthsRow[Pos].even ? even : WidthsRow[Pos].even; // before "odd"
odd = odd > WidthsRow[Pos].odd ? odd : WidthsRow[Pos].odd; // after "odd"
}
else
{
last = last > WidthsRow[Pos].even ? last: WidthsRow[Pos].even;
}
if(Pos == len - 1)
EndWidths++;
}
else if(Pos < len)
/*if(Pos == len && len == 0) // для контентов без точек выравнивания
{
last =
EndWidths++;
}*/
}
var w = even + odd > last ? even + odd : last;
var NewPoint = new CMathPoint();
NewPoint.even = even;
NewPoint.odd = odd;
this.WidthsPoints.push(w);
this.Points.push(NewPoint);
WidthsMetrics[0] += w;
Pos++;
}
/*if(true)
{
var str = "";
for(var i = 0; i < this.WidthsPoints.length; i++)
{
var num = this.WidthsPoints[i].toFixed(3);
str += num + " ";
}
console.log(str);
}*/
for(var i = 0; i < this.nRow; i++)
{
var size = this.elements[i][0].size;
AscentsMetrics[i] = size.ascent;
DescentsMetrics[i] = size.height - size.ascent;
}
/*for(var tt = 0; tt < this.nCol; tt++ )
Widths[tt] = 0;
for(var i=0; i < this.nRow; i++)
{
Ascents[i] = 0;
Descents[i] = 0;
for(var j = 0; j < this.nCol ; j++)
{
var size = this.elements[i][j].size;
Widths[j] = i > 0 && ( Widths[j] > size.width ) ? Widths[j] : size.width;
Ascents[i] = (Ascents[i] > size.ascent ) ? Ascents[i] : size.ascent;
Descents[i] = (Descents[i] > size.height - size.ascent ) ? Descents[i] : size.height - size.ascent;
}
}*/
return {ascents: AscentsMetrics, descents: DescentsMetrics, widths: WidthsMetrics};
}
CEqArray.prototype.new_getMetrics = function(RPI)
{
var AscentsMetrics = [];
var DescentsMetrics = [];
var WidthsMetrics = [];
// нумерация начинается с нуля, поэтому все четные точки идут с нечетными номерами в массиве
//var lngW = RPI.Widths.length; // this.nRow
var EndWidths = 0;
var even, // четная точка
odd, // нечетная точка
last,
maxDim;
var Pos = 0;
this.WidthsPoints.length = 0;
this.Points.length = 0;
WidthsMetrics[0] = 0;
while(EndWidths < this.nRow)
{
even = 0;
odd = 0;
last = 0;
maxDim = 0;
for(var i = 0; i < this.nRow; i++)
{
var WidthsRow = this.elements[i][0].WidthPoints.Widths,
len = WidthsRow.length;
if(Pos < len)
{
last = last > W[Pos] ? last: W[Pos];
if(WidthsRow[Pos].odd !== -1)
{
if(maxDim < WidthsRow[Pos].even || maxDim < WidthsRow[Pos].odd)
{
maxDim = WidthsRow[Pos].even < WidthsRow[Pos].odd ? WidthsRow[Pos].odd : WidthsRow[Pos].even;
this.WidthsPoints[Pos] = WidthsRow[Pos].even + WidthsRow[Pos].odd;
}
even = even > WidthsRow[Pos].even ? even : WidthsRow[Pos].even; // before "odd"
odd = odd > WidthsRow[Pos].odd ? odd : WidthsRow[Pos].odd; // after "odd"
}
else
{
if(maxDim < WidthsRow[Pos].even)
{
maxDim = WidthsRow[Pos].even;
this.WidthsPoints[Pos] = maxDim;
}
last = last > WidthsRow[Pos].even ? last: WidthsRow[Pos].even;
}
if(Pos == len - 1)
EndWidths++;
}
if(Pos + 1 == len || Pos + 2 == len)
/*if(Pos == len && len == 0) // для контентов без точек выравнивания
{
last =
EndWidths++;
}*/
}
var w = even + odd > last ? even + odd : last;
......@@ -789,12 +1050,12 @@ CEqArray.prototype.getMetrics = function(RPI)
NewPoint.even = even;
NewPoint.odd = odd;
this.WidthsPoints.push(w);
//this.WidthsPoints.push(w);
this.Points.push(NewPoint);
WidthsMetrics[0] += w;
Pos += 2;
Pos++;
}
/*if(true)
......@@ -837,10 +1098,10 @@ CEqArray.prototype.getMetrics = function(RPI)
return {ascents: AscentsMetrics, descents: DescentsMetrics, widths: WidthsMetrics};
}
CEqArray.prototype.setPosition = function(pos, PosInfo)
CEqArray.prototype.setPosition = function(pos)
{
PosInfo.Widths = this.WidthsPoints;
PosInfo.Points = this.Points;
//PosInfo.Widths = this.WidthsPoints;
//PosInfo.Points = this.Points;
this.pos.x = pos.x;
......@@ -861,13 +1122,15 @@ CEqArray.prototype.setPosition = function(pos, PosInfo)
NewPos.x = this.pos.x + this.GapLeft;
NewPos.y = this.pos.y + h;
this.elements[i][0].setPosition(NewPos, PosInfo);
//PosInfo.CurrPoint = 0;
this.elements[i][0].setPosition(NewPos);
h += Heights[i] + this.gaps.row[i];
}
PosInfo.Widths.length = 0;
PosInfo.Points.length = 0;
//PosInfo.Widths.length = 0;
//PosInfo.Points.length = 0;
}
CEqArray.prototype.setProperties = function(props)
......
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