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

1. Полностью переделала поиск позиции, Get_ParaContentPosByXY

* осталось доделать для матриц, Nary, Delimiters, GroupCharacters и Radical
2. Поправила баг : GapLeft для буквы был отрицательный, когда перед ней стоял мат объект. 
В связи с этим неправильно вычислялись ширина и позиция у буквы.
3. Для диакритических элементов (accent) отрисовываю i, j без точек для scr = TXT_ROMAN,
для стилей italic и plain

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@57641 954022d7-b5bf-4e40-9824-e11837661b57
parent 3dbcc17a
......@@ -35,7 +35,7 @@ function ParaMath()
this.bSelectionUse = false;
this.State = new CParaRunState(); // Положение курсора и селекта для данного run
//this.State = new CParaRunState(); // Положение курсора и селекта для данного run
this.Paragraph = null;
this.StartLine = 0;
......@@ -1204,6 +1204,9 @@ ParaMath.prototype =
var StartPos = this.Lines[CurLine].Ranges[CurRange].StartPos;
var EndPos = this.Lines[CurLine].Ranges[CurRange].EndPos;
/*PDSE.Graphics.p_color(255,0,0, 255);
PDSE.Graphics.drawHorLine(0, PDSE.Y - this.Ascent, PDSE.X - 30, PDSE.X + this.Width + 30 , 1);*/
if ( EndPos >= 1 )
{
//this.Math.Draw( PDSE.X, PDSE.Y, PDSE.Graphics );
......@@ -1214,6 +1217,9 @@ ParaMath.prototype =
this.Root.draw( PDSE.X, PDSE.Y - this.Ascent, PDSE.Graphics);
PDSE.X += this.Width;
}
/*PDSE.Graphics.p_color(255,0,0, 255);
PDSE.Graphics.drawHorLine(0, PDSE.Y - this.Ascent + this.Height, PDSE.X - 30, PDSE.X + this.Width + 30 , 1);*/
},
Draw_Lines : function(PDSL)
......@@ -1296,22 +1302,42 @@ ParaMath.prototype =
var Dx = this.Root.size.width;
var D = SearchPos.X - SearchPos.CurX;
var startDx = Math.abs(D),
endDx = Math.abs(D - Dx);
/*var startDx = Math.abs(D),
endDx = Math.abs(D - Dx);*/
var Diff = startDx < endDx ? startDx : endDx;
//var Diff = startDx < endDx ? startDx : endDx;
var CurX = SearchPos.CurX;
if(Math.abs(Diff) < SearchPos.DiffX + 0.001)
//SearchPos.CurY = SearchPos.Y - this.Y;
Result = this.Root.Get_ParaContentPosByXY(SearchPos, Depth, _CurLine, _CurRange, StepEnd);
/*var str = "Get_ParaContentPosByXY :";
//console.log("Get_ParaContentPosByXY");
for(var i = 0; i < SearchPos.Pos.Data.length; i++)
{
str += SearchPos.Pos.Data[i] + " ";
}
if(this.Id == "80")
console.log(str);*/
if ( D >= - 0.001 && D <= Dx + 0.001 )
{
SearchPos.DiffX = 0.001;
}
/*if(Math.abs(Diff) < SearchPos.DiffX + 0.001)
{
if ( D >= - 0.001 && D <= Dx + 0.001 )
{
var X = SearchPos.X,
Y = SearchPos.Y;
//console.log("Get_ParaContentPosByXY: X " + SearchPos.X + " Y " + SearchPos.Y);
SearchPos.X -= this.X;
SearchPos.Y -= this.Y;
......@@ -1341,7 +1367,7 @@ ParaMath.prototype =
Result = true;
}
}*/
SearchPos.CurX = CurX + Dx;
}
......@@ -1371,7 +1397,7 @@ ParaMath.prototype =
{
// TODO: ParaMath.Set_ParaContentPos
this.State.ContentPos = ContentPos.Get(Depth);
//this.State.ContentPos = ContentPos.Get(Depth);
/*console.log("Set_ParaContentPos");
var str = "";
......@@ -1382,6 +1408,8 @@ ParaMath.prototype =
console.log(str);*/
//console.log("Set_ParaContentPos");
this.Root.Set_ParaContentPos(ContentPos, Depth);
},
......
......@@ -3669,7 +3669,7 @@ ParaRun.prototype =
Result = true;
}
if (this.Type == para_Math_Run)
if (this.Type == para_Math_Run && this.Is_Empty())
{
var Diff = SearchPos.X - SearchPos.CurX;
if ( Math.abs( Diff ) < SearchPos.DiffX + 0.001 )
......@@ -7734,6 +7734,10 @@ ParaRun.prototype.Set_MathPr = function(MPrp)
History.Add( this, { Type : historyitem_ParaRun_MathPrp, New : MPrp, Old : OldValue } );
this.Recalc_CompiledPr(true);
}
ParaRun.prototype.IsAccent = function()
{
return this.Parent.IsAccent();
}
function CParaRunStartState(Run)
......
......@@ -550,6 +550,10 @@ CAccent.prototype.setChrType = function(chrType)
this.Pr.chrType = chrType;
this.RecalcInfo.bProps = true;
}
CAccent.prototype.IsAccent = function()
{
return true;
}
CAccent.prototype.old_init = function(properties)
{
var type = properties.chrType,
......@@ -1195,6 +1199,24 @@ CAccent.prototype.findDisposition = function(SearchPos, Depth)
SearchPos.Pos.Update(0, Depth + 1);
}
CAccent.prototype.Get_ParaContentPosByXY = function(SearchPos, Depth, _CurLine, _CurRange, StepEnd)
{
var align = (this.size.width - this.elements[0][0].size.width)/2;
SearchPos.CurX += this.GapLeft + align;
var result = this.elements[0][0].Get_ParaContentPosByXY(SearchPos, Depth+2, _CurLine, _CurRange, StepEnd);
if(result)
{
SearchPos.Pos.Update(0, Depth);
SearchPos.Pos.Update(0, Depth+1);
}
SearchPos.CurX += this.GapRight + align;
return result;
}
CAccent.prototype.setProperties = function(props)
{
this.Pr.chr = props.chr;
......
......@@ -213,6 +213,10 @@ CMathBase.prototype =
{
return false;
},
IsAccent: function()
{
return false;
},
getWidthsHeights: function()
{
var Widths = [];
......@@ -861,11 +865,10 @@ CMathBase.prototype =
return gaps;
},
/// Position for Paragraph
Get_ParaContentPosByXY: function(SearchPos, Depth, _CurLine, _CurRange, StepEnd)
old_Get_ParaContentPosByXY: function(SearchPos, Depth, _CurLine, _CurRange, StepEnd)
{
/// элементов just-draw не должно прийти
this.Check_PosInGaps(SearchPos);
this.findDisposition(SearchPos, Depth);
......@@ -889,6 +892,97 @@ CMathBase.prototype =
this.elements[Curr_Pos_X][Curr_Pos_Y].Get_ParaContentPosByXY(SearchPos, Depth+2, _CurLine, _CurRange, StepEnd);
},
Get_ParaContentPosByXY: function(SearchPos, Depth, _CurLine, _CurRange, StepEnd)
{
var maxWH = this.getWidthsHeights();
var Widths = maxWH.widths;
var Heights = maxWH.heights;
var X = this.ParaMath.X + this.pos.x + this.GapLeft, // this.ParaMath.X + this.pos.x совпадает с SearchPos.CurX
Y = this.ParaMath.Y + this.pos.y;
var CurrX, CurrY,
W_CurX,
Diff = 100000000;
var W = 0, H = 0;
var rX, rY,
minR;
for(var i=0; i < this.nRow; i++)
{
for(var j=0; j < this.nCol; j++)
{
if(!this.elements[i][j].IsJustDraw())
{
/*rY = SearchPos.Y - Y - H;
rX = SearchPos.X - X - W;
R = rX*rX + rY*rY;
rrX = SearchPos.X - X - W - Widths[j];
rrY = SearchPos.Y - Y - H - Heights[i];
RR = rrX*rrX + rrY*rrY;*/
var x1 = SearchPos.X - X - W,
x2 = SearchPos.X - X - W - Widths[j],
y1 = SearchPos.Y - Y - H,
y2 = SearchPos.Y - Y - H - Heights[i];
var bInY = 0 < y1 && y2 < 0,
bInX = 0 < x1 && x2 < 0;
rX = x1*x1 < x2*x2 ? x1 : x2;
rY = y1*y1 < y2*y2 ? y1 : y2;
if(bInY && bInX)
minR = 0;
else if(!bInY && !bInX)
minR = rX*rX + rY*rY;
else if(bInY)
minR = rX*rX;
else
minR = rY*rY;
if(Diff > minR)
{
Diff = minR;
CurrX = i;
CurrY = j;
W_CurX = W;
}
}
W += Widths[j] + this.dW;
}
W = 0;
H += Heights[i] + this.dH;
}
var SearchCurX = SearchPos.CurX;
var align = this.align(CurrX, CurrY);
SearchPos.CurX += this.GapLeft + W_CurX + align.x;
var result = this.elements[CurrX][CurrY].Get_ParaContentPosByXY(SearchPos, Depth+2, _CurLine, _CurRange, StepEnd);
if(result)
{
SearchPos.Pos.Update(CurrX, Depth);
SearchPos.Pos.Update(CurrY, Depth + 1);
}
SearchPos.CurX = SearchCurX + this.size.width;
return result;
},
Check_PosInGaps: function(SearchPos)
{
if(SearchPos.X <= this.GapLeft)
......
......@@ -381,6 +381,24 @@ CBorderBox.prototype.findDisposition = function(SearchPos, Depth)
//return {pos: posCurs, mCoord: coord, inside_flag: inside_flag};
}
CBorderBox.prototype.Get_ParaContentPosByXY = function(SearchPos, Depth, _CurLine, _CurRange, StepEnd)
{
var alignLeft = this.Pr.hideLeft ? 0 : this.gapBrd,
alignRight = this.Pr.hideRight ? 0 : this.gapBrd;
SearchPos.CurX += this.GapLeft + alignLeft;
var result = this.elements[0][0].Get_ParaContentPosByXY(SearchPos, Depth+2, _CurLine, _CurRange, StepEnd);
if(result)
{
SearchPos.Pos.Update(0, Depth);
SearchPos.Pos.Update(0, Depth + 1);
}
SearchPos.CurX += alignRight;
return result;
}
CBorderBox.prototype.getBase = function()
{
return this.elements[0][0];
......
......@@ -72,12 +72,12 @@ CFraction.prototype.drawSkewedFraction = function(x, y, pGraphics)
var penW = mgCtrPrp.FontSize/12.5*g_dKoef_pix_to_mm;
var gap = this.gapSlash/2 - penW/7.5;
var gap = this.dW/2 - penW/7.5;
var plh = 9.877777777777776 * mgCtrPrp.FontSize / 36;
var minHeight = 2*this.gapSlash,
var minHeight = 2*this.dW,
middleHeight = plh*4/3,
maxHeight = (3*this.gapSlash + 5*plh)*2/3;
maxHeight = (3*this.dW + 5*plh)*2/3;
var tg;
var tg1 = -2.22,
......@@ -284,8 +284,9 @@ CFraction.prototype.recalculateSkewed = function(oMeasure)
//var ctrPrp = this.Get_CompiledCtrPrp();
var mgCtrPrp = this.Get_CompiledCtrPrp();
this.gapSlash = 5.011235894097222 * mgCtrPrp.FontSize/36;
var width = this.elements[0][0].size.width + this.gapSlash + this.elements[0][1].size.width;
//this.gapSlash = 5.011235894097222 * mgCtrPrp.FontSize/36;
this.dW = 5.011235894097222 * mgCtrPrp.FontSize/36;
var width = this.elements[0][0].size.width + this.dW + this.elements[0][1].size.width;
var height = this.elements[0][0].size.height + this.elements[0][1].size.height;
var ascent = this.elements[0][0].size.height + this.ParaMath.GetShiftCenter(oMeasure, mgCtrPrp);
......@@ -337,16 +338,19 @@ CFraction.prototype.setPosition = function(pos)
this.pos.x = pos.x;
this.pos.y = pos.y - this.size.ascent;
var X = this.pos.x + this.GapLeft,
Y = this.pos.y;
var PosNum = new CMathPosition();
PosNum.x = this.pos.x + this.GapLeft;
PosNum.y = this.pos.y;
PosNum.x = X;
PosNum.y = Y;
var PosDen = new CMathPosition();
PosDen.x = this.pos.x + this.GapLeft + this.elements[0][0].size.width + this.gapSlash;
PosDen.y = this.pos.y + this.elements[0][0].size.height;
PosDen.x = X + this.elements[0][0].size.width + this.dW;
PosDen.y = Y + this.elements[0][0].size.height;
this.elements[0][0].setPosition(PosNum);
this.elements[0][1].setPosition(PosDen);
......
......@@ -68,6 +68,8 @@ function CCoeffGaps()
{
left: new CGaps(0.52, 0.26, 0, 0.52),
right: new CGaps(0.49, 0, 0, 0.49)
//left: new CGaps(0.52, 0.26, 0, 2.5),
//right: new CGaps(0.49, 0, 0, 2)
};
this.Mult =
......@@ -471,7 +473,8 @@ CMathGapsInfo.prototype =
rightCoeff = this.getGapsMComp(this.Left, 1);
leftCoeff = COEFF_GAPS.getCoeff(currCode, -1, -1);
leftCoeff -= rightCoeff;
if(leftCoeff > rightCoeff)
leftCoeff -= rightCoeff;
}
else
{
......@@ -500,9 +503,7 @@ CMathGapsInfo.prototype =
rightCoeff /= 2;
if(leftCoeff < rightCoeff/2)
{
leftCoeff = rightCoeff/2;
}
else
leftCoeff -= rightCoeff/2;
}
......@@ -567,9 +568,8 @@ CMathGapsInfo.prototype =
coeffRight = 0.3;
}
var result = direct == -1 ? coeffLeft : coeffRight;
return result;
return direct == -1 ? coeffLeft : coeffRight;
},
checkGapKind: function(kind)
{
......@@ -4073,7 +4073,6 @@ CMathContent.prototype =
NewPos.y = pos.y + this.size.ascent; // y по baseline;
for(var i=0; i < this.content.length; i++)
{
this.content[i].setPosition(NewPos);
......@@ -4128,6 +4127,15 @@ CMathContent.prototype =
return ctrPrp;
},
IsAccent: function()
{
var result = false;
if(!this.bRoot)
result = this.Parent.IsAccent();
return result;
},
////////////////////////
//////// /////////
......@@ -4467,6 +4475,12 @@ CMathContent.prototype =
var currPos = 0;
if(this.bRoot)
{
console.log(TEST_STR);
TEST_STR = "";
}
while(currPos < len)
{
current = this.content[currPos];
......@@ -4531,6 +4545,7 @@ CMathContent.prototype =
this.Internal_Content_Add(len, emptyRun);
}
},
Create_FontMap : function(Map)
{
......@@ -4544,7 +4559,8 @@ CMathContent.prototype =
},
/// функции для работы с курсором
Get_ParaContentPosByXY: function(SearchPos, Depth, _CurLine, _CurRange, StepEnd)
old_Get_ParaContentPosByXY: function(SearchPos, Depth, _CurLine, _CurRange, StepEnd)
{
if(this.content.length > 0) // случай , если у нас контент не заполнен, не предусмотрен
{
......@@ -4565,11 +4581,133 @@ CMathContent.prototype =
else if(this.content[pos].Type == para_Math_Run) // проверка на gaps в findDisposition
{
SearchPos.X += this.pos.x + this.ParaMath.X + this.WidthToElement[pos];
SearchPos.CurX += this.pos.x + this.WidthToElement[pos];
SearchPos.X += this.pos.x + this.WidthToElement[pos];
this.content[pos].Get_ParaContentPosByXY(SearchPos, Depth+1, _CurLine, _CurRange, StepEnd);
}
}
},
Get_ParaContentPosByXY: function(SearchPos, Depth, _CurLine, _CurRange, StepEnd)
{
var result = false;
if(this.content.length > 0) // случай , если у нас контент не заполнен, не предусмотрен
{
var W = 0;
var pos = 0;
var lng = this.content.length;
while( pos < lng - 1 && SearchPos.X > SearchPos.CurX + this.content[pos].size.width)
{
SearchPos.CurX += this.content[pos].size.width;
pos++;
}
var SearchCurX = SearchPos.CurX;
if(this.content[pos].Type == para_Math_Run)
{
//SearchPos.CurX += W;
if(this.content[pos].Get_ParaContentPosByXY(SearchPos, Depth+1, _CurLine, _CurRange, StepEnd))
{
SearchPos.Pos.Update(pos, Depth);
result = true;
}
}
else // para_Math_Composition
{
// необязательно попадем непосредственно в GapLeft просто в этом случае не ищем позицию в мат объектах,
// это избавит от ошибок, связанных с тем что расстояния до мат объекта и до пустого рана совпадают
// если же ран не пустой, то также должны встать в ран (в конец), а не в мат объект
if(SearchPos.X < SearchPos.CurX + this.content[pos].GapLeft)
{
SearchPos.CurX -= this.content[pos-1].size.width;
if(this.content[pos-1].Get_ParaContentPosByXY(SearchPos, Depth+1, _CurLine, _CurRange, StepEnd))
{
SearchPos.Pos.Update(pos-1, Depth);
result = true;
}
} // аналогично для GapRight
else if(SearchPos.CurX + this.content[pos].size.width - this.content[pos].GapRight < SearchPos.X)
{
SearchPos.CurX += this.content[pos].size.width + this.content[pos+1].size.width;
if(this.content[pos+1].Get_ParaContentPosByXY(SearchPos, Depth+1, _CurLine, _CurRange, StepEnd))
{
SearchPos.Pos.Update(pos+1, Depth);
result = true;
}
}
else
{
SearchPos.CurX -= this.content[pos-1].size.width;
// Для случая с Just-Draw элементами
if( this.content[pos-1].Get_ParaContentPosByXY(SearchPos, Depth+1, _CurLine, _CurRange, StepEnd) )
{
SearchPos.Pos.Update(pos-1, Depth);
result = true;
}
if( this.content[pos].Get_ParaContentPosByXY(SearchPos, Depth+1, _CurLine, _CurRange, StepEnd) )
{
SearchPos.Pos.Update(pos, Depth);
result = true;
}
if( this.content[pos+1].Get_ParaContentPosByXY(SearchPos, Depth+1, _CurLine, _CurRange, StepEnd) )
{
SearchPos.Pos.Update(pos+1, Depth);
result = true;
}
}
}
SearchPos.CurX = SearchCurX + this.size.width;
/*if(pos > 0)
{
SearchPos.CurX -= this.content[pos-1].size.width;
if( this.content[pos-1].Get_ParaContentPosByXY(SearchPos, Depth+1, _CurLine, _CurRange, StepEnd) )
{
SearchPos.Pos.Update(pos-1, Depth);
result = true;
}
}
if( this.content[pos].Get_ParaContentPosByXY(SearchPos, Depth+1, _CurLine, _CurRange, StepEnd) )
{
SearchPos.Pos.Update(pos, Depth);
result = true;
}
//this.findToInternalContent(pos, SearchPos, Depth, _CurLine, _CurRange, StepEnd);
//SearchPos.CurX += this.content[pos].size.width;
if(pos < lng - 1)
{
//SearchPos.CurX += this.size.width - this.WidthToElement[pos + 1];
if( this.content[pos+1].Get_ParaContentPosByXY(SearchPos, Depth+1, _CurLine, _CurRange, StepEnd) )
{
SearchPos.Pos.Update(pos+1, Depth);
result = true;
}
//SearchPos.CurX += this.size.width - this.WidthToElement[pos + 1] + this.content[pos + 1].size.width;
}*/
}
return result;
},
Get_ParaContentPos: function(bSelection, bStart, ContentPos)
{
if( bSelection )
......@@ -4590,13 +4728,8 @@ CMathContent.prototype =
{
this.CurPos = ContentPos.Get(Depth);
Depth++;
if(this.content.length > 0)
{
this.content[this.CurPos].Set_ParaContentPos(ContentPos, Depth);
}
this.content[this.CurPos].Set_ParaContentPos(ContentPos, Depth+1);
},
Cursor_MoveToStartPos: function()
......
......@@ -17,6 +17,8 @@ var DIV_CENT = 0.1386;
var StartTextElement = 0x2B1A; // Cambria Math
var TEST_STR = "";
// TODO
// убрать CMathTextPrp
......@@ -103,6 +105,10 @@ CMathText.prototype =
code = 0x2212;
this.value = code;
TEST_STR += code.toString(16) + " ";
},
addTxt: function(txt)
{
......@@ -118,6 +124,8 @@ CMathText.prototype =
if(this.Type === para_Math_Placeholder || this.bJDraw || Compiled_MPrp.nor)
return code;
var bAccent = this.Parent.IsAccent();
var bCapitale = (code > 0x0040 && code < 0x005B),
bSmall = (code > 0x0060 && code < 0x007b),
bDigit = (code > 0x002F && code < 0x003A);
......@@ -137,14 +145,14 @@ CMathText.prototype =
{
if(code == 0x68) // h
code = 0x210E;
else if((code == 0x69 && bAccent) || code == 0x131) // "i" with dot || "i" dotless plain => "i" dotless italic
code = 0x1D6A4;
else if((code == 0x6A && bAccent) ||code == 0x237) // "j" with dot || "j" dotless plain => "j" dotless italic
code = 0x1D6A5;
else if(bCapitale)
code = code + 0x1D3F3;
else if(bSmall)
code = code + 0x1D3ED;
else if(code == 0x131) // "i" without dot
code = 0x1D6A4;
else if(code == 0x237) // "j" without dot
code = 0x1D6A5;
else if(code == 0x3F4) // Capital THETA special
code = 0x1D6F3;
else if(code == 0x2207) // Capital NABLA
......@@ -235,6 +243,16 @@ CMathText.prototype =
else if(code == 0x3DD) // SMALL DIGAMMA
code = 0x1D7CB;
}
else // PLAIN
{
if(bAccent)
{
if(code == 0x69) // "i" with dot => "i" dotless plain
code = 0x131;
else if(code == 0x6A) // "j" with dot => "j" dotless plain
code = 0x237;
}
}
}
else if(Scr == TXT_DOUBLE_STRUCK)
{
......
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