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

переделаны Recalculate, setPostion, Draw для PARA_RUN

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@55283 954022d7-b5bf-4e40-9824-e11837661b57
parent 61db8995
......@@ -6366,10 +6366,12 @@ function CRunCollaborativeRange(PosS, PosE)
}
// добавлены поля
// size, Parent
ParaRun.prototype.Math_SetPosition = function(_pos)
{
var pos = {x: _pos.x, y: _pos.y - this.size.ascent};
var pos = {x: _pos.x, y: _pos.y - this.Math_GetSize().ascent};
for(var i = 0; i < this.Content.length; i++)
{
......@@ -6382,35 +6384,49 @@ ParaRun.prototype.Math_Draw = function(x, y, pGraphics)
if(this.bMathRun)
{
var X = x;
var Y = y + this.size.ascent;
var Y = y + this.Math_GetSize().ascent;
pGraphics.b_color1(0,0,0,255);
for(var i=0; i < this.Content.length;i++)
{
var oWPrp = this.Get_CompiledPr(false);
oWPrp.Merge(this.Parent.Composition.DEFAULT_RUN_PRP.getTxtPrp());
g_oTextMeasurer.SetFont(oWPrp);
this.Content[i].draw(X, Y, pGraphics);
}
}
}
ParaRun.prototype.Math_Recalculate = function()
ParaRun.prototype.Math_Recalculate = function(RecalcInfo)
{
var RangeStartPos = 0;
var RangeEndPos = this.Content.length;
this.Lines[0].Add_Range( 0, RangeStartPos, RangeEndPos );
// ??
this.Lines[0].Add_Range(0, RangeStartPos, RangeEndPos);
var width = 0,
ascent = 0, descent = 0;
var oWPrp = this.Get_CompiledPr(false);
oWPrp.Merge(this.Parent.Composition.DEFAULT_RUN_PRP.getTxtPrp());
var oWPrp = this.Get_CompiledPr(true);
oWPrp.Merge(RecalcInfo.Composition.DEFAULT_RUN_PRP.getTxtPrp());
// TODO
// смержить еще с math_Run_Prp
g_oTextMeasurer.SetFont(oWPrp);
for (var Pos = 0 ; Pos < this.Content.length; Pos++ )
{
RecalcInfo.leftRunPrp = RecalcInfo.currRunPrp;
RecalcInfo.Left = RecalcInfo.Current;
RecalcInfo.currRunPrp = oWPrp;
RecalcInfo.Current = this.Content[Pos];
RecalcInfo.setGaps();
this.Content[Pos].Resize(g_oTextMeasurer);
var oSize = this.Content[Pos].size;
......@@ -6424,6 +6440,24 @@ ParaRun.prototype.Math_Recalculate = function()
descent = descent < oDescent ? oDescent : descent;
}
this.size = {width: width, height: ascent + descent, ascent: ascent};
//this.size = {width: width, height: ascent + descent, ascent: ascent};
}
ParaRun.prototype.Math_GetSize = function()
{
var width = 0,
ascent = 0, descent = 0;
for (var Pos = 0 ; Pos < this.Content.length; Pos++ )
{
this.Content[Pos].Resize(g_oTextMeasurer);
var oSize = this.Content[Pos].size;
width += oSize.width;
ascent = ascent > oSize.ascent ? ascent : oSize.ascent;
var oDescent = oSize.height - oSize.ascent;
descent = descent < oDescent ? oDescent : descent;
}
return {width: width, height: ascent + descent, ascent: ascent};
}
\ No newline at end of file
......@@ -1566,7 +1566,7 @@ function Binary_oMathWriter(memory, oMathPara)
this.WriteMathElem = function(mathElem)
{
var oThis = this;
var item = mathElem.value;
var item = mathElem;
switch ( item.typeObj)
{
case MATH_COMP:
......@@ -1626,7 +1626,7 @@ function Binary_oMathWriter(memory, oMathPara)
this.WriteMathElemCollaborative = function(mathElem)
{
var oThis = this;
var item = mathElem.value;
var item = mathElem;
switch ( item.typeObj)
{
case MATH_COMP:
......@@ -1745,7 +1745,7 @@ function Binary_oMathWriter(memory, oMathPara)
{
var item = oElem.content[i];
if (MATH_RUN_PRP == item.value.typeObj)
if (MATH_RUN_PRP == item.typeObj)
{
var nCurPos = 0;
this.memory.WriteByte(c_oSer_OMathContentType.MRun);
......
......@@ -48,6 +48,9 @@ function CMathBase()
wdt: null
};
this.GapLeft = 0;
this.GapRight = 0;
return this;
}
CMathBase.prototype =
......@@ -939,8 +942,8 @@ CMathBase.prototype =
},
recalculateSize: function(oMeasure)
{
var _width = 0;
var _height = 0;
var width = 0;
var height = 0;
var maxWH = this.getWidthsHeights();
......@@ -950,18 +953,19 @@ CMathBase.prototype =
var Heights = maxWH.heights;
for( j = 0 ; j < this.nRow; j++ )
_height += Heights[j];
height += Heights[j];
_height += this.dH*(this.nRow - 1);
height += this.dH*(this.nRow - 1);
for( i=0; i < this.nCol ; i++)
_width += Widths[i];
for(var i=0; i < this.nCol ; i++)
width += Widths[i];
_width += this.dW*(this.nCol - 1);
width += this.dW*(this.nCol - 1);
width += this.GapLeft + this.GapRight;
var _ascent = this.getAscent(_height, oMeasure);
var ascent = this.getAscent(height, oMeasure);
this.size = {width: _width, height: _height, ascent: _ascent};
this.size = {width: width, height: height, ascent: ascent};
},
/*RecalculateReverse: function(oMeasure)
{
......@@ -1215,7 +1219,7 @@ CMathBase.prototype =
return content;
},
getGapsInside: function()
getGapsInside: function(RecalcInfo)
{
var kind = this.kind;
var gaps = {left: 0, right: 0};
......@@ -1224,7 +1228,7 @@ CMathBase.prototype =
if(checkBase)
{
var base = this.getBase();
gaps = base.getGapsInside();
gaps = base.getGapsInside(RecalcInfo);
}
return gaps;
......
......@@ -66,6 +66,477 @@ var SELECT_CHILD = 1;
var StartTextElement = 0x2B1A; // Cambria Math
function CGaps(oSign, oEqual, oZeroOper, oLett)
{
this.sign = oSign;
this.equal = oEqual;
this.zeroOper = oZeroOper;
this.letters = oLett;
}
function CCoeffGaps()
{
this.Sign =
{
left: new CGaps(0.52, 0.26, 0, 0.52),
right: new CGaps(0.49, 0, 0, 0.49)
};
this.Mult =
{
left: new CGaps(0, 0, 0, 0.46),
right: new CGaps(0, 0, 0, 0.49)
};
this.Equal =
{
left: new CGaps(0.35, 0, 0, 0.7),
right: new CGaps(0.25, 0, 0, 0.5)
};
this.Default =
{
left: new CGaps(0, 0, 0, 0),
right: new CGaps(0, 0, 0, 0)
};
}
CCoeffGaps.prototype =
{
getCoeff: function(codeCurr, codeLR , direct) // obj - либо codeChar, либо мат объект
{
var operator = null;
if(codeCurr == 0x3D)
operator = this.Equal;
else if(this.checkOperSign(codeCurr))
operator = this.Sign;
else if(codeCurr == 0x2217)
operator = this.Mult;
else
operator = this.Default;
var part = direct == -1 ? operator.left : operator.right;
var coeff = 0;
if(codeLR == -1) // мат объект
coeff = part.letters;
else if(this.checkOperSign(codeLR))
coeff = part.sign;
else if(codeLR == 0x3D )
coeff = part.equal;
else if(codeLR == this.checkZEROSign(codeLR))
coeff = part.zeroOper;
else
coeff = part.letters;
return coeff;
},
checkOperSign: function(code) // "+", "-", "<", ">", "±"
{
var PLUS = 0x2B,
MINUS = 0x2212,
LESS = 0x3C,
GREATER = 0x3E,
PLUS_MINUS = 0xB1;
return code == PLUS || code == MINUS || code == LESS || code == GREATER || code == PLUS_MINUS;
},
checkZEROSign: function(code, direct) // "*", "/", "\"
{
var MULT = 0x2217,
DIVISION = 0x2F,
B_SLASH = 0x5C;
var bOper = code == MULT || code == DIVISION || code == B_SLASH;
var bLeftBracket = direct == -1 && (code == 0x28 || code == 0x5B || code == 0x7B);
var bRightBracket = direct == 1 && (code == 0x29 || code == 0x5D || code == 0x7D);
return bOper || bLeftBracket || bRightBracket;
}
}
var COEFF_GAPS = new CCoeffGaps();
function CRecalculateInfo(oMeasure, argSize, Composition)
{
this.measure = oMeasure;
this.Composition = Composition; // для Para_Run
this.argSize = argSize; // argSize выставляем один раз для всего контента
this.leftRunPrp = null; // Run_Prp левого элемента
this.currRunPrp = null;
this.Left = null; // элемент слева
this.Current = null; // текущий элемент
}
CRecalculateInfo.prototype =
{
old_checkGapsSign: function(oMeasure, posCurr)
{
var left = null,
right = null;
var curr = this.content[posCurr].value;
if(this.argSize < 0)
{
// выставим нулевые gaps для случая, если при копировании/вставки часть контента добавили в итератор
this.content[posCurr].gaps.left = 0;
this.content[posCurr].gaps.right = 0;
}
else
{
var EQUAL = 0x3D,
PLUS = 0x2B,
MINUS = 0x2212,
MULT = 0x2217,
LESS = 0x3C,
GREATER = 0x3E;
var t = posCurr - 1;
while( t > 0 )
{
if(this.content[t].value.typeObj == MATH_TEXT || this.content[t].value.typeObj == MATH_COMP)
{
left = this.content[t].value;
break;
}
t--;
}
t = posCurr + 1;
while( t < this.content.length )
{
if(this.content[t].value.typeObj == MATH_TEXT || this.content[t].value.typeObj == MATH_COMP)
{
right = this.content[t].value;
break;
}
t++;
}
var coeffLeft = 0,
coeffRight = 0;
var bLeft = left !== null,
bRight = right !== null;
var bLeftComp = bLeft ? left.typeObj == MATH_COMP : false,
bRightComp = bRight ? right.typeObj == MATH_COMP : false,
bLeftText = bLeft ? left.typeObj == MATH_TEXT : false,
bRightText = bRight ? right.typeObj == MATH_TEXT : false;
var currCode = curr.typeObj == MATH_TEXT ? curr.getCodeChr() : null,
leftCode = bLeftText ? left.getCodeChr() : null,
rightCode = bRightText ? right.getCodeChr() : null;
var gapLeftComp = 0,
gapRightComp = 0;
if(bLeftComp)
gapLeftComp = this.getGapsMComp(left).right;
if(bRightComp)
gapRightComp = this.getGapsMComp(right).left;
if(curr.typeObj == MATH_TEXT)
{
var bSign = false;
if(this.checkOperSign(currCode)) // plus, minus, greater, less
{
bSign = true;
if(bLeft)
{
if(this.checkZEROSign(leftCode))
coeffLeft = 0;
else if(leftCode == EQUAL)
coeffLeft = 0.26;
else
coeffLeft = 0.52;
}
if(bRight)
{
var bZero = this.checkZEROSign(rightCode);
if(rightCode == EQUAL || bZero)
coeffRight = 0;
else
coeffRight = 0.49;
}
}
else if(currCode === MULT) // multiplication
{
bSign = true;
if(bLeft)
{
var bZeroLeft = this.checkZEROSign(leftCode),
bOperLeft = this.checkOperSign(leftCode);
if(leftCode == EQUAL || bOperLeft || bZeroLeft)
coeffLeft = 0;
else if(bLeft)
coeffLeft = 0.46;
}
if(bRight)
{
var bZeroRight = this.checkZEROSign(rightCode),
bOperRight = this.checkOperSign(rightCode);
if(rightCode == EQUAL || bOperRight || bZeroRight)
coeffRight = 0;
else if(bRight)
coeffRight = 0.49;
}
}
else if(currCode === EQUAL) // equal
{
bSign = true;
if(bLeft)
{
var bZero = this.checkZEROSign(leftCode);
if(leftCode == EQUAL || bZero)
coeffLeft = 0;
else if(this.checkOperSign(leftCode))
coeffLeft = 0.35;
else
coeffLeft = 0.7;
}
if(bRight)
{
var bZero = this.checkZEROSign(rightCode);
if(rightCode == EQUAL || bZero)
coeffRight = 0;
else if(this.checkOperSign(rightCode))
coeffRight = 0.25;
else
coeffRight = 0.5;
}
}
if(bSign && bLeftComp)
coeffLeft = coeffLeft - gapLeftComp;
if(bSign && bRightComp)
coeffRight = coeffRight - gapRightComp;
coeffLeft = Math.ceil(coeffLeft*10)/10;
coeffRight = Math.ceil(coeffRight*10)/10;
}
else if(curr.typeObj == MATH_COMP)
{
var currGaps = this.getGapsMComp(curr);
if(bLeft)
{
coeffLeft = currGaps.left;
if(bLeftComp)
{
if(gapLeftComp/2 < coeffLeft)
coeffLeft = gapLeftComp/2;
}
}
if(bRight)
{
coeffRight = currGaps.right;
if(bRightComp)
{
if(coeffRight/2 > gapRightComp )
coeffRight -= gapRightComp;
else
coeffRight /=2;
}
}
}
if(bLeftText)
{
if(leftCode == 0x28 || leftCode == 0x5B || leftCode == 0x7B)
coeffLeft = 0;
}
if(bRightText)
{
if(rightCode == 0x29 || rightCode == 0x5D || rightCode == 0x7D)
coeffRight = 0;
}
var runPrp = this.getRunPrp(posCurr);
var oWPrp = runPrp.getMergedWPrp();
this.applyArgSize(oWPrp);
var gapSign = 0.1513*oWPrp.FontSize;
this.content[posCurr].gaps.left = Math.ceil(coeffLeft*gapSign*10)/10; // если ни один случай не выполнился, выставляем "нулевые" gaps (default): необходимо, если что-то удалили и объект стал первый или последним в контенте
this.content[posCurr].gaps.right = Math.ceil(coeffRight*gapSign*10)/10;
/*if(this.bRoot)
{
if(bSign)
{
var code = this.content[posCurr].value.getCodeChr();
console.log(" " + String.fromCharCode(code));
}
else if(curr.typeObj == MATH_COMP)
{
console.log(curr.constructor.name + " :")
}
if(bSign || curr.typeObj == MATH_COMP)
{
console.log("coeff left " + coeffLeft + ", coeff right " + coeffRight );
console.log("gap left : " + this.content[posCurr].gaps.left + ", gap right : " + this.content[posCurr].gaps.right);
console.log("");
}
}*/
}
},
setGaps: function()
{
if(this.argSize < 0)
{
this.Current.GapLeft = 0;
if(this.Left !== null)
this.Left.GapRight = 0;
}
else
{
var currCoeff = 0,
rightCoeff = 0;
if(this.Current.typeObj == MATH_TEXT)
{
var currCode = this.Current.getCodeChr();
if(this.Left !== null)
{
if(this.Left.typeObj == MATH_COMP)
{
rightCoeff = this.getGapsMComp(this.Left, 1);
currCoeff = COEFF_GAPS.getCoeff(currCode, -1, -1);
currCoeff -= rightCoeff;
}
else
{
var leftCode = this.Left.getCodeChr();
currCoeff = COEFF_GAPS.getCoeff(currCode, leftCode, -1);
rightCoeff = COEFF_GAPS.getCoeff(leftCode, currCode, 1);
}
}
else
this.Current.GapLeft = 0;
}
else
{
currCoeff = this.getGapsMComp(this.Current, -1);
if(this.Left != null)
{
if(this.Left.typeObj == MATH_COMP)
{
rightCoeff = this.getGapsMComp(this.Left, 1);
if(rightCoeff/2 > currCoeff)
rightCoeff -= currCoeff;
else
rightCoeff /= 2;
if(currCoeff < rightCoeff/2)
{
currCoeff = rightCoeff/2;
}
}
else
{
rightCoeff -= currCoeff;
}
}
else
currCoeff = 0;
}
currCoeff = Math.ceil(currCoeff*10)/10;
rightCoeff = Math.ceil(rightCoeff*10)/10;
var LGapSign = 0.1513*this.currRunPrp.FontSize;
this.Current.GapLeft = Math.ceil(currCoeff*LGapSign*10)/10; // если ни один случай не выполнился, выставляем "нулевые" gaps (default): необходимо, если что-то удалили и объект стал первый или последним в контенте
if(this.Left != null)
{
var RGapSign = 0.1513*this.leftRunPrp.FontSize;
this.Left.GapRight = Math.ceil(rightCoeff*RGapSign*10)/10;
}
}
},
getGapsMComp: function(MComp, direct)
{
var kind = MComp.kind;
var checkGap = this.checkGapKind(kind);
var bNeedGap = !checkGap.bEmptyGaps && !checkGap.bChildGaps;
var coeffLeft = 0.001,
coeffRight = 0; // for checkGap.bEmptyGaps
//var bDegree = kind == MATH_DEGREE || kind == MATH_DEGREESubSup;
var bDegree = kind == MATH_DEGREE;
if(checkGap.bChildGaps)
{
if(bDegree)
{
coeffLeft = 0.03;
if(MComp.IsPlhIterator())
coeffRight = 0.12;
else
coeffRight = 0.16;
}
var gapsChild = MComp.getGapsInside(this);
coeffLeft = coeffLeft < gapsChild.left ? gapsChild.left : coeffLeft;
coeffRight = coeffRight < gapsChild.right ? gapsChild.right : coeffRight;
}
else if(bNeedGap)
{
coeffLeft = 0.4;
coeffRight = 0.3;
}
var result = direct == -1 ? coeffLeft : coeffRight;
return result;
},
checkGapKind: function(kind)
{
var bEmptyGaps = kind == MATH_DELIMITER || kind == MATH_MATRIX,
bChildGaps = kind == MATH_DEGREE || kind == MATH_DEGREESubSup || kind == MATH_ACCENT || kind == MATH_RADICAL|| kind == MATH_BOX || kind == MATH_BORDER_BOX;
return {bEmptyGaps: bEmptyGaps, bChildGaps: bChildGaps};
}
}
function dist(_left, _right, _top, _bottom)
{
this.left = _left;
......@@ -401,7 +872,6 @@ function CMathContent()
center: 0
};
this.init();
// Добавляем данный класс в таблицу Id (обязательно в конце конструктора)
g_oTableId.Add( this, this.Id );
......@@ -410,7 +880,7 @@ CMathContent.prototype =
{
init: function()
{
this.content.push( new mathElem(new CEmpty(), new dist(0,0,0,0), 0) );
},
setArgSize: function(argSize)
{
......@@ -421,6 +891,7 @@ CMathContent.prototype =
// складываем здесь, чтобы не потерять собственные настройки argSize: при добавлении в итератор формулы из меню; при добавлении готовых формул, когда есть вложенность формул с итераторами
// не будет работать при копиравнии в случае, если argSize будет отличатся от нуля для копируемой части контента
// поэтому при копировании свойство argSize не учитываем (копируем только массив элекентов вместе с Run Properties)
var val = this.argSize + argSize;
if(val < -2)
......@@ -681,7 +1152,7 @@ CMathContent.prototype =
return mathElem; // for finished equation
},
addElementToContent: function(obj) //for "read"
old_addElementToContent: function(obj) //for "read"
{
var element = new mathElem(obj);
//obj.relate(this);
......@@ -702,6 +1173,34 @@ CMathContent.prototype =
obj.setArgSize(this.argSize);
},
addElementToContent: function(obj) //for "read"
{
obj.Parent = this;
if(obj.typeObj === MATH_COMP)
{
obj.setComposition(this.Composition);
obj.setArgSize(this.argSize);
if(this.content.length == 0)
{
this.content.push(new ParaRun());
this.CurPos++;
}
this.content.push(obj);
this.content.push(new ParaRun());
this.CurPos += 2;
}
else
{
this.content.push(obj);
this.CurPos++;
}
this.setLogicalPosition(this.CurPos);
},
addToContent: function(obj, shift) // for "edit", letters
{
var elem = new mathElem(obj);
......@@ -3796,7 +4295,7 @@ CMathContent.prototype =
placeholder.relate(this);
placeholder.fillPlaceholders();
this.content.push( new mathElem( placeholder ) );
this.content.push( placeholder );
},
///////// перемещение //////////
old_old_cursor_moveRight: function()
......@@ -4715,40 +5214,6 @@ CMathContent.prototype =
return content;
},
old_recalculateSize: function()
{
var _width = 0 ;
var _ascent = 0 ;
var _descent = 0 ;
var _center = 0 ;
var _height = 0 ;
for(var i=0; i< this.content.length; i++)
{
var Size = this.content[i].value.size;
var gps = this.content[i].gaps;
_width += Size.width + gps.left + gps.right;
_descent = ( _descent < ( Size.height - Size.center + gps.bottom) ) ? ( Size.height - Size.center + gps.bottom): _descent;
_center = ( _center < (Size.center + gps.top) ) ? ( Size.center + gps.top) : _center;
var sAscent;
if( !this.content[i].value.typeObj === MATH_COMP )
sAscent = Size.ascent;
else
sAscent = Size.center;
_ascent = _ascent > sAscent ? _ascent : sAscent;
}
_width += this.gaps.left + this.gaps.right;
_height = _center + _descent + this.gaps.top + this.gaps.bottom;
_center += this.gaps.top;
this.size = {width: _width, height: _height, center: _center, ascent: _ascent};
this.update_widthContent(); /// !!!!
},
recalculateSize: function()
{
var width = 0 ;
var ascent = 0 ;
......@@ -4770,523 +5235,270 @@ CMathContent.prototype =
this.update_widthContent(); /// !!!!
},
Resize: function(oMeasure) // пересчитываем всю формулу
recalculateSize: function()
{
// default для случая с плейсхолдером, RunPrp в контенте отсутствуют
var TxtSettings =
{
type: TXT_ROMAN,
lit: false
}; // default type is TXT_ROMAN (MATH Text)
//var posPrev = -1;
var width = 0 ;
var ascent = 0 ;
var descent = 0 ;
var oSize;
for(var i = 0; i < this.content.length; i++)
{
var obj = this.content[i].value,
type = obj.typeObj;
if(type == MATH_TEXT)
{
this.content[i].value.setMText(TxtSettings.type);
this.content[i].value.Resize(oMeasure);
if(TxtSettings.type !== TXT_NORMAL && TxtSettings.lit === false)
this.checkGapsSign(oMeasure, i);
}
else if(type == MATH_COMP)
{
this.content[i].value.Resize(oMeasure);
this.checkGapsSign(oMeasure, i);
}
else if(type == MATH_RUN_PRP)
{
var mergedWPrp = obj.getMergedWPrp();
var oWPrp = new CTextPr();
oWPrp.Merge(mergedWPrp);
this.applyArgSize(oWPrp); // здесь мержим с DEFAULT_RUN_PRP
TxtSettings = obj.getTxtSettings();
/*if(typeTxt == TXT_ROMAN) // MATH TEXT, наклон не меняем, если italic
oWPrp.Italic = false;*/
oMeasure.SetFont(oWPrp);
}
else if(type == MATH_PLACEHOLDER)
{
if(!this.bRoot)
{
var oWPrp = this.Parent.getCtrPrp();
/*var txtPrp = new CMathTextPrp();
txtPrp.Merge(this.Composition.DEFAULT_RUN_PRP);
txtPrp.Merge(ctrPrp);*/
this.applyArgSize(oWPrp);
oWPrp.Italic = false;
if(this.content[i].typeObj === MATH_COMP)
oSize = this.content[i].size;
else
oSize = this.content[i].Math_GetSize();
oMeasure.SetFont(oWPrp);
width += oSize.width;
this.content[i].value.Resize(oMeasure);
}
}
else if(type == MATH_PARA_RUN)
{
this.content[i].value.Math_Recalculate();
}
ascent = ascent > oSize.ascent ? ascent : oSize.ascent;
var oDescent = oSize.height - oSize.ascent;
descent = descent < oDescent ? oDescent : descent;
}
this.recalculateSize();
},
old_checkGapsSign: function(oMeasure, posLeft, posCurr)
{
if(posLeft > 0 && posLeft < this.content.length)
{
var typePrev = this.content[posLeft].value.typeObj,
typeCurr = this.content[posCurr].value.typeObj;
var bPrevSign = this.checkSignComp(posLeft),
bCurrSign = this.checkSignComp(posCurr);
var bPrevComp = typePrev === MATH_COMP,
bCurrComp = typeCurr === MATH_COMP;
var prevKind = bPrevComp ? this.content[posLeft].value.kind : null,
currKind = bCurrComp ? this.content[posCurr].value.kind : null;
var gapSign = 0;
var bNeedGap = bPrevSign || bPrevComp || bCurrSign || bCurrComp;
if(bPrevComp || bPrevSign)
{
var coeff = 0;
var oWPrp = this.getTextPrpMObj(posLeft);
this.applyArgSize(oWPrp);
gapSign = this.Composition.GetGapSign(oMeasure, oWPrp);
if(bPrevComp)
{
if(prevKind == MATH_DEGREE)
coeff = 0.15;
else if(prevKind == MATH_ACCENT || prevKind == MATH_DELIMITER || prevKind == MATH_MATRIX || prevKind == MATH_RADICAL)
{
coeff = 0;
}
else if(prevKind == MATH_BOX)
{
//TEST
/*var txtPrp = this.getTextPrpMObj(posLeft);
var wTextRPrp = this.applyArgSize(txtPrp);
oMeasure.SetFont ( wTextRPrp );
var height = g_oTextMeasurer.GetHeight();*/
var txtHeight = 2.3622*gapSign;
if(this.content[posLeft].value.size.height < txtHeight)
coeff = 0;
else
coeff = 0.2;
}
else
coeff = 0.2;
}
else if(bCurrSign)
coeff = 0.33;
else
coeff = 0.4;
this.content[posLeft].gaps.right = coeff*gapSign;
}
if(bCurrSign || bCurrComp)
{
var coeff = 0;
if(bCurrComp)
{
if(currKind == MATH_DEGREE)
coeff = 0.15;
else if(prevKind == MATH_ACCENT || prevKind == MATH_DELIMITER || prevKind == MATH_MATRIX || prevKind == MATH_RADICAL)
{
coeff = 0;
}
else if(prevKind == MATH_BOX)
{
var txtHeight = 2.3622*gapSign;
if(this.content[posLeft].value.size.height < txtHeight)
coeff = 0;
else
coeff = 0.2;
}
else
coeff = 0.3;
}
else if(bCurrSign)
coeff = 0.45;
else
coeff = 0.45;
var txtPrp = this.getTextPrpMObj(posCurr);
var wTextRPrp = this.applyArgSize(txtPrp);
gapSign = this.Composition.GetGapSign(oMeasure, wTextRPrp);
this.content[posCurr].gaps.left = coeff*gapSign;
}
}
this.size = {width: width, height: ascent + descent, ascent: ascent};
},
checkGapsSign: function(oMeasure, posCurr)
old_Resize: function(oMeasure) // пересчитываем всю формулу
{
var left = null,
right = null;
var curr = this.content[posCurr].value;
if(this.argSize < 0)
{
// выставим нулевые gaps для случая, если при копировании/вставки часть контента добавили в итератор
this.content[posCurr].gaps.left = 0;
this.content[posCurr].gaps.right = 0;
}
else
{
var EQUAL = 0x3D,
PLUS = 0x2B,
MINUS = 0x2212,
MULT = 0x2217,
LESS = 0x3C,
GREATER = 0x3E;
var t = posCurr - 1;
while( t > 0 )
{
if(this.content[t].value.typeObj == MATH_TEXT || this.content[t].value.typeObj == MATH_COMP)
{
left = this.content[t].value;
break;
}
t--;
}
t = posCurr + 1;
while( t < this.content.length )
{
if(this.content[t].value.typeObj == MATH_TEXT || this.content[t].value.typeObj == MATH_COMP)
{
right = this.content[t].value;
break;
}
t++;
}
var coeffLeft = 0,
coeffRight = 0;
var bLeft = left !== null,
bRight = right !== null;
var bLeftComp = bLeft ? left.typeObj == MATH_COMP : false,
bRightComp = bRight ? right.typeObj == MATH_COMP : false,
bLeftText = bLeft ? left.typeObj == MATH_TEXT : false,
bRightText = bRight ? right.typeObj == MATH_TEXT : false;
var currCode = curr.typeObj == MATH_TEXT ? curr.getCodeChr() : null,
leftCode = bLeftText ? left.getCodeChr() : null,
rightCode = bRightText ? right.getCodeChr() : null;
var gapLeftComp = 0,
gapRightComp = 0;
if(bLeftComp)
gapLeftComp = this.getGapsMComp(left).right;
if(bRightComp)
gapRightComp = this.getGapsMComp(right).left;
if(curr.typeObj == MATH_TEXT)
{
var bSign = false;
if(this.checkOperSign(currCode)) // plus, minus, greater, less
{
bSign = true;
if(bLeft)
{
if(this.checkZEROSign(leftCode))
coeffLeft = 0;
else if(leftCode == EQUAL)
coeffLeft = 0.26;
else
coeffLeft = 0.52;
}
// default для случая с плейсхолдером, RunPrp в контенте отсутствуют
var TxtSettings =
{
type: TXT_ROMAN,
lit: false
};
if(bRight)
{
var bZero = this.checkZEROSign(rightCode);
if(rightCode == EQUAL || bZero)
coeffRight = 0;
else
coeffRight = 0.49;
}
}
else if(currCode === MULT) // multiplication
{
bSign = true;
var RecalcInfo = new CRecalculateInfo(this.argSize, oMeasure);
if(bLeft)
{
var bZeroLeft = this.checkZEROSign(leftCode),
bOperLeft = this.checkOperSign(leftCode);
if(this.content.length > 1)
{
if(this.IsEmptyRun(0))
{
RecalcInfo.Current = this.content[1];
if(leftCode == EQUAL || bOperLeft || bZeroLeft)
coeffLeft = 0;
else if(bLeft)
coeffLeft = 0.46;
}
if(this.IsEmptyRun(2))
RecalcInfo.Right = this.content[2];
}
else
RecalcInfo.Current = this.content[0]; // right не прописываем
}
if(bRight)
{
var bZeroRight = this.checkZEROSign(rightCode),
bOperRight = this.checkOperSign(rightCode);
for(var i = 0; i < this.content.length; i++)
{
if(rightCode == EQUAL || bOperRight || bZeroRight)
coeffRight = 0;
else if(bRight)
coeffRight = 0.49;
}
if(RecalcInfo.Current.typeObj == MATH_TEXT)
{
this.content[i].setMText(TxtSettings.type);
this.content[i].Resize(oMeasure);
}
else if(currCode === EQUAL) // equal
{
bSign = true;
if(TxtSettings.type !== TXT_NORMAL && TxtSettings.lit === false)
this.checkGapsSign(oMeasure, i);
}
else if(RecalcInfo.Current.typeObj == MATH_COMP)
{
RecalcInfo.Current.Resize(oMeasure);
if(bLeft)
{
var bZero = this.checkZEROSign(leftCode);
if(leftCode == EQUAL || bZero)
coeffLeft = 0;
else if(this.checkOperSign(leftCode))
coeffLeft = 0.35;
else
coeffLeft = 0.7;
}
RecalcInfo.checkGapsSign(oMeasure);
}
else if(RecalcInfo.Current.typeObj == MATH_RUN_PRP)
{
var mergedWPrp = obj.getMergedWPrp();
var oWPrp = new CTextPr();
oWPrp.Merge(mergedWPrp);
if(bRight)
{
var bZero = this.checkZEROSign(rightCode);
if(rightCode == EQUAL || bZero)
coeffRight = 0;
else if(this.checkOperSign(rightCode))
coeffRight = 0.25;
else
coeffRight = 0.5;
}
}
this.applyArgSize(oWPrp); // здесь мержим с DEFAULT_RUN_PRP
if(bSign && bLeftComp)
coeffLeft = coeffLeft - gapLeftComp;
TxtSettings = obj.getTxtSettings();
if(bSign && bRightComp)
coeffRight = coeffRight - gapRightComp;
/*if(typeTxt == TXT_ROMAN) // MATH TEXT, наклон не меняем, если italic
oWPrp.Italic = false;*/
coeffLeft = Math.ceil(coeffLeft*10)/10;
coeffRight = Math.ceil(coeffRight*10)/10;
oMeasure.SetFont(oWPrp);
}
else if(curr.typeObj == MATH_COMP)
else if(RecalcInfo.Current.typeObj == MATH_PLACEHOLDER)
{
var currGaps = this.getGapsMComp(curr);
if(bLeft)
if(!this.bRoot)
{
coeffLeft = currGaps.left;
var oWPrp = this.Parent.getCtrPrp();
if(bLeftComp)
{
if(gapLeftComp/2 < coeffLeft)
coeffLeft = gapLeftComp/2;
}
}
if(bRight)
{
coeffRight = currGaps.right;
/*var txtPrp = new CMathTextPrp();
txtPrp.Merge(this.Composition.DEFAULT_RUN_PRP);
txtPrp.Merge(ctrPrp);*/
if(bRightComp)
{
if(coeffRight/2 > gapRightComp )
coeffRight -= gapRightComp;
else
coeffRight /=2;
}
this.applyArgSize(oWPrp);
oWPrp.Italic = false;
oMeasure.SetFont(oWPrp);
this.content[i].Resize(oMeasure);
}
}
if(bLeftText)
else if(RecalcInfo.Current.typeObj == MATH_PARA_RUN)
{
if(leftCode == 0x28 || leftCode == 0x5B || leftCode == 0x7B)
coeffLeft = 0;
RecalcInfo.Current.Math_Recalculate(RecalcInfo);
}
if(bRightText)
RecalcInfo.Left = RecalcInfo.Сurrent;
RecalcInfo.Сurrent = RecalcInfo.Right;
if( i+1 == this.content.length )
RecalcInfo.Right = null;
else if(this.IsEmptyRun(i+1))
{
if(rightCode == 0x29 || rightCode == 0x5D || rightCode == 0x7D)
coeffRight = 0;
if(i + 2 == this.content.length)
RecalcInfo.Right = null;
else
RacalcInfo.Right = this.content[i+2];
}
}
var runPrp = this.getRunPrp(posCurr);
var oWPrp = runPrp.getMergedWPrp();
this.applyArgSize(oWPrp);
this.recalculateSize();
},
Resize: function(oMeasure) // пересчитываем всю формулу
{
// default для случая с плейсхолдером, RunPrp в контенте отсутствуют
/*var TxtSettings =
{
type: TXT_ROMAN,
lit: false
};*/
var gapSign = 0.1513*oWPrp.FontSize;
var RecalcInfo = new CRecalculateInfo(oMeasure, this.argSize, this.Composition);
this.content[posCurr].gaps.left = Math.ceil(coeffLeft*gapSign*10)/10; // если ни один случай не выполнился, выставляем "нулевые" gaps (default): необходимо, если что-то удалили и объект стал первый или последним в контенте
this.content[posCurr].gaps.right = Math.ceil(coeffRight*gapSign*10)/10;
/*if(this.content.length > 1)
{
if(this.IsEmptyRun(0))
{
RecalcInfo.Current = this.content[1];
/*if(this.bRoot)
{
if(bSign)
{
var code = this.content[posCurr].value.getCodeChr();
console.log(" " + String.fromCharCode(code));
}
else if(curr.typeObj == MATH_COMP)
{
console.log(curr.constructor.name + " :")
}
if(this.IsEmptyRun(2))
RecalcInfo.Right = this.content[2];
}
else
RecalcInfo.Current = this.content[0]; // right не прописываем
}*/
if(bSign || curr.typeObj == MATH_COMP)
{
console.log("coeff left " + coeffLeft + ", coeff right " + coeffRight );
console.log("gap left : " + this.content[posCurr].gaps.left + ", gap right : " + this.content[posCurr].gaps.right);
console.log("");
}
}*/
}
for(var pos = 0; pos < this.content.length; pos++)
{
if(this.content[pos].typeObj == MATH_COMP)
{
this.content[pos].Resize(oMeasure);
},
getGapsMComp: function(MComp)
{
var kind = MComp.kind;
var checkGap = this.checkGapKind(kind);
RecalcInfo.Left = RecalcInfo.Current;
RecalcInfo.leftRunPrp = RecalcInfo.currRunPrp;
var bNeedGap = !checkGap.bEmptyGaps && !checkGap.bChildGaps;
RecalcInfo.Current = this.content[pos];
var coeffLeft = 0.001,
coeffRight = 0; // for checkGap.bEmptyGaps
//var currRPrp = this.content[pos].getRunPrp();
//var bDegree = kind == MATH_DEGREE || kind == MATH_DEGREESubSup;
var bDegree = kind == MATH_DEGREE;
var runPrp =this.content[pos].getRunPrp();
var currRPrp = runPrp.getMergedWPrp();
this.applyArgSize(currRPrp);
if(checkGap.bChildGaps)
{
if(bDegree)
RecalcInfo.currRunPrp = currRPrp;
RecalcInfo.setGaps();
}
else if(this.content[pos].typeObj == MATH_PLACEHOLDER)
{
coeffLeft = 0.03;
if(!this.bRoot)
{
var oWPrp = this.Parent.getCtrPrp();
if(MComp.IsPlhIterator())
coeffRight = 0.12;
else
coeffRight = 0.16;
this.applyArgSize(oWPrp);
oWPrp.Italic = false;
oMeasure.SetFont(oWPrp);
this.content[pos].Resize(oMeasure);
}
}
else if(this.content[pos].typeObj == MATH_PARA_RUN)
{
this.content[pos].Math_Recalculate(RecalcInfo);
}
var gapsChild = MComp.getGapsInside();
/*RecalcInfo.Left = RecalcInfo.Сurrent;
RecalcInfo.Сurrent = RecalcInfo.Right;*/
coeffLeft = coeffLeft < gapsChild.left ? gapsChild.left : coeffLeft;
coeffRight = coeffRight < gapsChild.right ? gapsChild.right : coeffRight;
}
else if(bNeedGap)
{
coeffLeft = 0.4;
//coeffRight = 0.26;
coeffRight = 0.3;
/*if( pos+1 == this.content.length )
RecalcInfo.Right = null;
else if(this.IsEmptyRun(pos+1))
{
if(pos+2 == this.content.length)
RecalcInfo.Right = null;
else
RecalcInfo.Right = this.content[pos+2];
}
else
pos++;*/
}
return {left: coeffLeft, right: coeffRight};
if(RecalcInfo.Current !== null)
RecalcInfo.Current.GapRight = 0;
this.recalculateSize();
},
getGapsInside: function() // учитываем gaps внутренних объектов
IsEmptyRun: function(pos) // пустой Para_Run
{
var typeFirst = this.content.length > 1 ? this.content[1].value.typeObj : null;
var result = false;
var bFirstComp = typeFirst == MATH_COMP,
if(pos < this.content.length)
result = this.content[pos].typeObj !== MATH_COMP && this.content[pos].Is_Empty();
return result;
},
getGapsInside: function(RecalcInfo) // учитываем gaps внутренних объектов
{
var gaps = {left: 0, right: 0};
var bFirstComp = false,
bLastComp = false;
var posLComp = -1;
var len = this.content.length;
if( this.content.length > 1 )
if(len > 1)
{
posLComp = this.content.length - 2;
bLastComp = this.content[posLComp].value.typeObj == MATH_COMP;
}
var bFRunEmpty = this.content[0].Is_Empty();
bFirstComp = bFRunEmpty && this.content[1].typeObj == MATH_COMP; // первый всегда идет Run
var gaps = {left: 0, right: 0};
var bLastRunEmpty = this.content[len - 1].Is_Empty(); // т.к. после мат. объекта стоит пустой Run
bLastComp = bLastRunEmpty && this.content[len - 2].typeObj == MATH_COMP;
}
var checkGap;
if(bFirstComp)
{
checkGap = this.checkGapKind(this.content[0].value.kind);
checkGap = RecalcInfo.checkGapKind(this.content[1].kind);
if(!checkGap.bChildGaps)
{
var gapsMComp = this.getGapsMComp(this.content[0].value);
gaps.left = gapsMComp.left;
}
if(!checkGap.bChildGaps)
{
var gapsMComp = RecalcInfo.getGapsMComp(this.content[1]);
gaps.left = gapsMComp.left;
}
}
if(bLastComp)
{
checkGap = this.checkGapKind(this.content[posLComp].value.kind);
checkGap = RecalcInfo.checkGapKind(this.content[len - 1].kind);
if(!checkGap.bChildGaps)
{
var gapsMComp = this.getGapsMComp(this.content[0].value);
var gapsMComp = RecalcInfo.getGapsMComp(this.content[len - 1]);
gaps.right = gapsMComp.right;
}
}
return gaps;
},
checkGapKind: function(kind)
{
var bEmptyGaps = kind == MATH_DELIMITER || kind == MATH_MATRIX,
bChildGaps = kind == MATH_DEGREE || kind == MATH_DEGREESubSup || kind == MATH_ACCENT || kind == MATH_RADICAL|| kind == MATH_BOX || kind == MATH_BORDER_BOX;
return {bEmptyGaps: bEmptyGaps, bChildGaps: bChildGaps};
},
checkZEROSign: function(code) // "*", "/", "\"
{
var MULT = 0x2217,
DIVISION = 0x2F,
B_SLASH = 0x5C;
return code == MULT || code == DIVISION || code == B_SLASH;
},
checkOperSign: function(code) // "+", "-", "<", ">", "±"
{
var PLUS = 0x2B,
MINUS = 0x2212,
LESS = 0x3C,
GREATER = 0x3E,
PLUS_MINUS = 0xB1;
return code == PLUS || code == MINUS || code == LESS || code == GREATER || code == PLUS_MINUS;;
},
IsOnlyText: function()
{
var bOnlyText = true;
for(var i = 0; i < this.content.length; i++)
{
if(this.content[i].value.typeObj == MATH_COMP)
if(this.content[i].typeObj == MATH_COMP)
{
bOnlyText = false;
break;
......@@ -5346,7 +5558,7 @@ CMathContent.prototype =
{
for(var i=0; i < this.content.length;i++)
{
if(this.content[i].value.typeObj == MATH_RUN_PRP)
if(this.content[i].typeObj == MATH_RUN_PRP)
{
pGraphics.b_color1(0,0,0,255);
var mgWPrp = this.content[i].value.getMergedWPrp();
......@@ -5357,7 +5569,7 @@ CMathContent.prototype =
pGraphics.SetFont(oWPrp);
}
else if(this.content[i].value.typeObj == MATH_PLACEHOLDER)
else if(this.content[i].typeObj == MATH_PLACEHOLDER)
{
pGraphics.b_color1(0,0,0,255);
......@@ -5373,15 +5585,12 @@ CMathContent.prototype =
oWPrp.Italic = false;
pGraphics.SetFont(oWPrp);
this.content[i].value.draw(x, y, pGraphics);
}
else if(this.content[i].value.typeObj == MATH_PARA_RUN)
{
var PSDE = {X: x, Y: y, Graphics: pGraphics};
this.content[i].value.Math_Draw(x, y, pGraphics);
this.content[i].draw(x, y, pGraphics);
}
else
this.content[i].value.draw(x, y, pGraphics);
else if(this.content[i].typeObj == MATH_COMP)
this.content[i].draw(x, y, pGraphics);
else // MATH_PARA_RUN
this.content[i].Math_Draw(x, y, pGraphics);
/*if(this.content[i].value.typeObj == MATH_COMP)
{
......@@ -5430,7 +5639,7 @@ CMathContent.prototype =
{
for(var i = 1; i <this.content.length; i++)
{
this.content[i].widthToEl = this.content[i-1].widthToEl + this.content[i].value.size.width + this.content[i].gaps.left + this.content[i].gaps.right;
this.content[i].widthToEl = this.content[i-1].widthToEl + this.content[i].value.size.width + this.content[i].GapLeft + this.content[i].GapRight;
}
},
old_update_Cursor: function()
......@@ -6191,14 +6400,19 @@ CMathContent.prototype =
for(var i=0; i < this.content.length; i++)
{
_pos.x += this.content[i].gaps.left;
if(this.content[i].value.typeObj == MATH_PARA_RUN)
this.content[i].value.Math_SetPosition(_pos);
if(this.content[i].typeObj == MATH_COMP)
{
_pos.x += this.content[i].GapLeft;
this.content[i].setPosition(_pos);
_pos.x += this.content[i].size.width + this.content[i].GapRight;
}
else
this.content[i].value.setPosition(_pos);
{
this.content[i].Math_SetPosition(_pos);
_pos.x += this.content[i].Math_GetSize().width;
}
_pos.x += this.content[i].value.size.width;
}
},
old_drawSelect: function()
......@@ -6387,7 +6601,7 @@ CMathContent.prototype =
if(this.content.length > 1)
{
var obj = this.content[1].value;
var obj = this.content[1];
if(obj.typeObj === MATH_RUN_PRP) // если первый объект - буква
{
rPrp.Merge(obj);
......@@ -8237,7 +8451,7 @@ CMathComposition.prototype =
//////////////* end of test functions *//////////////////
Init: function()
{
{
this.Root = new CMathContent();
//this.Root.gaps = gps;
this.Root.setComposition(this);
......
......@@ -58,6 +58,9 @@ function CMathText()
this.bJDraw = false;
this.type = TXT_ROMAN;
this.GapLeft = 0;
this.GapRight = 0;
//this.Parent = null;
/*this.TxtPrp = new CMathTextPrp();
......@@ -65,6 +68,10 @@ function CMathText()
//this.sizeSymbol = null; // размер символа без учета трансформации
// TO DO
// убрать
this.transform =
{
sx: 1,
......@@ -99,8 +106,6 @@ CMathText.prototype =
if(this.type == TXT_ROMAN )
{
var bDigit = (code > 0x002F && code < 0x003A),
bCapGreek = (code > 0x0390 && code < 0x03AA ),
bSmallGreek = (code > 0x03B0 && code < 0x03CA);
......@@ -248,6 +253,8 @@ CMathText.prototype =
var widthG = metricsTxt.WidthG;
width += this.GapLeft + this.GapRight;
this.size = {width: width, widthG: widthG, height: height, ascent: ascent};
},
old_draw: function()
......
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