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 @@
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) {
if ('b' === av) { // bottom - vertical
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;
sx = 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 @@
dy = h - mul * tm.height;
}
} 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 ('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;
......@@ -278,7 +279,7 @@
}
}
if ('t' === av) {
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;
......@@ -298,17 +299,13 @@
}
}
this.bound.dx = dx;
this.bound.dy = dy;
this.bound.x = x;
this.bound.y = y;
this.bound.sx = sx;
this.bound.sw = sw;
this.xtrange.sx = sx;
this.xtrange.sw = sw;
this.bound.dx = dx;
this.bound.dy = dy;
this.bound.x = x;
this.bound.y = y;
this.bound.sx = sx;
this.bound.sw = sw;
if (angle === 90 || angle === -90) {
this.bound.height = textW;
......@@ -316,81 +313,10 @@
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 @@
var textW = this._calcTextWidth(x1ct, x2ct, ct.metrics, ct.cellHA);
// TODO : все в отдельный метод
var xb1, yb1, wb, hb, bound, colLeft, colRight;
var xb1, yb1, wb, hb, bound, colLeft, colRight, sw, sx;
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;
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 = this.stringRender.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) {
ctx.AddClipRect (xb1, yb1, wb, hb); // клип по ячейке
// клип по ячейке
ctx.AddClipRect (xb1, yb1, wb, hb);
} else {
ctx.AddClipRect (0, yb1, this.drawingCtx.getWidth(), h); // клип по строке
// клип по строке
ctx.AddClipRect (0, yb1, this.drawingCtx.getWidth(), h);
if (!isMerged && !isWrapped) {
colLeft = col;
if (0 !== bound.sx) {
if (0 !== sx) {
while (true) {
if (0 == colLeft) break;
if (bound.sx > this.cols[colLeft].left) break;
if (bound.sx >= this.cols[colLeft].left) break;
--colLeft;
}
}
colRight = Math.min(col, this.nColsCount - 1);
if (0 !== bound.sw) {
if (0 !== sw) {
while (true) {
++colRight;
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;
colRight = isMerged ? Math.min(range.c2, this.nColsCount - 1) : colRight;
colLeft = isMerged ? range.c1 : colLeft;
colRight = isMerged ? Math.min(range.c2, this.nColsCount - 1) : colRight;
this._eraseCellRightBorder(
drawingCtx, colLeft, colRight + (isTrimmedR ? 1 : 0), row, offsetX, offsetY);
this._eraseCellRightBorder(drawingCtx, colLeft, colRight + (isTrimmedR ? 1 : 0), row, offsetX, offsetY);
}
}
this.stringRender.rotateAtPoint(drawingCtx, ct.angle, xb1, yb1);
this.stringRender
.restoreInternalState(ct.state)
.renderForPrint(drawingCtx, 0, 0, textW, ct.color);
this.stringRender.restoreInternalState(ct.state).renderForPrint(drawingCtx, 0, 0, textW, ct.color);
this.stringRender.resetTransform(drawingCtx);
} else {
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();
} 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;
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 = this.stringRender.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 {
// клип по строке
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) {
colLeft = col;
if (0 !== bound.sx) {
if (0 !== sx) {
while (true) {
if (0 == colLeft) break;
if (bound.sx > this.cols[colLeft].left) break;
if (sx >= this.cols[colLeft].left) break;
--colLeft;
}
}
colRight = Math.min(col, this.nColsCount - 1);
if (0 !== bound.sw) {
if (0 !== sw) {
while (true) {
++colRight;
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;
this._eraseCellRightBorder(
drawingCtx, colLeft, colRight + (isTrimmedR ? 1 : 0), row, offsetX, offsetY);
this._eraseCellRightBorder(drawingCtx, colLeft, colRight + (isTrimmedR ? 1 : 0), row, offsetX, offsetY);
}
}
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
// //.setFillStyle("#fcd")
// //.fillRect(textX, textY, ct.metrics.width, ct.metrics.height);
// .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);
ctx
// //.setFillStyle("#fcd")
// //.fillRect(textX, textY, ct.metrics.width, ct.metrics.height);
.restore();
ctx.save().beginPath().rect(x1, y1, w, h).clip();
this.stringRender.restoreInternalState(ct.state).render(textX, textY, textW, ct.color);
ctx.restore();
}
}
......@@ -3709,10 +3684,7 @@
var pad = this.width_padding * 2 + this.width_1px;
var sstr, sfl, stm;
//TODO:
//this.stringRender.setRotation(c.getAngle() || 0);
if (!this.cols[col].isCustomWidth && isNumberFormat && !fMergedColumns &&
if (!this.cols[col].isCustomWidth && isNumberFormat && !fMergedColumns &&
(c_oAscCanChangeColWidth.numbers === canChangeColWidth ||
c_oAscCanChangeColWidth.all === canChangeColWidth)) {
colWidth = this.cols[col].innerWidth;
......@@ -3779,7 +3751,13 @@
var oFontColor = c.getFontcolor();
if(null != oFontColor)
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(),
flags : fl,
color : (oFontColor || this.settings.cells.defaultState.color),
......@@ -3791,7 +3769,8 @@
sideR : cto.rightSide,
cellType: cellType,
isFormula: c.getFormula().length > 0,
angle : c.getAngle()
angle : c.getAngle(),
textBound : textBound
};
this._fetchCellCacheText(col, row).hasText = true;
......@@ -3821,15 +3800,18 @@
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 (rotateTextBound) {
if (this.rows[row].height < rotateTextBound.height) {
this.rows[row].height = Math.max(this.rows[row].height, rotateTextBound.height);
if (!this.rows[row].isDefaultHeight) {
this.model.setRowHeight(this.rows[row].height + this.height_1px, row, row);
if (this.isChanged) {
if (textBound) {
if (this.rows[row].height < textBound.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);
}
}
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