Commit 0a1a83d4 authored by Alexey.Musinov's avatar Alexey.Musinov Committed by Alexander.Trofimov

autofit rorate text

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@48821 954022d7-b5bf-4e40-9824-e11837661b57
parent 387f0d72
...@@ -222,9 +222,10 @@ ...@@ -222,9 +222,10 @@
var posv = (angle === 90 || angle === -90) ? 0 : Math.abs(Math.cos(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; var sx = 0, sw = 0;
if ('b' === av) { if ('b' === av) { // bottom - vertical
if (angle < 0) { if (angle < 0) {
if ('l' === ah) { dx = (1 - mul * 0.5) * tm.height; sw = x + posv + (mul * 0.5) * tm.height; } 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 ('c' === ah) { dx = (w + tm.height - posv) * 0.5;
sx = x + (w - posv) * 0.5 - (mul * 0.5) * tm.height; sx = x + (w - posv) * 0.5 - (mul * 0.5) * tm.height;
sw = x + (w + posv) * 0.5 + (mul * 0.5) * tm.height; sw = x + (w + posv) * 0.5 + (mul * 0.5) * tm.height;
...@@ -247,11 +248,11 @@ ...@@ -247,11 +248,11 @@
dy = h - mul * tm.height; dy = h - mul * tm.height;
} }
} else { } else {
if (angle > 0) dy = h - mul * tm.height; if (angle > 0) {dy = h - mul * tm.height;} // Math.min(posh, posh - h); } // dy = h - mul * tm.height;
} }
} }
if ('c' === av) { if ('c' === av) { // center - vertical
if (angle < 0) { if (angle < 0) {
if ('l' === ah) { dx = (1 - mul * 0.5) * tm.height; sw = x + posv + (mul * 0.5) * tm.height; } 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 ('c' === ah) { dx = (w + tm.height - posv) * 0.5;
...@@ -278,7 +279,7 @@ ...@@ -278,7 +279,7 @@
} }
} }
if ('t' === av) { if ('t' === av) { // top - verictal
if (angle < 0) { if (angle < 0) {
if ('l' === ah) { dx = (1 - mul * 0.5) * tm.height; sw = x + posv + (mul * 0.5) * tm.height; } 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 ('c' === ah) { dx = (w + tm.height - posv) * 0.5;
...@@ -298,17 +299,13 @@ ...@@ -298,17 +299,13 @@
} }
} }
this.bound.dx = dx; this.bound.dx = dx;
this.bound.dy = dy; this.bound.dy = dy;
this.bound.x = x; this.bound.x = x;
this.bound.y = y; this.bound.y = y;
this.bound.sx = sx;
this.bound.sw = sw;
this.xtrange.sx = sx;
this.xtrange.sw = sw;
this.bound.sx = sx;
this.bound.sw = sw;
if (angle === 90 || angle === -90) { if (angle === 90 || angle === -90) {
this.bound.height = textW; this.bound.height = textW;
...@@ -316,81 +313,10 @@ ...@@ -316,81 +313,10 @@
this.bound.height = Math.abs(Math.sin(angle / 180.0 * Math.PI) * textW) + (mul) * tm.height; this.bound.height = Math.abs(Math.sin(angle / 180.0 * Math.PI) * textW) + (mul) * tm.height;
} }
return this.bound;
},
getRotateOffset: function(angle, x, y, w, h, textW, alignH, alignV) {
this.angle = angle;
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);
if ('b' === av) {
if (posh < h) {
if (angle < 0) {
if ('l' === ah) dx = (1 - mul * 0.5) * tm.height;
if ('c' === ah) dx = (w + tm.height - posv) * 0.5;
if ('r' === ah) dx = w - (mul * 0.5) * tm.height - posv;
dy = h - (posh + mul * tm.height);
} else {
if ('c' === ah) dx = (w - tm.height - posv) * 0.5;
if ('r' === ah) dx = w - posv - tm.height;
dy = h - mul * tm.height;
}
} else {
if (angle < 0) {
if ('l' === ah) dx = (1 - mul * 0.5) * tm.height;
if ('c' === ah) dx = (w + tm.height - posv) * 0.5;
if ('r' === ah) dx = w - (mul * 0.5) * tm.height - posv;
} else {
if ('c' === ah) dx = (w - tm.height - posv) * 0.5;
if ('r' === ah) dx = w - posv - tm.height;
dy = h - mul * tm.height;
}
}
}
if ('c' === av) {
if (posh < h) {
if (angle < 0) {
if ('l' === ah) dx = (1 - mul * 0.5) * tm.height;
if ('c' === ah) dx = (w + tm.height - posv) * 0.5;
if ('r' === ah) dx = w - (mul * 0.5) * tm.height - posv;
dy = (h - posh) * 0.5;
} else {
if ('c' == ah) dx = (w - tm.height - posv) * 0.5;
if ('r' === ah) dx = w - posv - tm.height;
dy = (h + posh) * 0.5;
}
} else {
if (angle < 0) {
if ('l' === ah) dx = (1 - mul * 0.5) * tm.height;
if ('c' === ah) dx = (w + tm.height - posv) * 0.5;
if ('r' === ah) dx = w - (mul * 0.5) * tm.height - posv;
} else {
if ('c' === ah) dx = (w - tm.height - posv) * 0.5;
if ('r' === ah) dx = w - posv - tm.height;
dy = Math.min(h + tm.height * mul, posh);
}
}
}
if ('t' === av) {
if (angle < 0) {
if ('l' === ah) dx = (1 - mul * 0.5) * tm.height;
if ('c' === ah) dx = (w + tm.height - posv) * 0.5;
if ('r' === ah) dx = w - (mul * 0.5) * tm.height - posv;
} else {
if ('c' === ah) dx = (w - tm.height - posv) * 0.5;
if ('r' === ah) dx = w - posv - tm.height;
dy = Math.min(h + tm.height * mul, posh);
}
}
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};
}, },
/** /**
......
...@@ -2405,149 +2405,124 @@ ...@@ -2405,149 +2405,124 @@
var textW = this._calcTextWidth(x1ct, x2ct, ct.metrics, ct.cellHA); var textW = this._calcTextWidth(x1ct, x2ct, ct.metrics, ct.cellHA);
// TODO : все в отдельный метод // TODO : все в отдельный метод
var xb1, yb1, wb, hb, bound, colLeft, colRight; var xb1, yb1, wb, hb, bound, colLeft, colRight, sw, sx;
if (drawingCtx) { if (drawingCtx) {
if (ct.angle || 0) { if (ct.angle || 0) {
xb1 = this.cols[col].left - offsetX; xb1 = this.cols[col].left - offsetX;
yb1 = this.rows[row].top - offsetY; yb1 = this.rows[row].top - offsetY;
wb = this.cols[col].width; wb = this.cols[col].width;
hb = this.rows[row].height; hb = this.rows[row].height;
sx = ct.textBound.sx + xb1;
sw = ct.textBound.sw + xb1;
bound = this.stringRender. bound = this.stringRender.getTransformBound(ct.angle, xb1, yb1, wb, hb, textW, ct.cellHA, ct.cellVA);
getTransformBound(ct.angle, xb1, yb1, wb, hb, textW, ct.cellHA, ct.cellVA); bound.x = xb1;
bound.y = yb1;
if (90 === ct.angle || -90 === ct.angle) { if (90 === ct.angle || -90 === ct.angle) {
ctx.AddClipRect (xb1, yb1, wb, hb); // клип по ячейке // клип по ячейке
ctx.AddClipRect (xb1, yb1, wb, hb);
} else { } else {
ctx.AddClipRect (0, yb1, this.drawingCtx.getWidth(), h); // клип по строке // клип по строке
ctx.AddClipRect (0, yb1, this.drawingCtx.getWidth(), h);
if (!isMerged && !isWrapped) { if (!isMerged && !isWrapped) {
colLeft = col; colLeft = col;
if (0 !== bound.sx) { if (0 !== sx) {
while (true) { while (true) {
if (0 == colLeft) break; if (0 == colLeft) break;
if (bound.sx > this.cols[colLeft].left) break; if (bound.sx >= this.cols[colLeft].left) break;
--colLeft; --colLeft;
} }
} }
colRight = Math.min(col, this.nColsCount - 1); colRight = Math.min(col, this.nColsCount - 1);
if (0 !== bound.sw) { if (0 !== sw) {
while (true) { while (true) {
++colRight; ++colRight;
if (colRight >= this.nColsCount) { --colRight; break; } if (colRight >= this.nColsCount) { --colRight; break; }
if (bound.sw <= this.cols[colRight].left) { --colRight; break; } if (sw <= this.cols[colRight].left) { --colRight; break; }
} }
} }
colLeft = isMerged ? range.c1 : colLeft; colLeft = isMerged ? range.c1 : colLeft;
colRight = isMerged ? Math.min(range.c2, this.nColsCount - 1) : colRight; colRight = isMerged ? Math.min(range.c2, this.nColsCount - 1) : colRight;
this._eraseCellRightBorder( this._eraseCellRightBorder(drawingCtx, colLeft, colRight + (isTrimmedR ? 1 : 0), row, offsetX, offsetY);
drawingCtx, colLeft, colRight + (isTrimmedR ? 1 : 0), row, offsetX, offsetY);
} }
} }
this.stringRender.rotateAtPoint(drawingCtx, ct.angle, xb1, yb1); this.stringRender.rotateAtPoint(drawingCtx, ct.angle, xb1, yb1);
this.stringRender this.stringRender.restoreInternalState(ct.state).renderForPrint(drawingCtx, 0, 0, textW, ct.color);
.restoreInternalState(ct.state)
.renderForPrint(drawingCtx, 0, 0, textW, ct.color);
this.stringRender.resetTransform(drawingCtx); this.stringRender.resetTransform(drawingCtx);
} else { } else {
ctx.AddClipRect (x1, y1, w, h); ctx.AddClipRect (x1, y1, w, h);
this.stringRender.restoreInternalState(ct.state).renderForPrint(drawingCtx, textX, textY, textW, ct.color);
this.stringRender
.restoreInternalState(ct.state)
.renderForPrint(drawingCtx, textX, textY, textW, ct.color);
} }
ctx.RemoveClipRect(); ctx.RemoveClipRect();
} else { } else {
if (ct.angle || 0) { if (ct.angle || 0) {
xb1 = this.cols[col].left - offsetX; xb1 = this.cols[col].left - offsetX;
yb1 = this.rows[row].top - offsetY; yb1 = this.rows[row].top - offsetY;
wb = this.cols[col].width; wb = this.cols[col].width;
hb = this.rows[row].height; hb = this.rows[row].height;
sx = ct.textBound.sx + xb1;
sw = ct.textBound.sw + xb1;
bound = this.stringRender. bound = this.stringRender.getTransformBound(ct.angle, xb1, yb1, wb, hb, textW, ct.cellHA, ct.cellVA);
getTransformBound(ct.angle, xb1, yb1, wb, hb, textW, ct.cellHA, ct.cellVA); bound.x = xb1;
bound.y = yb1;
if (90 === ct.angle || -90 === ct.angle) { this.stringRender.bound = bound;
//this.stringRender.fontNeedUpdate = true;
if (90 === ct.angle || -90 === ct.angle) {
// клип по ячейке // клип по ячейке
ctx.save().beginPath().rect(xb1, yb1, wb, hb).clip();
ctx.save()
.beginPath()
.rect(xb1, yb1, wb, hb)
.clip();
} else { } else {
// клип по строке // клип по строке
ctx.save().beginPath().rect(0, y1, this.drawingCtx.getWidth(), h).clip();
ctx.save()
.beginPath()
.rect(0, y1, this.drawingCtx.getWidth(), h)
.clip();
if (!isMerged && !isWrapped) { if (!isMerged && !isWrapped) {
colLeft = col; colLeft = col;
if (0 !== bound.sx) { if (0 !== sx) {
while (true) { while (true) {
if (0 == colLeft) break; if (0 == colLeft) break;
if (bound.sx > this.cols[colLeft].left) break; if (sx >= this.cols[colLeft].left) break;
--colLeft; --colLeft;
} }
} }
colRight = Math.min(col, this.nColsCount - 1); colRight = Math.min(col, this.nColsCount - 1);
if (0 !== bound.sw) { if (0 !== sw) {
while (true) { while (true) {
++colRight; ++colRight;
if (colRight >= this.nColsCount) { --colRight; break; } if (colRight >= this.nColsCount) { --colRight; break; }
if (bound.sw <= this.cols[colRight].left) { --colRight; break; } if (sw <= this.cols[colRight].left) { --colRight; break; }
} }
} }
colLeft = isMerged ? range.c1 : colLeft; colLeft = isMerged ? range.c1 : colLeft;
colRight = isMerged ? Math.min(range.c2, this.nColsCount - 1) : colRight; colRight = isMerged ? Math.min(range.c2, this.nColsCount - 1) : colRight;
this._eraseCellRightBorder( this._eraseCellRightBorder(drawingCtx, colLeft, colRight + (isTrimmedR ? 1 : 0), row, offsetX, offsetY);
drawingCtx, colLeft, colRight + (isTrimmedR ? 1 : 0), row, offsetX, offsetY);
} }
} }
this.stringRender.rotateAtPoint(undefined, ct.angle, xb1, yb1); this.stringRender.rotateAtPoint(undefined, ct.angle, xb1, yb1);
this.stringRender.restoreInternalState(ct.state).render(0, 0, textW, ct.color);
this.stringRender
.restoreInternalState(ct.state)
.render(0, 0, textW, ct.color);
ctx.restore(); ctx.restore();
// ctx
// //.setFillStyle("#fcd")
// //.fillRect(textX, textY, ct.metrics.width, ct.metrics.height);
// .restore();
this.stringRender.resetTransform(undefined); this.stringRender.resetTransform(undefined);
} else { } else {
ctx.save().beginPath().rect(x1, y1, w, h).clip();
ctx.save() this.stringRender.restoreInternalState(ct.state).render(textX, textY, textW, ct.color);
.beginPath() ctx.restore();
.rect(x1, y1, w, h)
.clip();
this.stringRender
.restoreInternalState(ct.state)
.render(textX, textY, textW, ct.color);
ctx
// //.setFillStyle("#fcd")
// //.fillRect(textX, textY, ct.metrics.width, ct.metrics.height);
.restore();
} }
} }
...@@ -3709,10 +3684,7 @@ ...@@ -3709,10 +3684,7 @@
var pad = this.width_padding * 2 + this.width_1px; var pad = this.width_padding * 2 + this.width_1px;
var sstr, sfl, stm; var sstr, sfl, stm;
//TODO: if (!this.cols[col].isCustomWidth && isNumberFormat && !fMergedColumns &&
//this.stringRender.setRotation(c.getAngle() || 0);
if (!this.cols[col].isCustomWidth && isNumberFormat && !fMergedColumns &&
(c_oAscCanChangeColWidth.numbers === canChangeColWidth || (c_oAscCanChangeColWidth.numbers === canChangeColWidth ||
c_oAscCanChangeColWidth.all === canChangeColWidth)) { c_oAscCanChangeColWidth.all === canChangeColWidth)) {
colWidth = this.cols[col].innerWidth; colWidth = this.cols[col].innerWidth;
...@@ -3779,7 +3751,13 @@ ...@@ -3779,7 +3751,13 @@
var oFontColor = c.getFontcolor(); var oFontColor = c.getFontcolor();
if(null != oFontColor) if(null != oFontColor)
oFontColor = oFontColor.getRgb(); oFontColor = oFontColor.getRgb();
this._fetchCellCache(col, row).text = {
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);
}
this._fetchCellCache(col, row).text = {
state : this.stringRender.getInternalState(), state : this.stringRender.getInternalState(),
flags : fl, flags : fl,
color : (oFontColor || this.settings.cells.defaultState.color), color : (oFontColor || this.settings.cells.defaultState.color),
...@@ -3791,7 +3769,8 @@ ...@@ -3791,7 +3769,8 @@
sideR : cto.rightSide, sideR : cto.rightSide,
cellType: cellType, cellType: cellType,
isFormula: c.getFormula().length > 0, isFormula: c.getFormula().length > 0,
angle : c.getAngle() angle : c.getAngle(),
textBound : textBound
}; };
this._fetchCellCacheText(col, row).hasText = true; this._fetchCellCacheText(col, row).hasText = true;
...@@ -3821,15 +3800,18 @@ ...@@ -3821,15 +3800,18 @@
if (c.getAngle() || 0) { if (c.getAngle() || 0) {
var rotateTextBound = this.stringRender.getTransformBound(c.getAngle(), 0, 0, this.cols[col].width, this.rows[row].height, tm.width, ha, va); if (this.isChanged) {
if (rotateTextBound) { if (textBound) {
if (this.rows[row].height < rotateTextBound.height) { if (this.rows[row].height < textBound.height) {
this.rows[row].height = Math.max(this.rows[row].height, rotateTextBound.height); this.rows[row].height = Math.max(this.rows[row].height, textBound.height);
if (!this.rows[row].isDefaultHeight) {
this.model.setRowHeight(this.rows[row].height + this.height_1px, row, row); if (!this.rows[row].isDefaultHeight) {
this.model.setRowHeight(this.rows[row].height + this.height_1px, row, row);
}
} }
this.isChanged = true;
} }
this.isChanged = true;
} }
} }
......
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