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

Поворотный текст с учетом BB

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@68239 954022d7-b5bf-4e40-9824-e11837661b57
parent 3ace581d
...@@ -245,67 +245,68 @@ ...@@ -245,67 +245,68 @@
* @param {String} alignVertical * @param {String} alignVertical
* @param {Number} maxWidth * @param {Number} maxWidth
*/ */
StringRender.prototype.getTransformBound = function(angle, x, y, w, h, textW, alignHorizontal, alignVertical, maxWidth) { StringRender.prototype.getTransformBound = function(angle, x, y, w, h, textW, alignHorizontal, alignVertical, maxWidth) {
this.angle = 0; // angle; this.angle = 0; // angle;
this.fontNeedUpdate = true; this.fontNeedUpdate = true;
var dx = 0, dy = 0, sx = 0, sw = 0, var dx = 0, dy = 0,offsetX = 0, // смещение BB
tm = this._doMeasure(maxWidth), tm = this._doMeasure(maxWidth),
mul = (90 - (Math.abs(angle)) ) / 90, mul = (90 - (Math.abs(angle)) ) / 90,
posh = (angle === 90 || angle === -90) ? textW : Math.abs(Math.sin(angle * Math.PI / 180.0) * textW),
posv = (angle === 90 || angle === -90) ? 0 : Math.abs(Math.cos(angle * Math.PI / 180.0) * textW), angleSin = Math.sin(angle * Math.PI / 180.0),
angleCos = Math.cos(angle * Math.PI / 180.0),
posh = (angle === 90 || angle === -90) ? textW : Math.abs(angleSin * textW),
posv = (angle === 90 || angle === -90) ? 0 : Math.abs(angleCos * textW),
isHorzLeft = ('left' === alignHorizontal), isHorzLeft = ('left' === alignHorizontal),
isHorzCenter = ('center' === alignHorizontal), isHorzCenter = ('center' === alignHorizontal),
isHorzRight = ('right' === alignHorizontal), isHorzRight = ('right' === alignHorizontal),
isVertBottom = ('bottom' === alignVertical), isVertBottom = ('bottom' === alignVertical),
isVertCenter = ('center' === alignVertical), isVertCenter = ('center' === alignVertical),
isVertTop = ('top' === alignVertical); isVertTop = ('top' === alignVertical);
if (isVertBottom) { if (isVertBottom) {
if (angle < 0) { if (angle < 0) {
if (isHorzLeft) { if (isHorzLeft) {
dx = (1 - mul) * tm.height; dx = - (angleSin * tm.height);
sw = x + posv + (mul * 0.5) * tm.height;
} }
else if (isHorzCenter) { else if (isHorzCenter) {
dx = (w + tm.height - posv) * 0.5; dx = (w - angleSin * tm.height - posv) / 2;
sx = x + (w - posv) * 0.5 - (mul * 0.5) * tm.height; offsetX = - (w - posv) / 2 - angleSin * tm.height / 2;
sw = x + (w + posv) * 0.5 + (mul * 0.5) * tm.height;
} }
else if (isHorzRight) { else if (isHorzRight) {
dx = w - posv; dx = w - posv + 2;
sx = x + dx - (mul * 0.5) * tm.height; offsetX = - (w - posv) - angleSin * tm.height - 2;
} }
} else { } else {
if (isHorzLeft) { if (isHorzLeft) {
sw = x + posv + (mul * 0.5) * tm.height;
} }
else if (isHorzCenter) { else if (isHorzCenter) {
dx = (w - tm.height - posv) * 0.5; dx = (w - angleSin * tm.height - posv) / 2;
sx = x + (w - posv) * 0.5 - (mul * 0.5) * tm.height; offsetX = - (w - posv) / 2 + angleSin * tm.height / 2;
sw = x + (w + posv) * 0.5 + (mul * 0.5) * tm.height;
} }
else if (isHorzRight) { else if (isHorzRight) {
dx = w - posv - (1 - mul) * tm.height; dx = asc_calcnpt(w - posv + 1 + 1 - tm.height * angleSin, 96);
sx = x + dx; offsetX = - asc_calcnpt(w - posv + 1 + 1 - tm.height * angleSin, 96);
} }
} }
//
if (posh < h) { if (posh < h) {
if (angle < 0) { if (angle < 0) {
dy = h - (posh + mul * tm.height); dy = h - (posh + angleCos * tm.height);
} }
else { else {
dy = h - mul * tm.height; dy = h - angleCos * tm.height;
} }
} else { } else {
if (angle > 0) { if (angle > 0) {
dy = h - mul * tm.height; dy = h - angleCos * tm.height;
} }
} }
} }
...@@ -313,30 +314,27 @@ ...@@ -313,30 +314,27 @@
if (angle < 0) { if (angle < 0) {
if (isHorzLeft) { if (isHorzLeft) {
dx = (1 - mul * 0.5) * tm.height; dx = - (angleSin * tm.height);
sw = x + posv + (mul * 0.5) * tm.height;
} }
else if (isHorzCenter) { else if (isHorzCenter) {
dx = (w + tm.height - posv) * 0.5; dx = (w - angleSin * tm.height - posv) / 2;
sx = x + (w - posv) * 0.5 - (mul * 0.5) * tm.height; offsetX = - (w - posv) / 2 - angleSin * tm.height / 2;
sw = x + (w + posv) * 0.5 + (mul * 0.5) * tm.height;
} }
else if (isHorzRight) { else if (isHorzRight) {
dx = w - (mul * 0.5) * tm.height - posv; dx = w - posv + 2;
sx = x + dx - (mul * 0.5) * tm.height; offsetX = - (w - posv) - angleSin * tm.height - 2;
} }
} else { } else {
if (isHorzLeft) { if (isHorzLeft) {
sw = x + posv + (mul * 0.5) * tm.height;
} }
else if (isHorzCenter) { else if (isHorzCenter) {
dx = (w - tm.height - posv) * 0.5; dx = (w - angleSin * tm.height - posv) / 2;
sx = x + (w - posv) * 0.5 - (mul * 0.5) * tm.height; offsetX = - (w - posv) / 2 + angleSin * tm.height / 2;
sw = x + (w + posv) * 0.5 + (mul * 0.5) * tm.height;
} }
else if (isHorzRight) { else if (isHorzRight) {
dx = w - posv - tm.height; sx = x + dx; dx = asc_calcnpt(w - posv + 1 + 1 - tm.height * angleSin, 96);
sx = x + dx - (mul * 0.5) * tm.height; offsetX = - asc_calcnpt(w - posv + 1 + 1 - tm.height * angleSin, 96);
} }
} }
...@@ -344,14 +342,14 @@ ...@@ -344,14 +342,14 @@
if (posh < h) { if (posh < h) {
if (angle < 0) { if (angle < 0) {
dy = (h - posh) * 0.5; dy = (h - posh - angleCos * tm.height) * 0.5;
} }
else { else {
dy = (h + posh) * 0.5; dy = (h + posh - angleCos * tm.height) * 0.5;
} }
} else { } else {
if (angle > 0) { if (angle > 0) {
dy = h - mul * tm.height; dy = h - angleCos * tm.height;
} }
} }
} }
...@@ -359,46 +357,41 @@ ...@@ -359,46 +357,41 @@
if (angle < 0) { if (angle < 0) {
if (isHorzLeft) { if (isHorzLeft) {
dx = (1 - mul * 0.5) * tm.height; dx = - (angleSin * tm.height);
sw = x + posv + (mul * 0.5) * tm.height;
} }
else if (isHorzCenter) { else if (isHorzCenter) {
dx = (w + tm.height - posv) * 0.5; dx = (w - angleSin * tm.height - posv) / 2;
sx = x + (w - posv) * 0.5 - (mul * 0.5) * tm.height; offsetX = - (w - posv) / 2 - angleSin * tm.height / 2;
sw = x + (w + posv) * 0.5 + (mul * 0.5) * tm.height;
} }
else if (isHorzRight) { else if (isHorzRight) {
dx = w - (mul * 0.5) * tm.height - posv; dx = w - posv + 2;
sx = x + dx - (mul * 0.5) * tm.height; offsetX = - (w - posv) - angleSin * tm.height - 2;
} }
} else { } else {
if (isHorzLeft) { if (isHorzLeft) {
sw = x + posv + (mul * 0.5) * tm.height;
} }
else if (isHorzCenter) { else if (isHorzCenter) {
dx = (w - tm.height - posv) * 0.5; dx = (w - angleSin * tm.height - posv) / 2;
sx = x + (w - posv) * 0.5 - (mul * 0.5) * tm.height; offsetX = - (w - posv) / 2 + angleSin * tm.height / 2;
sw = x + (w + posv) * 0.5 + (mul * 0.5) * tm.height;
} }
else if (isHorzRight) { else if (isHorzRight) {
dx = w - posv - tm.height; sx = x + dx; dx = asc_calcnpt(w - posv + 1 + 1 - tm.height * angleSin, 96);
sx = x + dx - (mul * 0.5) * tm.height; offsetX = - asc_calcnpt(w - posv + 1 + 1 - tm.height * angleSin, 96);
} }
// dy = Math.min(h + tm.height * angleCos, posh);
dy = Math.min(h + tm.height * mul, posh);
} }
} }
var bound = { dx: dx, dy: dy, x: x, y: y, sx: sx, sw: sw, height: 0, width: 0 }; var bound = { dx: dx, dy: dy, x: x, y: y, height: 0, width: 0, offsetX: offsetX};
if (angle === 90 || angle === -90) { if (angle === 90 || angle === -90) {
bound.width = tm.height; bound.width = tm.height;
bound.height = textW; bound.height = textW;
} else { } else {
bound.height = Math.abs(Math.sin(angle / 180.0 * Math.PI) * textW) + (mul) * tm.height; bound.height = Math.abs(angleSin * textW) + Math.abs(angleCos * tm.height);
bound.width = Math.abs(Math.cos(angle / 180.0 * Math.PI) * textW) + Math.abs(Math.sin(angle / 180.0 * Math.PI) * tm.height); bound.width = Math.abs(angleCos * textW) + Math.abs(angleSin * tm.height);
// Делаем кратным 1pt // Делаем кратным 1pt
bound.height = asc_calcnpt(bound.height, 96); bound.height = asc_calcnpt(bound.height, 96);
} }
......
...@@ -2696,8 +2696,8 @@ ...@@ -2696,8 +2696,8 @@
wb = this.cols[col].width; wb = this.cols[col].width;
hb = this.rows[row].height; hb = this.rows[row].height;
txtRotX = ct.textBound.sx + xb1; txtRotX = xb1 - ct.textBound.offsetX;
txtRotW = ct.textBound.sw + xb1; txtRotW = ct.textBound.width + xb1 - ct.textBound.offsetX;
if ( isMerged ) { if ( isMerged ) {
...@@ -2791,12 +2791,12 @@ ...@@ -2791,12 +2791,12 @@
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;
txtRotX = ct.textBound.sx + xb1; txtRotX = xb1 - ct.textBound.offsetX;
txtRotW = ct.textBound.sw + xb1; txtRotW = ct.textBound.width + xb1 - ct.textBound.offsetX;
if ( isMerged ) { if ( isMerged ) {
...@@ -2871,12 +2871,25 @@ ...@@ -2871,12 +2871,25 @@
this.stringRender.rotateAtPoint( null, ct.angle, xb1, yb1, ct.textBound.dx, ct.textBound.dy ); 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.restoreInternalState( ct.state ).render( 0, 0, textW, ct.color );
// var color = new CColor(0, 0, 255, 0.5);
//
// ctx.setStrokeStyle(color).
// moveTo(0, 0).
// lineTo(ct.metrics.width, 0).
// lineTo(ct.metrics.width, ct.metrics.height).
// lineTo(0, ct.metrics.height).
// closePath().
// stroke();
this.stringRender.resetTransform( null ); this.stringRender.resetTransform( null );
if ( clipUse ) { if ( clipUse ) {
ctx.restore(); ctx.restore();
} }
// color = new CColor( 0, 0, 255, 0.5 );
// ctx.setStrokeStyle(color).strokeRect(xb1 - ct.textBound.offsetX, yb1, ct.textBound.width, ct.textBound.height);
} }
else { else {
ctx.save().beginPath().rect( x1, y1, w, h ).clip(); ctx.save().beginPath().rect( x1, y1, w, h ).clip();
......
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