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 {drawingCtx} drawingCtx
* @param {type} angle Угол поворота в градусах
*/
rotateAtPoint: function (drawingCtx, angle, x, y) {
* @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;
getTransformBound: function(angle, x, y, w, h, textW, alignHorizontal, alignVertical) {
this.angle = 0; // angle;
this.fontNeedUpdate = true;
var dx = 0, dy = 0;
var tm = this._doMeasure(undefined);
var ah = alignH[0], av = alignV[0];
var dx = 0, dy = 0, sx = 0, sw = 0;
var tm = this._doMeasure();
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 = {};
bound.dx = dx;
bound.dy = dy;
bound.x = x;
bound.y = y;
this.bound.sx = sx;
this.bound.sw = sw;
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();
}
} 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;
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.save().beginPath().rect(xb1, yb1, wb, hb).clip();
}
this.stringRender.bound = bound;
//this.stringRender.fontNeedUpdate = true;
this.stringRender.angle = ct.angle;
this.stringRender.fontNeedUpdate = true;
if (90 === ct.angle || -90 === ct.angle) {
// клип по ячейке
ctx.save().beginPath().rect(xb1, yb1, wb, hb).clip();
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);
......@@ -3716,9 +3754,22 @@
if(null != oFontColor)
oFontColor = oFontColor.getRgb();
var rowHeight = this.rows[row].height;
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);
// повернутый текст учитывает мерж ячеек по строкам
if (fMergedRows) {
rowHeight = 0;
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 = {
......@@ -3761,23 +3812,40 @@
}
}
// TODO: отступы
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);
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;
......
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