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

1. Испавила отрисовку дроби (черта дроби находится на уровне "-") для всех...

1. Испавила отрисовку дроби (черта дроби находится на уровне "-") для всех размеров шрифта (теперь центр дроби всегда отрисовывается как в Ворде)
2. Сделала подмену "-" и "*" на этапе добавление код символа в CMathText (для чтения)
2. Center => Baseline
degree
degreeSubSup
n-ary SubSup
3. Удалила gap для контента, и соответственно coordWOGaps


git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@53431 954022d7-b5bf-4e40-9824-e11837661b57
parent 5fdce5ad
......@@ -606,7 +606,8 @@ CSign.prototype.fixSize = function(oMeasure, stretch, bIncline)
var ctrPrp = this.Parent.getCtrPrp();
var rPrp = new CMathTextPrp();
rPrp.Merge(DEFAULT_RUN_PRP);
var defaultRPrp = this.Parent.Composition.DEFAULT_RUN_PRP;
rPrp.Merge(defaultRPrp);
rPrp.Merge(ctrPrp);
rPrp.Italic = false;
......
......@@ -93,7 +93,7 @@ CMathBase.prototype =
getCtrPrp: function()
{
var ctrPrp = new CTextPr();
ctrPrp.Merge(DEFAULT_RUN_PRP);
ctrPrp.Merge(this.Composition.DEFAULT_RUN_PRP);
ctrPrp.Merge(this.Composition.GetFirstPrp() );
ctrPrp.Merge(this.CtrPrp);
return ctrPrp;
......@@ -101,11 +101,18 @@ CMathBase.prototype =
getCtrPrpForFirst: function()
{
var ctrPrp = new CTextPr();
ctrPrp.Merge(DEFAULT_RUN_PRP);
ctrPrp.Merge(this.Composition.DEFAULT_RUN_PRP);
ctrPrp.Merge(this.CtrPrp);
return ctrPrp;
},
getShiftCenter: function(oMeasure, font)
{
oMeasure.SetFont(font);
var metrics = oMeasure.Measure2Code(8727); // "+"
return 0.6*metrics.Height;
},
// для управляющих символов в приоритете GetFirstPrp
// если первый элемент - мат объект, то берутся его CtrPrp
getPrpToControlLetter: function()
......@@ -881,7 +888,7 @@ CMathBase.prototype =
for(var j = 0; j < this.nCol; j++)
this.elements[i][j].Resize(oMeasure);
this.recalculateSize();
this.recalculateSize(oMeasure); // передаем oMeasure, для
},
old_getCenter: function(_height)
{
......@@ -987,10 +994,6 @@ CMathBase.prototype =
var content = this.elements[pos.X][pos.Y].getContent(stack, bCurrent);
return content;
},
setTypeElement: function(type)
{
this.typeElement = type;
},
//// For Edit /////
selection_Start: function(x, y)
......
......@@ -20,9 +20,6 @@ CDegree.prototype.init = function(props)
}
CDegree.prototype.init_2 = function(props, oBase)
{
/*if( typeof(props.type)!=="undefined"|| props.type !== null)
this.type = props.type;*/
if(props.type === DEGREE_SUPERSCRIPT)
this.type = DEGREE_SUPERSCRIPT;
else if(props.type === DEGREE_SUBSCRIPT)
......@@ -35,14 +32,14 @@ CDegree.prototype.init_2 = function(props, oBase)
this.addMCToContent(oBase, oDegree);
}
CDegree.prototype.recalculateSize = function()
CDegree.prototype.recalculateSize = function(oMeasure)
{
if(this.type === DEGREE_SUPERSCRIPT)
this.recalculateSup();
this.recalculateSup(oMeasure);
else if(this.type === DEGREE_SUBSCRIPT)
this.recalculateSubScript();
this.recalculateSubScript(oMeasure);
}
CDegree.prototype.recalculateSup = function()
CDegree.prototype.recalculateSup = function(oMeasure)
{
var base = this.elements[0][0].size,
iter = this.elements[0][1].size;
......@@ -53,18 +50,19 @@ CDegree.prototype.recalculateSup = function()
ascent = 0;
var descIter = iter.height - iter.ascent;
var FontSize = this.getCtrPrp().FontSize,
shiftCenter = DIV_CENT*FontSize;
var ctrPrp = this.getCtrPrp(); // выставить потом размер шрифта для итератора
var shCenter = this.getShiftCenter(oMeasure, ctrPrp);
var upper = 0;
if(descIter + shiftCenter > 2/3*base.height)
if(descIter + shCenter > 2/3*base.height)
{
upper = iter.height - 2/3*base.height;
}
else
{
upper = iter.ascent - shiftCenter;
upper = iter.ascent - shCenter;
}
this.upper = upper;
......@@ -82,7 +80,7 @@ CDegree.prototype.recalculateSup = function()
this.size = {width: width, height: height, ascent: ascent};
}
CDegree.prototype.recalculateSubScript = function()
CDegree.prototype.recalculateSubScript = function(oMeasure)
{
var base = this.elements[0][0].size,
iter = this.elements[0][1].size;
......@@ -91,17 +89,20 @@ CDegree.prototype.recalculateSubScript = function()
var height = 0,
ascent = 0;
var FontSize = this.getCtrPrp().FontSize,
shiftCenter = 0.5*DIV_CENT*FontSize;
/*var FontSize = this.getCtrPrp().FontSize,
shiftCenter = 0.5*DIV_CENT*FontSize;*/
var ctrPrp = this.getCtrPrp(); // выставить потом размер шрифта для итератора
var shCenter = this.getShiftCenter(oMeasure, ctrPrp);
var low = 0;
if(iter.ascent - shiftCenter > 2/3*base.height)
if(iter.ascent - shCenter > 2/3*base.height)
{
low = iter.height - 2/3*base.height;
}
else
{
low = iter.height - iter.ascent + shiftCenter;
low = iter.height - iter.ascent + shCenter;
}
height = base.height + low;
......@@ -125,6 +126,9 @@ CDegree.prototype.old_setPosition = function(_pos)
}
CDegree.prototype.setPosition = function(pos)
{
if(this.bMObjs === true)
this.pos = pos;
else
this.pos = {x: pos.x, y: pos.y - this.size.ascent};
var shBase = 0,
......@@ -292,6 +296,7 @@ CDegree.prototype.getPropsForWrite = function()
function CIterators()
{
this.upper = 0;
CMathBase.call(this);
}
extend(CIterators, CMathBase);
......@@ -300,34 +305,62 @@ CIterators.prototype.init = function()
this.setDimension(2, 1);
this.setContent();
}
CIterators.prototype.setDistance = function()
CIterators.prototype.setDistanceIters = function(oMeasure)
{
var descF = this.elements[0][0].size.height - this.elements[0][0].size.center ,
ascS = this.elements[1][0].size.center ;
/*var descF = this.elements[0][0].size.height - this.elements[0][0].size.center ,
ascS = this.elements[1][0].size.center;*/
var upIter = this.elements[0][0].size,
lowIter = this.elements[1][0].size;
/*var FontSize = this.getCtrPrp().FontSize,
shCent = DIV_CENT*FontSize;*/
var ctrPrp = this.getCtrPrp();
var shCenter = this.getShiftCenter(oMeasure, ctrPrp);
var upDesc = upIter.height - upIter.ascent + shCenter,
lowAsc = lowIter.ascent - shCenter;
var up = 0;
var down = 0;
if(this.lUp > descF)
up = this.lUp - descF;
if( this.lD > ascS )
down = this.lD - ascS;
if(this.lUp > upDesc)
{
up = this.lUp - upDesc;
this.upper = upIter.height - upDesc;
}
else
{
up = 0;
this.upper = upIter.height - this.lUp;
}
if( this.lD > lowAsc )
down = this.lD - lowAsc;
this.dH = up + down;
this.dW = 0;
}
CIterators.prototype.getCenter = function()
/*CIterators.prototype.getAscent = function()
{
var center = 0;
var descF = this.elements[0][0].size.height - this.elements[0][0].size.center;
var ascent = 0;
var upIter = this.elements[0][0].size;
*//*var FontSize = this.getCtrPrp().FontSize,
shCent = DIV_CENT*FontSize;*//*
var shCenter = this.getShiftCenter();
if( this.lUp > descF )
center = this.elements[0][0].size.center + this.lUp;
var upDesc = upIter.height - upIter.ascent + shCent;
if(this.lUp > upDesc)
ascent = upIter.height - upDesc + this.lUp;
else
center = this.elements[0][0].size.height;
ascent = upIter.height + shCent;
return center;
}
return ascent;
}*/
CIterators.prototype.getUpperIterator = function()
{
return this.elements[0][0];
......@@ -396,24 +429,80 @@ CDegreeSubSup.prototype.init_2 = function(props, oBase)
}
}
CDegreeSubSup.prototype.recalculateSize = function()
CDegreeSubSup.prototype.recalculateSize = function(oMeasure)
{
var ctrPrp = this.getCtrPrp();
var shCenter = this.getShiftCenter(oMeasure, ctrPrp);
var width = 0, height = 0,
ascent = 0;
var iters, base;
if(this.type == DEGREE_SubSup)
{
this.elements[0][1].lUp = this.elements[0][0].size.center;
this.elements[0][1].lD = this.elements[0][0].size.height - this.elements[0][0].size.center;
this.elements[0][1].setDistance();
this.elements[0][1].recalculateSize();
iters = this.elements[0][1];
base = this.elements[0][0];
}
else if(this.type == DEGREE_PreSubSup)
{
this.elements[0][0].lUp = this.elements[0][1].size.center;
iters = this.elements[0][0];
base = this.elements[0][1];
/*this.elements[0][0].lUp = this.elements[0][1].size.center;
this.elements[0][0].lD = this.elements[0][1].size.height - this.elements[0][1].size.center;
this.elements[0][0].setDistance();
this.elements[0][0].recalculateSize();
this.elements[0][0].recalculateSize();*/
}
iters.lUp = base.size.ascent - shCenter;
iters.lD = base.size.height - iters.lUp;
iters.setDistanceIters(oMeasure);
iters.recalculateSize();
width = iters.size.width + base.size.width;
//height = shCenter + iters.lUp;
height = iters.size.height;
ascent = iters.upper + base.size.ascent;
this.size = {width: width, height: height, ascent: ascent};
//CSubMathBase.superclass.recalculateSize.call(this);
}
CDegreeSubSup.prototype.old_setPosition = function(pos)
{
this.pos = {x: pos.x, y: pos.y - this.size.ascent};
if(this.type == DEGREE_SubSup)
{
var iters = this.elements[0][1],
base = this.elements[0][0];
var posBase = {x: this.pos.x, y: this.pos.y + iters.upper},
posIters = {x: this.pos.x + base.size.width, y: this.pos.y};
base.setPosition(posBase);
iters.setPosition(posIters);
}
}
CDegreeSubSup.prototype.align = function(x, y)
{
var _x = 0, _y = 0;
if(this.type == DEGREE_SubSup)
{
if(x == 0 && y == 0)
_y = this.elements[0][1].upper;
}
else
{
if(x == 0 && y == 1)
_y = this.elements[0][0].upper;
}
CSubMathBase.superclass.recalculateSize.call(this);
return {x: _x, y: _y};
}
CDegreeSubSup.prototype.getBase = function()
{
......
......@@ -89,7 +89,26 @@ CFraction.prototype.drawBarFraction = function(x, y, pGraphics)
var x1 = this.pos.x + x ,
x2 = this.pos.x + x + this.size.width,
y1 = this.pos.y + y + numHeight - penW/2;
y1 = this.pos.y + y + numHeight- penW;
/*var xx1 = x1, yy1 = this.pos.y + y,
xx2 = xx1 + this.size.width, yy2 = yy1 + this.elements[0][0].size.height;
var xxx1 = x1, yyy1 = this.pos.y + y + this.elements[0][0].size.height,
xxx2 = xxx1 + this.size.width, yyy2 = yyy1 + this.elements[1][0].size.height;
pGraphics.p_color(255,0,0, 255);
pGraphics.drawHorLine(0, yy1, xx1, xx2, 0.1);
pGraphics.drawVerLine(0, xx2, yy1, yy2, 0.1);
pGraphics.drawHorLine(0, yy2, xx1, xx2, 0.1);
pGraphics.drawVerLine(0, xx1, yy1, yy2, 0.1);
pGraphics.p_color(0,255,0, 255);
pGraphics.drawHorLine(0, yyy1, xxx1, xxx2, 0.1);
pGraphics.drawVerLine(0, xxx2, yyy1, yyy2, 0.1);
pGraphics.drawHorLine(0, yyy2, xxx1, xxx2, 0.1);
pGraphics.drawVerLine(0, xxx1, yyy1, yyy2, 0.1);*/
if( !this.bHideBar )
{
......@@ -240,34 +259,36 @@ CFraction.prototype.getDenominator = function()
return denominator;
}
CFraction.prototype.recalculateSize = function()
CFraction.prototype.recalculateSize = function(oMeasure)
{
if(this.type == BAR_FRACTION || this.type == NO_BAR_FRACTION)
this.recalculateBarFraction();
this.recalculateBarFraction(oMeasure);
else if(this.type == SKEWED_FRACTION)
this.recalculateSkewed();
this.recalculateSkewed(oMeasure);
else if(this.type == LINEAR_FRACTION)
this.recalculateLinear();
this.recalculateLinear(oMeasure);
}
CFraction.prototype.recalculateBarFraction = function()
CFraction.prototype.recalculateBarFraction = function(oMeasure)
{
var num = this.elements[0][0].size,
den = this.elements[1][0].size;
var ctrPrp = this.getCtrPrp();
var width = num.width > den.width ? num.width : den.width;
var height = num.height + den.height;
var shCenter = DIV_CENT*this.getCtrPrp().FontSize;
var ascent = num.height + shCenter;
var ascent = num.height + this.getShiftCenter(oMeasure, ctrPrp);
//var ascent = num.height;
this.size = {width: width, height: height, ascent: ascent};
}
CFraction.prototype.recalculateSkewed = function()
CFraction.prototype.recalculateSkewed = function(oMeasure)
{
var ctrPrp = this.getCtrPrp();
this.gapSlash = 5.011235894097222 * ctrPrp.FontSize/36;
var _width = this.elements[0][0].size.width + this.gapSlash + 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 + ctrPrp.FontSize*DIV_CENT;
var _ascent = this.elements[0][0].size.height + this.getShiftCenter(oMeasure, ctrPrp);
this.size = {width: _width, height: _height, ascent: _ascent};
}
......
......@@ -29,6 +29,8 @@
// 10. Поправить баги для CAccent с точками : смещение, когда идут подряд с одной точкой, двумя и тремя они перекрываются
// 11. Для управляющих символов запрашивать не getCtrPrp, getPrpToControlLetter (реализована, нужно только протащить для всех управляющих элементов)
// 12. объединение формул на remove и add
// 13. Для N-арных операторов в случае со степенью : итераторы занимают не 2/3 от основание, а примерно половину (когда один итератор сверху или снизу)
// 14. Для дробей, n-арных операторов и пр. считать расстояние исходя из shiftCenter
// TODO Refactoring
......@@ -51,7 +53,7 @@ var SELECT_PARENT = 0;
var SELECT_CHILD = 1;
var DEFAULT_RUN_PRP =
/*var DEFAULT_RUN_PRP =
{
FontFamily: {Name : "Cambria Math", Index : -1 },
FontSize: 11,
......@@ -59,7 +61,8 @@ var DEFAULT_RUN_PRP =
Bold: false,
RFonts: {},
Lang: {}
};
};*/
var StartTextElement = 0x2B1A; // Cambria Math
function dist(_left, _right, _top, _bottom)
......@@ -525,7 +528,6 @@ CMathContent.prototype =
//l_gap = r_gap = Math.floor( this.font.FontSize / 5 )*g_dKoef_pix_to_mm;
mathElem.relate(this);
mathElem.setTypeElement(ind);
//mathElem.setComposition(this.Composition);
var ctrPrp = new CTextPr();
......@@ -544,7 +546,7 @@ CMathContent.prototype =
}
else //на всякий случай
{
ctrPrp.Merge(DEFAULT_RUN_PRP);
ctrPrp.Merge(this.Composition.DEFAULT_RUN_PRP);
}
mathElem.setCtrPrp(ctrPrp);
......@@ -4659,7 +4661,7 @@ CMathContent.prototype =
var runPrp = this.content[i].value.getWRunPrp();
var txtPrp = new CMathTextPrp();
txtPrp.Merge(DEFAULT_RUN_PRP);
txtPrp.Merge(this.Composition.DEFAULT_RUN_PRP);
txtPrp.Merge(runPrp);
bItalic = txtPrp.Italic;
txtPrp.Italic = false;
......@@ -4673,7 +4675,7 @@ CMathContent.prototype =
var ctrPrp = this.Parent.getCtrPrp();
var txtPrp = new CMathTextPrp();
txtPrp.Merge(DEFAULT_RUN_PRP);
txtPrp.Merge(this.Composition.DEFAULT_RUN_PRP);
txtPrp.Merge(ctrPrp);
txtPrp.Italic = false;
......@@ -4699,7 +4701,7 @@ CMathContent.prototype =
pGraphics.b_color1(0,0,0,255);
var rPrp = new CMathTextPrp();
rPrp.Merge(DEFAULT_RUN_PRP);
rPrp.Merge(this.Composition.DEFAULT_RUN_PRP);
rPrp.Merge( this.content[i].value.getWRunPrp() );
rPrp.Italic = false;
......@@ -4712,7 +4714,7 @@ CMathContent.prototype =
var ctrPrp = this.Parent.getCtrPrp();
var rPrp = new CMathTextPrp();
rPrp.Merge(DEFAULT_RUN_PRP);
rPrp.Merge(this.Composition.DEFAULT_RUN_PRP);
rPrp.Merge(ctrPrp);
rPrp.Italic = false;
......@@ -4738,7 +4740,7 @@ CMathContent.prototype =
pGraphics.b_color1(0,0,0,255);
var rPrp = new CMathTextPrp();
rPrp.Merge(DEFAULT_RUN_PRP);
rPrp.Merge(this.Composition.DEFAULT_RUN_PRP);
rPrp.Merge( this.content[i].value.getWRunPrp() );
rPrp.Italic = false;
......@@ -4751,7 +4753,7 @@ CMathContent.prototype =
var ctrPrp = this.Parent.getCtrPrp();
var rPrp = new CMathTextPrp();
rPrp.Merge(DEFAULT_RUN_PRP);
rPrp.Merge(this.Composition.DEFAULT_RUN_PRP);
rPrp.Merge(ctrPrp);
rPrp.Italic = false;
......@@ -4776,7 +4778,7 @@ CMathContent.prototype =
//var sizeCursor = this.getRunPrp(this.CurPos).FontSize*g_dKoef_pt_to_mm;
var rPrp = new CMathTextPrp();
rPrp.Merge(DEFAULT_RUN_PRP);
rPrp.Merge(this.Composition.DEFAULT_RUN_PRP);
rPrp.Merge(this.getCurrRunPrp());
var absPos = this.Composition.absPos;
......@@ -5646,7 +5648,7 @@ CMathContent.prototype =
getFirstPrp: function()
{
var txtPrp = new CMathTextPrp();
txtPrp.Merge(DEFAULT_RUN_PRP);
txtPrp.Merge(this.Composition.DEFAULT_RUN_PRP);
if(this.content.length > 1)
{
......@@ -5733,7 +5735,7 @@ CMathContent.prototype =
else if(this.content[this.CurPos - 2].value.typeObj == MATH_COMP)
rPrp = this.content[this.CurPos - 2].value.getCtrPrp();
else // на всякий случай
rPrp = DEFAULT_RUN_PRP;
rPrp = this.Composition.DEFAULT_RUN_PRP;
this.addRunPrp(rPrp);
}
......@@ -6435,10 +6437,10 @@ function CMathComposition()
this.CurrentContent = null;
this.SelectContent = null;
this.DefaultTxtPrp =
this.DEFAULT_RUN_PRP =
{
FontFamily: {Name : "Cambria Math", Index : -1 },
FontSize: 36,
FontSize: 11,
Italic: true,
Bold: false,
RFonts: {},
......@@ -7350,3 +7352,28 @@ function TEST_UNION_CONTENT(indef)
//oCurContent.verifyRPrp_MC_2(rPr);
}
function GetShiftCenter()
{
// 1.5875 / FontSize
var txtPrp =
{
FontFamily: {Name : "Cambria Math", Index : -1 },
FontSize: 11,
Italic: true,
Bold: false,
RFonts: {},
Lang: {}
};
for(var i = 2; i < 255; i += 2)
{
txtPrp.FontSize = i;
g_oTextMeasurer.SetFont(txtPrp);
//var metricsTxt = g_oTextMeasurer.Measure2Code(StartTextElement);
var Height = g_oTextMeasurer.GetHeight();
var shift = Height / i;
//var shift = metricsTxt.Height/2 / i;
console.log(i + ": " + shift);
}
}
\ No newline at end of file
......@@ -9,7 +9,9 @@
// возвращает название шрифта
//var DIV_CENT = 0.2487852283770651;
var DIV_CENT = 0.1;
// /var DIV_CENT = 0.1;
var DIV_CENT = 0.1386;
function CMathTextPrp()
{
......@@ -76,11 +78,17 @@ CMathText.prototype =
{
add: function(code)
{
if(code == 42) // "*"
code = 8727;
else if(code == 45) // "-"
code = 8722;
this.value = code;
},
addTxt: function(txt)
{
this.value = txt.charCodeAt(0);
var code = txt.charCodeAt(0);
this.add(code);
},
getCode: function()
{
......
......@@ -2806,7 +2806,8 @@ COperator.prototype.draw = function(x, y, pGraphics)
var ctrPrp = this.getCtrPrp();
var rPrp = new CMathTextPrp();
rPrp.Merge(DEFAULT_RUN_PRP);
var defaultRPrp = this.Parent.Composition.DEFAULT_RUN_PRP;
rPrp.Merge(defaultRPrp);
rPrp.Merge(ctrPrp);
rPrp.Italic = false;
pGraphics.SetFont(rPrp);
......@@ -2871,7 +2872,8 @@ COperator.prototype.fixSize = function(oMeasure, stretch)
var ctrPrp = this.getCtrPrp();
var rPrp = new CMathTextPrp();
rPrp.Merge(DEFAULT_RUN_PRP);
var defaultRPrp = this.Parent.Composition.DEFAULT_RUN_PRP;
rPrp.Merge(defaultRPrp);
rPrp.Merge(ctrPrp);
rPrp.Italic = false;
......
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