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

matrix (new)

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@48314 954022d7-b5bf-4e40-9824-e11837661b57
parent b54b7823
......@@ -19,27 +19,6 @@ CDegreeOrdinary.prototype.init_2 = function(base)
this.addMCToContent(base, degree);
}
CDegreeOrdinary.prototype.old_setContent = function()
{
var oBase = null;
if(arguments.length > 0)
oBase = arguments[0];
else
{
oBase = new CMathContent();
oBase.init( this.params );
oBase.relate(this);
oBase.fillPlaceholders();
}
var oDegree = new CMathContent();
oDegree.init( this.params );
oDegree.relate(this);
oDegree.fillPlaceholders();
oDegree.setFont(getTypeDegree(this.params.font), -1);
CDegreeOrdinary.superclass.setContent.call(this, oBase, oDegree);
}
CDegreeOrdinary.prototype.setIndex = function(index)
{
this.index = index;
......@@ -276,39 +255,6 @@ CDegreeSubSup.prototype.init_2 = function(oBase)
this.addMCToContent(oIters, oBase);
}
}
CDegreeSubSup.prototype.old_setContent = function()
{
var oBase = null;
if(arguments.length > 0)
oBase = arguments[0];
else
{
oBase = new CMathContent();
oBase.init( this.params );
oBase.relate(this);
oBase.fillPlaceholders();
}
var oIters = new CIterators();
oIters.init( this.params );
oIters.relate(this);
oIters.fillPlaceholders();
oIters.setFont(getTypeDegree(this.params.font), -1);
oIters.lUp = 0;
oIters.lD = 0;
if(this.type == 0)
{
oIters.alignHor(-1, 0);
CDegreeSubSup.superclass.setContent.call(this, oBase, oIters);
}
else
{
oIters.alignHor(-1, 1);
CDegreeSubSup.superclass.setContent.call(this, oIters, oBase);
}
}
CDegreeSubSup.prototype.recalculateSize = function()
{
if(this.type == 0)
......
......@@ -63,30 +63,6 @@ CMinimaxFunc.prototype.init = function()
this.addMCToContent(oBase, oIter);
}
CMinimaxFunc.prototype.old_setContent = function()
{
var oBase = new CMathContent();
var GParams = Common_CopyObj(this.params);
GParams.bMText = false;
oBase.init(GParams);
oBase.relate(this);
if(this.num == 0)
oBase.addText("min");
else if(this.num == 1)
oBase.addText("max");
else
oBase.addText("lim");
var oIter = new CMathContent();
GParams = Common_CopyObj(this.params);
GParams.font = getTypeDegree(this.params.font);
oIter.init(GParams);
oIter.relate(this);
oIter.fillPlaceholders();
CMinimaxFunc.superclass.setContent.call(this, oBase, oIter);
}
CMinimaxFunc.prototype.getCenter = function()
{
return this.elements[0][0].size.center;
......@@ -128,27 +104,6 @@ CMinimax.prototype.init = function()
this.addMCToContent(oFunc, oArg);
}
CMinimax.prototype.old_setContent = function()
{
var oFunc = new CMinimaxFunc(this.num);
oFunc.init(this.params);
oFunc.relate(this);
oFunc.setContent();
var oArg = new CMathContent();
oArg.init(this.params);
oArg.relate(this);
oArg.fillPlaceholders();
CMinimax.superclass.setContent.call(this, oFunc, oArg);
}
CMinimax.prototype.old_setDistance = function()
{
//todo
//переделать !
this.dW = slashWidth(this.params.font);
this.dH = 0;
}
CMinimax.prototype.getFunction = function()
{
return this.elements[0][0].getBase();
......
......@@ -248,6 +248,9 @@ CMathContent.prototype =
case 20:
mathElem = new CStructArrow();
break;
case 21:
mathElem = new CMathMatrix();
break;
case 30:
mathElem = new CMathBase();
break;
......@@ -1752,6 +1755,256 @@ CMathContent.prototype =
var base = arrow.getBase();
base.addTxt("");
break;
case 206:
var matrix = this.createMComponent(21);
matrix.init(1, 2);
matrix.fillPlaceholders();
break;
case 207:
var matrix = this.createMComponent(21);
matrix.init(2, 1);
matrix.fillPlaceholders();
break;
case 208:
var matrix = this.createMComponent(21);
matrix.init(1, 3);
matrix.fillPlaceholders();
break;
case 209:
var matrix = this.createMComponent(21);
matrix.init(3, 1);
matrix.fillPlaceholders();
break;
case 210:
var matrix = this.createMComponent(21);
matrix.init(2, 2);
matrix.fillPlaceholders();
break;
case 211:
var matrix = this.createMComponent(21);
matrix.init(2, 3);
matrix.fillPlaceholders();
break;
case 212:
var matrix = this.createMComponent(21);
matrix.init(3, 2);
matrix.fillPlaceholders();
break;
case 213:
var matrix = this.createMComponent(21);
matrix.init(3, 3);
matrix.fillPlaceholders();
break;
case 214:
this.addTxt("");
break;
case 215:
this.addTxt("");
break;
case 216:
this.addTxt("");
break;
case 217:
this.addTxt("");
break;
case 218:
var matrix = this.createMComponent(21);
matrix.init(2, 2);
elem1 = matrix.getElement(0,0);
elem1.addTxt("1");
elem2 = matrix.getElement(0,1);
elem2.addTxt("0");
elem3 = matrix.getElement(1,0);
elem3.addTxt("0");
elem4 = matrix.getElement(1,1);
elem4.addTxt("1");
break;
case 219:
var matrix = this.createMComponent(21);
matrix.init(2, 2);
matrix.hidePlaceholder(true);
elem1 = matrix.getElement(0,0);
elem1.addTxt("1");
elem2 = matrix.getElement(0,1);
elem2.fillPlaceholders();
elem3 = matrix.getElement(1,0);
elem3.fillPlaceholders();
elem4 = matrix.getElement(1,1);
elem4.addTxt("1");
break;
case 220:
var matrix = this.createMComponent(21);
matrix.init(3, 3);
elem1 = matrix.getElement(0,0);
elem1.addTxt("1");
elem2 = matrix.getElement(0,1);
elem2.addTxt("0");
elem3 = matrix.getElement(0,2);
elem3.addTxt("0");
elem4 = matrix.getElement(1,0);
elem4.addTxt("0");
elem5 = matrix.getElement(1,1);
elem5.addTxt("1");
elem6 = matrix.getElement(1,2);
elem6.addTxt("0");
elem7 = matrix.getElement(2,0);
elem7.addTxt("0");
elem8 = matrix.getElement(2,1);
elem8.addTxt("0");
elem9 = matrix.getElement(2,2);
elem9.addTxt("1");
break;
case 221:
var matrix = this.createMComponent(21);
matrix.init(3, 3);
matrix.hidePlaceholder(true);
elem1 = matrix.getElement(0,0);
elem1.addTxt("1");
elem2 = matrix.getElement(0,1);
elem2.fillPlaceholders();
elem3 = matrix.getElement(0,2);
elem3.fillPlaceholders();
elem4 = matrix.getElement(1,0);
elem4.fillPlaceholders();
elem5 = matrix.getElement(1,1);
elem5.addTxt("1");
elem6 = matrix.getElement(1,2);
elem6.fillPlaceholders();
elem7 = matrix.getElement(2,0);
elem7.fillPlaceholders();
elem8 = matrix.getElement(2,1);
elem8.fillPlaceholders();
elem9 = matrix.getElement(2,2);
elem9.addTxt("1");
break;
case 222:
var delim = this.createMComponent(9);
delim.init(0, 4, 0, 1);
base = delim.getBase();
var matrix = base.createMComponent(21);
matrix.init(2, 2);
matrix.fillPlaceholders();
break;
case 223:
var delim = this.createMComponent(9);
delim.init(2, 4, 0, 1);
base = delim.getBase();
var matrix = base.createMComponent(21);
matrix.init(2, 2);
matrix.fillPlaceholders();
break;
case 224:
var delim = this.createMComponent(9);
delim.init(5, 4, 0, 1);
base = delim.getBase();
var matrix = base.createMComponent(21);
matrix.init(2, 2);
matrix.fillPlaceholders();
break;
case 225:
var delim = this.createMComponent(9);
delim.init(6, 4, 0, 1);
base = delim.getBase();
var matrix = base.createMComponent(21);
matrix.init(2, 2);
matrix.fillPlaceholders();
break;
case 226:
var delim = this.createMComponent(9);
delim.init(0, 4, 0, 1);
base = delim.getBase();
var matrix = base.createMComponent(21);
matrix.init(3, 3);
elem1 = matrix.getElement(0,0);
elem1.fillPlaceholders();
elem2 = matrix.getElement(0,1);
elem2.addTxt("");
elem3 = matrix.getElement(0,2);
elem3.fillPlaceholders();
elem4 = matrix.getElement(1,0);
elem4.addTxt("");
elem5 = matrix.getElement(1,1);
elem5.addTxt("");
elem6 = matrix.getElement(1,2);
elem6.addTxt("");
elem7 = matrix.getElement(2,0);
elem7.fillPlaceholders();
elem8 = matrix.getElement(2,1);
elem8.addTxt("");
elem9 = matrix.getElement(2,2);
elem9.fillPlaceholders();
break;
case 227:
var delim = this.createMComponent(9);
delim.init(2, 4, 0, 1);
base = delim.getBase();
var matrix = base.createMComponent(21);
matrix.init(3, 3);
elem1 = matrix.getElement(0,0);
elem1.fillPlaceholders();
elem2 = matrix.getElement(0,1);
elem2.addTxt("");
elem3 = matrix.getElement(0,2);
elem3.fillPlaceholders();
elem4 = matrix.getElement(1,0);
elem4.addTxt("");
elem5 = matrix.getElement(1,1);
elem5.addTxt("");
elem6 = matrix.getElement(1,2);
elem6.addTxt("");
elem7 = matrix.getElement(2,0);
elem7.fillPlaceholders();
elem8 = matrix.getElement(2,1);
elem8.addTxt("");
elem9 = matrix.getElement(2,2);
elem9.fillPlaceholders();
break;
}
},
......@@ -2330,6 +2583,8 @@ CMathContent.prototype =
for(var i = 0; i < this.content.length; i++)
this.content[i].value.Resize();
this.rInterval.startPos = this.rInterval.endPos = this.CurPos;
this.recalculateSize();
},
draw: function()
......
function CMathMatrix(numRow, numCol)
function CMathMatrix()
{
this.lineGapColumn = 1.5;
this.lineGapRow = 1;
......@@ -19,92 +19,42 @@ function CMathMatrix(numRow, numCol)
};
this.baseJc = 0;
this.gaps =
{
row: new Array(),
column: new Array()
};
CMathBase.call(this, numRow, numCol);
CMathBase.call(this);
}
extend(CMathMatrix, CMathBase);
CMathMatrix.prototype.setContent = function()
CMathMatrix.prototype.init = function(countRow, countCol)
{
this.init(this.nRow, this.nCol);
this.fillPlaceholders();
this.setDimension(countRow, countCol);
this.setContent();
}
CMathMatrix.prototype.setProperties = function(nRow, nCol)
{
this.nRow = nRow;
this.nCol = nCol;
}
CMathMatrix.prototype.old_getLineGap = function(spaceLine)
{
var metrs = this.params.font.metrics;
var textHeight = metrs.Height;
var t = 0;
if(spaceLine >= 2)
t = metrs.Height;
else
t = metrs.Height - metrs.Placeholder.Height;
return textHeight*(spaceLine - 1) + t;
}
CMathMatrix.prototype.old_recalculateSize = function()
{
this.gaps = {row: new Array(), column: new Array()};
var interval = this.getLineGap(this.lineGapColumn);
this.gaps.column[0] = 0;
for(var i = 0; i < this.nCol - 1; i++)
this.gaps.column[i + 1] = interval ;
interval = this.getLineGap( this.lineGapRow );
var simpleGap = this.getLineGap(1),
divCenter = 0;
var metrics = this.getMetrics();
this.gaps.row[0] = 0;
for(var j = 0; j < this.nRow - 1; j++)
{
divCenter = metrics.descents[j] + metrics.ascents[j + 1] + simpleGap;
this.gaps.row[j + 1] = divCenter > interval ? simpleGap : interval - metrics.descents[j] - metrics.ascents[j + 1];
}
var height = 0, width = 0;
for(var i = 0; i< this.nCol; i++)
width += this.gaps.column[i] + metrics.widths[i];
for(var j = 0; j < this.nRow; j++)
height += this.gaps.row[j] + metrics.ascents[j] + metrics.descents[j];
this.size = {width: width, height: height, center: height/2};
}
CMathMatrix.prototype.old_setLineGapColumn = function(coeff)
{
this.lineGapColumn = coeff;
this.recalculateSize();
}
CMathMatrix.prototype.old_setLineGapRow = function(coeff)
{
this.lineGapRow = coeff;
this.recalculateSize();
}
CMathMatrix.prototype.recalculateSize = function()
{
this.gaps = {row: new Array(), column: new Array()};
var txtPrp = this.getTxtPrp();
var interval = this.getLineGap(this.spaceColumn);
var interval = this.getLineGap(txtPrp);
this.gaps.column[0] = 0;
for(var i = 0; i < this.nCol - 1; i++)
this.gaps.column[i + 1] = interval;
interval = this.getRowSpace(this.spaceRow);
interval = this.getRowSpace(txtPrp);
var divCenter = 0;
var metrics = this.getMetrics();
var minGp = this.spaceRow.minGap*this.params.font.FontSize*g_dKoef_pt_to_mm;
minGp -= this.params.font.metrics.Placeholder.Height;
var plH = 0.2743827160493827 * txtPrp.FontSize;
var minGp = this.spaceRow.minGap*txtPrp.FontSize*g_dKoef_pt_to_mm;
minGp -= plH;
this.gaps.row[0] = 0;
for(var j = 0; j < this.nRow - 1; j++)
{
......@@ -171,81 +121,6 @@ CMathMatrix.prototype.setPosition = function(pos)
}
}
CMathMatrix.prototype.old_old_findDisposition = function( coord )
{
var pos_x = this.nRow - 1, pos_y = this.nCol - 1,
w = 0, h = 0;
var maxWH = this.getWidthsHeights();
var Widths = maxWH.widths;
var Heights = maxWH.heights;
for(var i = 0; i < this.nCol; i++)
{
w += Widths[i] + this.gaps.column[i + 1]/2;
if(coord.x < w)
{
pos_y = i;
break;
}
w += this.gaps.column[i + 1]/2;
}
for(var j = 0; j < this.nRow; j++)
{
h += Heights[j] + this.gaps.row[j + 1]/2;
if(coord.y < h)
{
pos_x = j;
break;
}
h += this.gaps.row[j + 1]/2;
}
////////////////////////////////
var sumWidth = 0;
var sumHeight = 0;
for(var t = 0; t < pos_y; t++)
sumWidth += Widths[t] + this.gaps.column[t + 1];
for(t = 0; t < pos_x; t++)
sumHeight += Heights[t] + this.gaps.row[t + 1];
// флаг для случая, когда выходим за границы элемента и есть выравнивание относительно других элементов
var flag = true;
if( pos_x != null && pos_y != null)
{
var size = this.elements[pos_x][pos_y].size;
var align = this.align(pos_x, pos_y);
if(coord.x < ( sumWidth + align.x ))
{
mX = 0;
flag = false;
}
else if( coord.x > (sumWidth + align.x + size.width ))
{
mX = size.width;
flag = false;
}
else
mX = coord.x - ( sumWidth + align.x );
if(coord.y < (sumHeight + align.y))
mY = 0;
else if( coord.y > ( sumHeight + align.y + size.height ) )
mY = size.height;
else
mY = coord.y - ( sumHeight + align.y );
}
return {pos: {x: pos_x, y: pos_y }, mCoord: {x: mX, y: mY}, flag: flag};
}
CMathMatrix.prototype.findDisposition = function( coord )
{
var mouseCoord = {x: null, y: null},
......@@ -369,12 +244,11 @@ CMathMatrix.prototype.addRow = function()
for(var j = 0; j < this.nCol; j++)
{
this.elements[this.nRow-1][j] = new CMathContent();
this.elements[this.nRow-1][j].init(this.params);
this.elements[this.nRow-1][j].relate(this);
this.elements[this.nRow-1][j].fillPlaceholders();
this.elements[this.nRow-1][j].setReduct(this.reduct);
this.elements[this.nRow-1][j].setComposition(this.Composition);
}
//this.setDistance();
this.recalculateSize();
}
......@@ -387,97 +261,67 @@ CMathMatrix.prototype.setColumnGapRule = function(rule, gap, minGap)
{
this.spaceColumn.rule = rule;
this.spaceColumn.gap = gap;
if(minGap != null && typeof(minGap) !== "undefined")
if(minGap !== null && typeof(minGap) !== "undefined")
this.spaceColumn.minGap = minGap;
}
CMathMatrix.prototype.getLineGap = function(space)
CMathMatrix.prototype.getLineGap = function(txtPrp)
{
var spLine;
if(space.rule == 0)
if(this.spaceColumn.rule == 0)
spLine = 1; //em
else if(space.rule == 1)
else if(this.spaceColumn.rule == 1)
spLine = 1.5; //em
else if(space.rule == 2)
else if(this.spaceColumn.rule == 2)
spLine = 2; //em
else if(space.rule == 3)
spLine = space.gap/20; //pt
else if(space.rule == 4)
spLine = space.gap/2; //em
else if(this.spaceColumn.rule == 3)
spLine = this.spaceColumn.gap/20; //pt
else if(this.spaceColumn.rule == 4)
spLine = this.spaceColumn.gap/2; //em
else
spLine = 1;
var lineGap;
if(space.rule == 3)
if(this.spaceColumn.rule == 3)
lineGap = spLine*g_dKoef_pt_to_mm; //pt
else
lineGap = spLine*this.params.font.FontSize*g_dKoef_pt_to_mm; //em
lineGap = spLine*txtPrp.FontSize*g_dKoef_pt_to_mm; //em
var wPlh = 0.3241834852430555 * txtPrp.FontSize;
var min = space.minGap / 20 * g_dKoef_pt_to_mm - this.params.font.metrics.Placeholder.Width;
var min = this.spaceColumn.minGap / 20 * g_dKoef_pt_to_mm - wPlh;
lineGap = Math.max(lineGap, min);
//lineGap += this.params.font.metrics.Placeholder.Height; // для случая, когда gapRow - (аскент + дескент) > minGap, вычитаем из gap строки, а здесь прибавляем стандартный metrics.Height
return lineGap;
}
CMathMatrix.prototype.old_getRowSpace = function(space)
{
var spLine;
if(space.rule == 0)
spLine = 840 / 20; //pt
else if(space.rule == 1)
spLine = 840*1.5 /20; //em
else if(space.rule == 2)
spLine = 840*2 /20; //em
else if(space.rule == 3)
spLine = space.gap/20; //pt
else if(space.rule == 4)
spLine = space.gap/2; //em
else
spLine = 1;
//minGap = 780
var lineGap;
/*if(space.rule == 3)
lineGap = spLine*g_dKoef_pt_to_mm; //pt
else
lineGap = spLine*this.params.font.FontSize*g_dKoef_pt_to_mm; //em*/
lineGap = spLine*g_dKoef_pt_to_mm; //pt
lineGap = Math.max(lineGap, space.minGap*this.params.font.FontSize*g_dKoef_pt_to_mm);
return lineGap;
}
CMathMatrix.prototype.getRowSpace = function(space)
CMathMatrix.prototype.getRowSpace = function(txtPrp)
{
var spLine;
if(space.rule == 0)
if(this.spaceRow.rule == 0)
spLine = 7 /6; //em
else if(space.rule == 1)
else if(this.spaceRow.rule == 1)
spLine = 7 /6 *1.5; //em
else if(space.rule == 2)
else if(this.spaceRow.rule == 2)
spLine = 7 /6 *2; //em
else if(space.rule == 3)
spLine = space.gap/20; //pt
else if(space.rule == 4)
spLine = 7/6 * space.gap/2; //em
else if(this.spaceRow.rule == 3)
spLine = this.spaceRow.gap/20; //pt
else if(this.spaceRow.rule == 4)
spLine = 7/6 * this.spaceRow.gap/2; //em
else
spLine = 7 /6;
var lineGap;
if(space.rule == 3)
if(this.spaceRow.rule == 3)
lineGap = spLine*g_dKoef_pt_to_mm; //pt
else
lineGap = spLine*this.params.font.FontSize*g_dKoef_pt_to_mm; //em
lineGap = spLine*txtPrp.FontSize*g_dKoef_pt_to_mm; //em
var min = space.minGap*this.params.font.FontSize*g_dKoef_pt_to_mm;
var min = this.spaceRow.minGap*txtPrp.FontSize*g_dKoef_pt_to_mm;
lineGap = Math.max(lineGap, min);
return lineGap;
......
......@@ -2081,44 +2081,6 @@ CStructArrow.prototype.init = function(type, loc, turn)
this.addMCToContent(argument, operator);
}
CStructArrow.prototype.old_setContent = function()
{
var operator;
if(this.type == 0)
operator = new CHalfArrow();
else if(this.type == 1)
operator = new CSingleArrow();
else if(this.type == 2)
operator = new CLeftRightArrow();
else if(this.type == 3)
operator = new CDoubleArrow();
else if(this.type == 4)
operator = new CLR_DoubleArrow();
else if(this.type == 5)
operator = new CCombiningArrow();
operator.init(this.params);
operator.setLocation(this.loc, this.turn);
var params2 = Common_CopyObj(this.params);
params2.font = getTypeDegree(params2.font);
var argument = new CMathContent();
//var argument = new CDenominator();
argument.init(params2);
argument.relate(this);
argument.fillPlaceholders();
if(this.loc == 0)
{
CStructArrow.superclass.setContent.call(this, operator, argument);
}
else
{
CStructArrow.superclass.setContent.call(this, argument, operator);
}
}
CStructArrow.prototype.getCenter = function()
{
var center, sizeGlyph;
......
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