Commit 8b0f8a15 authored by Alexey.Musinov's avatar Alexey.Musinov
parent 59cb9a7c
......@@ -81,10 +81,7 @@
this.lines = [];
this.ratio = 1;
this.angle = 0;
this.bound = {x: 0, y: 0, dx: 0, dy: 0};
//
this.xtrange = {sx: 0, sw: 0};
this.fontNeedUpdate = false;
return this;
......@@ -164,22 +161,26 @@
/**
* Применяем только трансформации поворота в области
* @param {type} angle Угол поворота в градусах
*/
rotateAtPoint: function (drawingCtx, angle, x, y) {
var m = new asc.Matrix(); m.rotate(angle, 0);
* @param {drawingCtx} drawingCtx
* @param {type} angle Угол поворота в градусах
* @param {Number} x
* @param {Number} y
* @param {Number} dx
* @param {Number} dy
* */
rotateAtPoint: function (drawingCtx, angle, x, y, dx, dy) {
var m = new asc.Matrix(); m.rotate(angle, 0);
var mbt = new asc.Matrix();
if (undefined === drawingCtx) {
mbt.translate(x + this.bound.dx, y + this.bound.dy);
if (null === drawingCtx) {
mbt.translate(x + dx, y + dy);
this.drawingCtx.setTextTransform(m.sx, m.shy, m.shx, m.sy, m.tx, m.ty);
this.drawingCtx.setTransform(mbt.sx, mbt.shy, mbt.shx, mbt.sy, mbt.tx, mbt.ty);
this.drawingCtx.updateTransforms();
} else {
mbt.translate((x + this.bound.dx) * vector_koef, (y + this.bound.dy) * vector_koef);
mbt.translate((x + dx) * vector_koef, (y + dy) * vector_koef);
mbt.multiply(m, 0);
drawingCtx.setTransform(mbt.sx, mbt.shy, mbt.shx, mbt.sy, mbt.tx, mbt.ty);
......@@ -189,7 +190,7 @@
},
resetTransform: function (drawingCtx) {
if (undefined === drawingCtx) {
if (null === drawingCtx) {
this.drawingCtx.resetTransforms();
} else {
var m = new asc.Matrix();
......@@ -207,116 +208,172 @@
* @param {Number} w
* @param {Number} h
* @param {Number} textW
* @param {Number} alignH
* @param {Number} alignV
* @param {String} alignHorizontal
* @param {String} alignVertical
*/
getTransformBound: function(angle, x, y, w, h, textW, alignH, alignV) {
this.angle = angle;
this.fontNeedUpdate = true;
getTransformBound: function(angle, x, y, w, h, textW, alignHorizontal, alignVertical) {
this.angle = 0; // angle;
this.fontNeedUpdate = true;
var dx = 0, dy = 0, sx = 0, sw = 0;
var tm = this._doMeasure();
var dx = 0, dy = 0;
var tm = this._doMeasure(undefined);
var ah = alignH[0], av = alignV[0];
var mul = (90 - (Math.abs(angle)) ) / 90;
var posh = (angle === 90 || angle === -90) ? textW : Math.abs(Math.sin(angle * Math.PI / 180.0) * textW);
var posv = (angle === 90 || angle === -90) ? 0 : Math.abs(Math.cos(angle * Math.PI / 180.0) * textW);
var sx = 0, sw = 0;
if ('b' === av) { // bottom - vertical
if ("bottom" === alignVertical) {
if (angle < 0) {
if ('l' === ah) { dx = (posv* 0.5 + (1 - mul) * tm.height * 0.5);
sw = x + posv + (mul * 0.5) * tm.height; }
if ('c' === ah) { dx = (w + tm.height - posv) * 0.5;
if ("left" === alignHorizontal) {
dx = (1 - mul) * tm.height;
sw = x + posv + (mul * 0.5) * tm.height;
}
else if ("center" === alignHorizontal) {
dx = (w + tm.height - posv) * 0.5;
sx = x + (w - posv) * 0.5 - (mul * 0.5) * tm.height;
sw = x + (w + posv) * 0.5 + (mul * 0.5) * tm.height;
}
if ('r' === ah) { dx = w - (mul * 0.5) * tm.height - posv; sx = x + dx - (mul * 0.5) * tm.height; }
else if ("right" === alignHorizontal) {
dx = w - posv;
sx = x + dx - (mul * 0.5) * tm.height;
}
} else {
if ('l' === ah) { sw = x + posv + (mul * 0.5) * tm.height; }
if ('c' === ah) { dx = (w - tm.height - posv) * 0.5;
if ("left" === alignHorizontal) {
sw = x + posv + (mul * 0.5) * tm.height;
}
else if ("center" === alignHorizontal) {
dx = (w - tm.height - posv) * 0.5;
sx = x + (w - posv) * 0.5 - (mul * 0.5) * tm.height;
sw = x + (w + posv) * 0.5 + (mul * 0.5) * tm.height;
}
if ('r' === ah) { dx = w - posv - tm.height; sx = x + dx;}
else if ("right" === alignHorizontal) {
dx = w - posv - (1 - mul) * tm.height;
sx = x + dx;
}
}
//
if (posh < h) {
if (angle < 0) {
dy = h - (posh + mul * tm.height);
} else {
}
else {
dy = h - mul * tm.height;
}
} else {
if (angle > 0) {dy = h - mul * tm.height;} // Math.min(posh, posh - h); } // dy = h - mul * tm.height;
if (angle > 0) {
dy = h - mul * tm.height;
}
else {
}
}
}
else if ("center" === alignVertical) {
if ('c' === av) { // center - vertical
if (angle < 0) {
if ('l' === ah) { dx = (1 - mul * 0.5) * tm.height; sw = x + posv + (mul * 0.5) * tm.height; }
if ('c' === ah) { dx = (w + tm.height - posv) * 0.5;
if ("left" === alignHorizontal) {
dx = (1 - mul * 0.5) * tm.height;
sw = x + posv + (mul * 0.5) * tm.height;
}
else if ("center" === alignHorizontal) {
dx = (w + tm.height - posv) * 0.5;
sx = x + (w - posv) * 0.5 - (mul * 0.5) * tm.height;
sw = x + (w + posv) * 0.5 + (mul * 0.5) * tm.height;
}
if ('r' === ah) { dx = w - (mul * 0.5) * tm.height - posv; sx = x + dx - (mul * 0.5) * tm.height; }
else if ("right" === alignHorizontal) {
dx = w - (mul * 0.5) * tm.height - posv;
sx = x + dx - (mul * 0.5) * tm.height;
}
} else {
if ('l' === ah) { sw = x + posv + (mul * 0.5) * tm.height; }
if ('c' == ah) { dx = (w - tm.height - posv) * 0.5; }
if ('r' === ah) { dx = w - posv - tm.height; sx = x + dx; }
if ("left" === alignHorizontal) {
sw = x + posv + (mul * 0.5) * tm.height;
}
else if ("center" == alignHorizontal) {
dx = (w - tm.height - posv) * 0.5;
sx = x + (w - posv) * 0.5 - (mul * 0.5) * tm.height;
sw = x + (w + posv) * 0.5 + (mul * 0.5) * tm.height;
}
else if ("right" === alignHorizontal) {
dx = w - posv - tm.height; sx = x + dx;
sx = x + dx - (mul * 0.5) * tm.height;
}
}
//
if (posh < h) {
if (angle < 0) {
dy = (h - posh) * 0.5;
} else {
}
else {
dy = (h + posh) * 0.5;
}
} else {
if (angle > 0) {
dy = Math.min(h + tm.height * mul, posh);
dy = h - mul * tm.height;
}
else {
}
}
}
else if ("top" === alignVertical) {
if ('t' === av) { // top - verictal
if (angle < 0) {
if ('l' === ah) { dx = (1 - mul * 0.5) * tm.height; sw = x + posv + (mul * 0.5) * tm.height; }
if ('c' === ah) { dx = (w + tm.height - posv) * 0.5;
if ("left" === alignHorizontal) {
dx = (1 - mul * 0.5) * tm.height;
sw = x + posv + (mul * 0.5) * tm.height;
}
else if ('c' === alignHorizontal) {
dx = (w + tm.height - posv) * 0.5;
sx = x + (w - posv) * 0.5 - (mul * 0.5) * tm.height;
sw = x + (w + posv) * 0.5 + (mul * 0.5) * tm.height;
}
if ('r' === ah) { dx = w - (mul * 0.5) * tm.height - posv; sx = x + dx - (mul * 0.5) * tm.height;}
else if ("right" === alignHorizontal) {
dx = w - (mul * 0.5) * tm.height - posv;
sx = x + dx - (mul * 0.5) * tm.height;
}
} else {
if ('l' === ah) { sw = x + posv + (mul * 0.5) * tm.height; }
if ('c' === ah) { dx = (w - tm.height - posv) * 0.5;
if ("left" === alignHorizontal) {
sw = x + posv + (mul * 0.5) * tm.height;
}
else if ('c' === alignHorizontal) {
dx = (w - tm.height - posv) * 0.5;
sx = x + (w - posv) * 0.5 - (mul * 0.5) * tm.height;
sw = x + (w + posv) * 0.5 + (mul * 0.5) * tm.height;
}
if ('r' === ah) { dx = w - posv - tm.height; sx = x + dx; }
else if ("right" === alignHorizontal) {
dx = w - posv - tm.height; sx = x + dx;
sx = x + dx - (mul * 0.5) * tm.height;
}
//
dy = Math.min(h + tm.height * mul, posh);
}
}
this.bound.dx = dx;
this.bound.dy = dy;
this.bound.x = x;
this.bound.y = y;
var bound = {};
this.bound.sx = sx;
this.bound.sw = sw;
bound.dx = dx;
bound.dy = dy;
bound.x = x;
bound.y = y;
bound.sx = sx;
bound.sw = sw;
if (angle === 90 || angle === -90) {
this.bound.height = textW;
bound.height = textW;
} else {
this.bound.height = Math.abs(Math.sin(angle / 180.0 * Math.PI) * textW) + (mul) * tm.height;
bound.height = Math.abs(Math.sin(angle / 180.0 * Math.PI) * textW) + (mul) * tm.height;
}
return {x: this.bound.x, y: this.bound.y, dx: this.bound.dx, dy: this.bound.dy, sx: this.bound.sx, sw: this.bound.sw,
height: this.bound.height};
return bound;
},
/**
......@@ -953,6 +1010,7 @@
* @param {Number} alignV
* */
_boundTransform: function(angle, tm, x, y, w, h, textW, alignH, alignV) {
var dx = 0, dy = 0;
var mbt = new asc.Matrix();
var ah = alignH[0], av = alignV[0];
......
......@@ -2338,46 +2338,66 @@
var textY = this._calcTextVertPos(y1, y2, bl, ct.metrics, ct.cellVA);
var textW = this._calcTextWidth(x1ct, x2ct, ct.metrics, ct.cellHA);
// TODO : все в отдельный метод
var xb1, yb1, wb, hb, bound, colLeft, colRight, sw, sx;
var xb1, yb1, wb, hb, bound, colLeft, colRight, i;
var txtRotX, txtRotW;
if (drawingCtx) {
// для печати
if (ct.angle || 0) {
xb1 = this.cols[col].left - offsetX;
yb1 = this.rows[row].top - offsetY;
wb = this.cols[col].width;
hb = this.rows[row].height;
sx = ct.textBound.sx + xb1;
sw = ct.textBound.sw + xb1;
bound = this.stringRender.getTransformBound(ct.angle, xb1, yb1, wb, hb, textW, ct.cellHA, ct.cellVA);
bound.x = xb1;
bound.y = yb1;
txtRotX = ct.textBound.sx + xb1;
txtRotW = ct.textBound.sw + xb1;
if (isMerged) {
wb = 0;
for (i = colL; i <= colR && i < this.nColsCount; ++i) {
wb += this.cols[i].width;
}
hb = 0;
for (i = rowT; i <= rowB && i < this.nColsCount; ++i) {
hb += this.rows[i].height;
}
ctx.AddClipRect (xb1, yb1, wb, hb);
}
this.stringRender.angle = ct.angle;
this.stringRender.fontNeedUpdate = true;
if (90 === ct.angle || -90 === ct.angle) {
// клип по ячейке
ctx.AddClipRect (xb1, yb1, wb, hb);
if (!isMerged) ctx.AddClipRect (xb1, yb1, wb, hb);
} else {
// клип по строке
ctx.AddClipRect (0, yb1, this.drawingCtx.getWidth(), h);
if (!isMerged) ctx.AddClipRect (0, yb1, this.drawingCtx.getWidth(), h);
if (!isMerged && !isWrapped) {
colLeft = col;
if (0 !== sx) {
if (0 !== txtRotX) {
while (true) {
if (0 == colLeft) break;
if (bound.sx >= this.cols[colLeft].left) break;
if (txtRotX >= this.cols[colLeft].left) break;
--colLeft;
}
}
colRight = Math.min(col, this.nColsCount - 1);
if (0 !== sw) {
if (0 !== txtRotW) {
while (true) {
++colRight;
if (colRight >= this.nColsCount) { --colRight; break; }
if (sw <= this.cols[colRight].left) { --colRight; break; }
if (txtRotW <= this.cols[colRight].left) { --colRight; break; }
}
}
......@@ -2388,55 +2408,73 @@
}
}
this.stringRender.rotateAtPoint(drawingCtx, ct.angle, xb1, yb1);
this.stringRender.rotateAtPoint(drawingCtx, ct.angle, xb1, yb1, ct.textBound.dx, ct.textBound.dy);
this.stringRender.restoreInternalState(ct.state).renderForPrint(drawingCtx, 0, 0, textW, ct.color);
this.stringRender.resetTransform(drawingCtx);
if (!isMerged) ctx.RemoveClipRect();
} else {
ctx.AddClipRect (x1, y1, w, h);
this.stringRender.restoreInternalState(ct.state).renderForPrint(drawingCtx, textX, textY, textW, ct.color);
ctx.RemoveClipRect();
}
ctx.RemoveClipRect();
} else {
// для отрисовки
if (ct.angle || 0) {
xb1 = this.cols[col].left - offsetX;
yb1 = this.rows[row].top - offsetY;
wb = this.cols[col].width;
hb = this.rows[row].height;
sx = ct.textBound.sx + xb1;
sw = ct.textBound.sw + xb1;
bound = this.stringRender.getTransformBound(ct.angle, xb1, yb1, wb, hb, textW, ct.cellHA, ct.cellVA);
bound.x = xb1;
bound.y = yb1;
txtRotX = ct.textBound.sx + xb1;
txtRotW = ct.textBound.sw + xb1;
this.stringRender.bound = bound;
//this.stringRender.fontNeedUpdate = true;
if (isMerged) {
wb = 0;
for (i = colL; i <= colR && i < this.nColsCount; ++i) {
wb += this.cols[i].width;
}
hb = 0;
for (i = rowT; i <= rowB && i < this.nColsCount; ++i) {
hb += this.rows[i].height;
}
if (90 === ct.angle || -90 === ct.angle) {
// клип по ячейке
ctx.save().beginPath().rect(xb1, yb1, wb, hb).clip();
}
this.stringRender.angle = ct.angle;
this.stringRender.fontNeedUpdate = true;
if (90 === ct.angle || -90 === ct.angle) {
// клип по ячейке
if (!isMerged) ctx.save().beginPath().rect(xb1, yb1, wb, hb).clip();
} else {
// клип по строке
ctx.save().beginPath().rect(0, y1, this.drawingCtx.getWidth(), h).clip();
if (!isMerged) ctx.save().beginPath().rect(0, y1, this.drawingCtx.getWidth(), h).clip();
if (!isMerged && !isWrapped) {
colLeft = col;
if (0 !== sx) {
if (0 !== txtRotX) {
while (true) {
if (0 == colLeft) break;
if (sx >= this.cols[colLeft].left) break;
if (txtRotX >= this.cols[colLeft].left) break;
--colLeft;
}
}
colRight = Math.min(col, this.nColsCount - 1);
if (0 !== sw) {
if (0 !== txtRotW) {
while (true) {
++colRight;
if (colRight >= this.nColsCount) { --colRight; break; }
if (sw <= this.cols[colRight].left) { --colRight; break; }
if (txtRotW <= this.cols[colRight].left) { --colRight; break; }
}
}
......@@ -2447,12 +2485,12 @@
}
}
this.stringRender.rotateAtPoint(undefined, ct.angle, xb1, yb1);
this.stringRender.rotateAtPoint(null, ct.angle, xb1, yb1, ct.textBound.dx, ct.textBound.dy);
this.stringRender.restoreInternalState(ct.state).render(0, 0, textW, ct.color);
this.stringRender.resetTransform(null);
ctx.restore();
if (!isMerged) ctx.restore();
this.stringRender.resetTransform(undefined);
} else {
ctx.save().beginPath().rect(x1, y1, w, h).clip();
this.stringRender.restoreInternalState(ct.state).render(textX, textY, textW, ct.color);
......@@ -3548,240 +3586,270 @@
return undefined;
},
_addCellTextToCache: function (col, row, canChangeColWidth) {
var self = this;
_addCellTextToCache: function (col, row, canChangeColWidth) {
var self = this;
function isFixedWidthCell(frag) {
for (var i = 0; i < frag.length; ++i) {
var f = frag[i].format;
if (f && f.repeat) {return true;}
}
return false;
}
function isFixedWidthCell(frag) {
for (var i = 0; i < frag.length; ++i) {
var f = frag[i].format;
if (f && f.repeat) {return true;}
}
return false;
}
function truncFracPart(frag) {
var s = frag.reduce(function (prev,val) {return prev + val.text;}, "");
// Проверка scientific format
if (s.search(/E/i) >= 0) {
return frag;
}
// Поиск десятичной точки
var pos = s.search(/[,\.]/);
if (pos >= 0) {
frag[0].text = s.slice(0, pos);
frag.splice(1, frag.length - 1);
}
return frag;
}
function truncFracPart(frag) {
var s = frag.reduce(function (prev,val) {return prev + val.text;}, "");
// Проверка scientific format
if (s.search(/E/i) >= 0) {
return frag;
}
// Поиск десятичной точки
var pos = s.search(/[,\.]/);
if (pos >= 0) {
frag[0].text = s.slice(0, pos);
frag.splice(1, frag.length - 1);
}
return frag;
}
function makeFnIsGoodNumFormat(flags, width) {
return function (str) {
return self.stringRender.measureString(str, flags, width).width <= width;
};
}
function makeFnIsGoodNumFormat(flags, width) {
return function (str) {
return self.stringRender.measureString(str, flags, width).width <= width;
};
}
function changeColWidth(col, width, pad) {
var cc = Math.min(self._colWidthToCharCount(width + pad), /*max col width*/255);
var modelw = self._charCountToModelColWidth(cc, true);
var colw = self._calcColWidth(modelw);
function changeColWidth(col, width, pad) {
var cc = Math.min(self._colWidthToCharCount(width + pad), /*max col width*/255);
var modelw = self._charCountToModelColWidth(cc, true);
var colw = self._calcColWidth(modelw);
if (colw.width > self.cols[col].width) {
self.cols[col].width = colw.width;
self.cols[col].innerWidth = colw.innerWidth;
self.cols[col].charCount = colw.charCount;
History.Create_NewPoint();
History.SetSelection(null, true);
History.StartTransaction();
// Выставляем, что это bestFit
self.model.setColBestFit (true, modelw, col, col);
History.EndTransaction();
self._updateColumnPositions();
self.isChanged = true;
}
}
if (colw.width > self.cols[col].width) {
self.cols[col].width = colw.width;
self.cols[col].innerWidth = colw.innerWidth;
self.cols[col].charCount = colw.charCount;
var c = this._getCell(col, row);
if (c === undefined) {return col;}
History.Create_NewPoint();
History.SetSelection(null, true);
History.StartTransaction();
// Выставляем, что это bestFit
self.model.setColBestFit (true, modelw, col, col);
History.EndTransaction();
var bUpdateScrollX = false;
var bUpdateScrollY = false;
// Проверка на увеличение колличества столбцов
if (col >= this.cols.length) {
bUpdateScrollX = this.expandColsOnScroll(/*isNotActive*/ false, /*updateColsCount*/ true);
}
// Проверка на увеличение колличества строк
if (row >= this.rows.length) {
bUpdateScrollY = this.expandRowsOnScroll(/*isNotActive*/ false, /*updateRowsCount*/ true);
}
if (bUpdateScrollX && bUpdateScrollY) {
this._trigger("reinitializeScroll");
}
else if (bUpdateScrollX) {
this._trigger("reinitializeScrollX");
}
else if (bUpdateScrollY) {
this._trigger("reinitializeScrollY");
}
self._updateColumnPositions();
self.isChanged = true;
}
}
// Range для замерженной ячейки
var mc = this.model.getMergedByCell(row, col);
var fl = this._getCellFlags(c);
var fMergedColumns = false; // Замержены ли колонки (если да, то автоподбор ширины не должен работать)
var fMergedRows = false; // Замержены ли строки (если да, то автоподбор высоты не должен работать)
if (null !== mc) {
if (col !== mc.c1 || row !== mc.r1) {return mc.c2;} // skip other merged cell from range
if (mc.c1 !== mc.c2)
fMergedColumns = true;
if (mc.r1 !== mc.r2)
fMergedRows = true;
}
var c = this._getCell(col, row);
if (c === undefined) {return col;}
if (this._isCellEmpty(c)) {return mc ? mc.c2 : col;}
var bUpdateScrollX = false;
var bUpdateScrollY = false;
// Проверка на увеличение колличества столбцов
if (col >= this.cols.length) {
bUpdateScrollX = this.expandColsOnScroll(/*isNotActive*/ false, /*updateColsCount*/ true);
}
// Проверка на увеличение колличества строк
if (row >= this.rows.length) {
bUpdateScrollY = this.expandRowsOnScroll(/*isNotActive*/ false, /*updateRowsCount*/ true);
}
if (bUpdateScrollX && bUpdateScrollY) {
this._trigger("reinitializeScroll");
}
else if (bUpdateScrollX) {
this._trigger("reinitializeScrollX");
}
else if (bUpdateScrollY) {
this._trigger("reinitializeScrollY");
}
var dDigitsCount = 0;
var colWidth = 0;
var cellType = c.getType();
var isNumberFormat = (!cellType || CellValueType.Number === cellType);
var numFormatStr = c.getNumFormatStr();
var pad = this.width_padding * 2 + this.width_1px;
var sstr, sfl, stm;
// Range для замерженной ячейки
var mc = this.model.getMergedByCell(row, col);
var fl = this._getCellFlags(c);
var fMergedColumns = false; // Замержены ли колонки (если да, то автоподбор ширины не должен работать)
var fMergedRows = false; // Замержены ли строки (если да, то автоподбор высоты не должен работать)
if (null !== mc) {
if (col !== mc.c1 || row !== mc.r1) {return mc.c2;} // skip other merged cell from range
if (mc.c1 !== mc.c2)
fMergedColumns = true;
if (mc.r1 !== mc.r2)
fMergedRows = true;
}
if (!this.cols[col].isCustomWidth && isNumberFormat && !fMergedColumns &&
(c_oAscCanChangeColWidth.numbers === canChangeColWidth ||
c_oAscCanChangeColWidth.all === canChangeColWidth)) {
colWidth = this.cols[col].innerWidth;
// Измеряем целую часть числа
sstr = c.getValue2(gc_nMaxDigCountView, function(){return true;});
//todo убрать Asc.clone на другой clone или изменить truncFracPart, чтобы не изменяла исходный массив
if ("General" === numFormatStr) {sstr = truncFracPart(Asc.clone(sstr));}
sfl = asc_clone(fl);
sfl.wrapText = false;
stm = this._roundTextMetrics( this.stringRender.measureString(sstr, sfl, colWidth) );
// Если целая часть числа не убирается в ячейку, то расширяем столбец
if (stm.width > colWidth) {changeColWidth(col, stm.width, pad);}
// Обновленная ячейка
dDigitsCount = this.cols[col].charCount;
colWidth = this.cols[col].innerWidth;
} else if (null === mc) {
// Обычная ячейка
dDigitsCount = this.cols[col].charCount;
colWidth = this.cols[col].innerWidth;
// подбираем ширину
if (!this.cols[col].isCustomWidth && !fMergedColumns && !fl.wrapText &&
c_oAscCanChangeColWidth.all === canChangeColWidth) {
sstr = c.getValue2(gc_nMaxDigCountView, function(){return true;});
stm = this._roundTextMetrics( this.stringRender.measureString(sstr, fl, colWidth) );
if (stm.width > colWidth) {
changeColWidth(col, stm.width, pad);
// Обновленная ячейка
dDigitsCount = this.cols[col].charCount;
colWidth = this.cols[col].innerWidth;
}
}
} else {
// Замерженная ячейка, нужна сумма столбцов
for (var i = mc.c1; i <= mc.c2 && i < this.nColsCount; ++i) {
colWidth += this.cols[i].width;
}
colWidth -= pad;
dDigitsCount = gc_nMaxDigCountView;
}
if (this._isCellEmpty(c)) {return mc ? mc.c2 : col;}
// ToDo dDigitsCount нужно рассчитывать исходя не из дефалтового шрифта и размера, а исходя из текущего шрифта и размера ячейки
var str = c.getValue2(dDigitsCount, makeFnIsGoodNumFormat(fl, colWidth));
var ha = c.getAlignHorizontalByValue().toLowerCase();
var va = c.getAlignVertical().toLowerCase();
var maxW = fl.wrapText || fl.shrinkToFit || fl.isMerged || isFixedWidthCell(str) ? this._calcMaxWidth(col, row, mc) : undefined;
var tm = this._roundTextMetrics( this.stringRender.measureString(str, fl, maxW) );
var cto = (fl.isMerged || fl.wrapText) ?
{
maxWidth: maxW - this.cols[col].innerWidth + this.cols[col].width,
leftSide: 0,
rightSide: 0
} :
this._calcCellTextOffset(col, row, ha, tm.width);
// check right side of cell text and append columns if it exceeds existing cells borders
if (!fl.isMerged) {
var rside = this.cols[col - cto.leftSide].left + tm.width;
var lc = this.cols[this.cols.length - 1];
if (rside > lc.left + lc.width) {
this._appendColumns(rside);
cto = this._calcCellTextOffset(col, row, ha, tm.width);
}
}
var oFontColor = c.getFontcolor();
if(null != oFontColor)
oFontColor = oFontColor.getRgb();
var dDigitsCount = 0;
var colWidth = 0;
var cellType = c.getType();
var isNumberFormat = (!cellType || CellValueType.Number === cellType);
var numFormatStr = c.getNumFormatStr();
var pad = this.width_padding * 2 + this.width_1px;
var sstr, sfl, stm;
var rowHeight = this.rows[row].height;
var textBound = {};
if (!this.cols[col].isCustomWidth && isNumberFormat && !fMergedColumns &&
(c_oAscCanChangeColWidth.numbers === canChangeColWidth ||
c_oAscCanChangeColWidth.all === canChangeColWidth)) {
colWidth = this.cols[col].innerWidth;
// Измеряем целую часть числа
sstr = c.getValue2(gc_nMaxDigCountView, function(){return true;});
//todo убрать Asc.clone на другой clone или изменить truncFracPart, чтобы не изменяла исходный массив
if ("General" === numFormatStr) {sstr = truncFracPart(Asc.clone(sstr));}
sfl = asc_clone(fl);
sfl.wrapText = false;
stm = this._roundTextMetrics( this.stringRender.measureString(sstr, sfl, colWidth) );
// Если целая часть числа не убирается в ячейку, то расширяем столбец
if (stm.width > colWidth) {changeColWidth(col, stm.width, pad);}
// Обновленная ячейка
dDigitsCount = this.cols[col].charCount;
colWidth = this.cols[col].innerWidth;
} else if (null === mc) {
// Обычная ячейка
dDigitsCount = this.cols[col].charCount;
colWidth = this.cols[col].innerWidth;
// подбираем ширину
if (!this.cols[col].isCustomWidth && !fMergedColumns && !fl.wrapText &&
c_oAscCanChangeColWidth.all === canChangeColWidth) {
sstr = c.getValue2(gc_nMaxDigCountView, function(){return true;});
stm = this._roundTextMetrics( this.stringRender.measureString(sstr, fl, colWidth) );
if (stm.width > colWidth) {
changeColWidth(col, stm.width, pad);
// Обновленная ячейка
dDigitsCount = this.cols[col].charCount;
colWidth = this.cols[col].innerWidth;
}
}
} else {
// Замерженная ячейка, нужна сумма столбцов
for (var i = mc.c1; i <= mc.c2 && i < this.nColsCount; ++i) {
colWidth += this.cols[i].width;
}
colWidth -= pad;
dDigitsCount = gc_nMaxDigCountView;
}
if (c.getAngle() || 0) {
// ToDo dDigitsCount нужно рассчитывать исходя не из дефалтового шрифта и размера, а исходя из текущего шрифта и размера ячейки
var str = c.getValue2(dDigitsCount, makeFnIsGoodNumFormat(fl, colWidth));
var ha = c.getAlignHorizontalByValue().toLowerCase();
var va = c.getAlignVertical().toLowerCase();
var maxW = fl.wrapText || fl.shrinkToFit || fl.isMerged || isFixedWidthCell(str) ? this._calcMaxWidth(col, row, mc) : undefined;
var tm = this._roundTextMetrics( this.stringRender.measureString(str, fl, maxW) );
var cto = (fl.isMerged || fl.wrapText) ?
{
maxWidth: maxW - this.cols[col].innerWidth + this.cols[col].width,
leftSide: 0,
rightSide: 0
} :
this._calcCellTextOffset(col, row, ha, tm.width);
// повернутый текст учитывает мерж ячеек по строкам
// check right side of cell text and append columns if it exceeds existing cells borders
if (!fl.isMerged) {
var rside = this.cols[col - cto.leftSide].left + tm.width;
var lc = this.cols[this.cols.length - 1];
if (rside > lc.left + lc.width) {
this._appendColumns(rside);
cto = this._calcCellTextOffset(col, row, ha, tm.width);
}
}
var oFontColor = c.getFontcolor();
if(null != oFontColor)
oFontColor = oFontColor.getRgb();
if (fMergedRows) {
rowHeight = 0;
var textBound = {};
if (c.getAngle() || 0) {
textBound = this.stringRender.getTransformBound(c.getAngle(), 0, 0, this.cols[col].width, this.rows[row].height, tm.width, ha, va);
for (var j = mc.r1; j <= mc.r2 && j < this.nRowsCount; ++j) {
rowHeight += this.rows[j].height;
}
}
textBound = this.stringRender.getTransformBound(c.getAngle(), 0, 0, colWidth, rowHeight, tm.width, ha, va);
}
this._fetchCellCache(col, row).text = {
state : this.stringRender.getInternalState(),
flags : fl,
color : (oFontColor || this.settings.cells.defaultState.color),
metrics : tm,
cellW : cto.maxWidth,
cellHA : ha,
cellVA : va,
sideL : cto.leftSide,
sideR : cto.rightSide,
cellType : cellType,
isFormula : c.getFormula().length > 0,
angle : c.getAngle(),
state : this.stringRender.getInternalState(),
flags : fl,
color : (oFontColor || this.settings.cells.defaultState.color),
metrics : tm,
cellW : cto.maxWidth,
cellHA : ha,
cellVA : va,
sideL : cto.leftSide,
sideR : cto.rightSide,
cellType : cellType,
isFormula : c.getFormula().length > 0,
angle : c.getAngle(),
textBound : textBound,
mc : mc
};
mc : mc
};
this._fetchCellCacheText(col, row).hasText = true;
this._fetchCellCacheText(col, row).hasText = true;
if (cto.leftSide !== 0 || cto.rightSide !== 0) {
this._addErasedBordersToCache(col - cto.leftSide, col + cto.rightSide, row);
}
// update row's descender
if (va !== kvaTop && va !== kvaCenter && !fl.isMerged) {
this.rows[row].descender = Math.max(this.rows[row].descender, tm.height - tm.baseline);
}
if (cto.leftSide !== 0 || cto.rightSide !== 0) {
this._addErasedBordersToCache(col - cto.leftSide, col + cto.rightSide, row);
}
// update row's height
if (!this.rows[row].isCustomHeight) {
// Замерженная ячейка (с 2-мя или более строками) не влияет на высоту строк!
if (!fMergedRows) {
this.rows[row].heightReal = this.rows[row].height = Math.min(this.maxRowHeight, Math.max(this.rows[row].height, tm.height));
if (!this.rows[row].isDefaultHeight) {
this.model.setRowHeight(this.rows[row].height + this.height_1px, row, row);
}
this.isChanged = true;
}
}
// update row's descender
if (va !== kvaTop && va !== kvaCenter && !fl.isMerged) {
this.rows[row].descender = Math.max(this.rows[row].descender, tm.height - tm.baseline);
}
// TODO: отступы
// update row's height
if (!this.rows[row].isCustomHeight) {
// Замерженная ячейка (с 2-мя или более строками) не влияет на высоту строк!
if (!fMergedRows) {
this.rows[row].heightReal = this.rows[row].height = Math.min(this.maxRowHeight, Math.max(this.rows[row].height, tm.height));
if (!this.rows[row].isDefaultHeight) {
this.model.setRowHeight(this.rows[row].height + this.height_1px, row, row);
}
this.isChanged = true;
}
}
if ((c.getAngle() || 0) && !this.rows[row].isCustomHeight) {
if (this.isChanged) {
if (textBound) {
if (this.rows[row].height < textBound.height) {
this.rows[row].heightReal = this.rows[row].height = Math.max(this.rows[row].height, textBound.height);
this.rows[row].heightReal = this.rows[row].height = Math.max(this.rows[row].height, textBound.height);
rowHeight = this.rows[row].heightReal;
if (!this.rows[row].isDefaultHeight) {
this.model.setRowHeight(this.rows[row].height + this.height_1px, row, row);
}
this._fetchCellCache(col, row).text.textBound =
this.stringRender.getTransformBound(c.getAngle(), 0, 0, colWidth, rowHeight, tm.width, ha, va);
}
else {
// если была автоподстройка по высоте, надо ее сбросить и оставить текущее значение высоты
this.isChanged = true;
if (fMergedRows) {
this.rows[row].heightReal = this.rows[row].height = Math.max(this.rows[row].height, textBound.height);
if (this.rows[row].isDefaultHeight) {
this.model.setRowHeight(this.rows[row].height, row, row);
}
}
}
}
this.isChanged = true;
}
}
return mc ? mc.c2 : col;
},
return mc ? mc.c2 : col;
},
_calcMaxWidth: function (col, row, mc) {
if (null === mc) {return this.cols[col].innerWidth;}
......
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