Commit c1588d5b authored by Alexander.Trofimov's avatar Alexander.Trofimov Committed by Alexander.Trofimov

Частично поправил баг http://bugzserver/show_bug.cgi?id=25606

Четко рисуем 1px-ю сетку и границы (несмотря на zoom)

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@57760 954022d7-b5bf-4e40-9824-e11837661b57
parent 23a1a928
...@@ -415,8 +415,6 @@ ...@@ -415,8 +415,6 @@
this.scaleFactor = 1; this.scaleFactor = 1;
this._1px_x = getCvtRatio(0/*px*/, 3/*mm*/, this.ppiX);
this._1px_y = getCvtRatio(0/*px*/, 3/*mm*/, this.ppiY);
this.units = 3/*mm*/; this.units = 3/*mm*/;
this.changeUnits(undefined !== settings.units ? settings.units : this.units); this.changeUnits(undefined !== settings.units ? settings.units : this.units);
...@@ -551,8 +549,6 @@ ...@@ -551,8 +549,6 @@
this._mct.sx = getCvtRatio(i, 0/*px*/, this.ppiX); this._mct.sx = getCvtRatio(i, 0/*px*/, this.ppiX);
this._mct.sy = getCvtRatio(i, 0/*px*/, this.ppiY); this._mct.sy = getCvtRatio(i, 0/*px*/, this.ppiY);
this._calcMFT(); this._calcMFT();
this._1px_x = getCvtRatio(0/*px*/, i, this.ppiX);
this._1px_y = getCvtRatio(0/*px*/, i, this.ppiY);
this.units = units; this.units = units;
return this; return this;
}; };
...@@ -784,6 +780,15 @@ ...@@ -784,6 +780,15 @@
return this; return this;
}; };
DrawingContext.prototype.clearRectByX = function (x, y, w, h) {
var r = this._calcRect(x, y, w, h);
this.ctx.clearRect(r.x - 1, r.y, r.w + 1, r.h);
};
DrawingContext.prototype.clearRectByY = function (x, y, w, h) {
var r = this._calcRect(x, y, w, h);
this.ctx.clearRect(r.x, r.y - 1, r.w, r.h + 1);
};
// Font and text methods // Font and text methods
DrawingContext.prototype.getFont = function () { DrawingContext.prototype.getFont = function () {
...@@ -1020,10 +1025,28 @@ ...@@ -1020,10 +1025,28 @@
return this; return this;
}; };
// Отрисовка на 1px меньше
DrawingContext.prototype.lineHorPrevPx = function (x1, y, x2) {
var isEven = (0 !== this.ctx.lineWidth % 2 ? 0.5 : 0) - 1;
var r1 = this._calcRect(x1, y);
var r2 = this._calcRect(x2, y);
this.ctx.moveTo(r1.x, r1.y + isEven);
this.ctx.lineTo(r2.x, r2.y + isEven);
return this;
};
DrawingContext.prototype.lineVerPrevPx = function (x, y1, y2) {
var isEven = (0 !== this.ctx.lineWidth % 2 ? 0.5 : 0) - 1;
var r1 = this._calcRect(x, y1);
var r2 = this._calcRect(x, y2);
this.ctx.moveTo(r1.x + isEven, r1.y);
this.ctx.lineTo(r2.x + isEven, r2.y);
return this;
};
DrawingContext.prototype.dashLineCleverHor = function (x1, y, x2) { DrawingContext.prototype.dashLineCleverHor = function (x1, y, x2) {
var w_dot = c_oAscCoAuthoringDottedWidth, w_dist = c_oAscCoAuthoringDottedDistance; var w_dot = c_oAscCoAuthoringDottedWidth, w_dist = c_oAscCoAuthoringDottedDistance;
var _x1 = this._mct.transformPointX(x1, y); var _x1 = this._mct.transformPointX(x1, y);
var _y = this._mct.transformPointY(x1, y); var _y = this._mct.transformPointY(x1, y) - 1;
var _x2 = this._mct.transformPointX(x2, y); var _x2 = this._mct.transformPointX(x2, y);
var ctx = this.ctx; var ctx = this.ctx;
...@@ -1044,7 +1067,7 @@ ...@@ -1044,7 +1067,7 @@
DrawingContext.prototype.dashLineCleverVer = function (x, y1, y2) { DrawingContext.prototype.dashLineCleverVer = function (x, y1, y2) {
var w_dot = c_oAscCoAuthoringDottedWidth, w_dist = c_oAscCoAuthoringDottedDistance; var w_dot = c_oAscCoAuthoringDottedWidth, w_dist = c_oAscCoAuthoringDottedDistance;
var _y1 = this._mct.transformPointY(x, y1); var _y1 = this._mct.transformPointY(x, y1);
var _x = this._mct.transformPointX(x, y1); var _x = this._mct.transformPointX(x, y1) - 1;
var _y2 = this._mct.transformPointY(x, y2); var _y2 = this._mct.transformPointY(x, y2);
var ctx = this.ctx; var ctx = this.ctx;
...@@ -1189,15 +1212,15 @@ ...@@ -1189,15 +1212,15 @@
DrawingContext.prototype._calcRect = function (x, y, w, h) { DrawingContext.prototype._calcRect = function (x, y, w, h) {
var wh = w !== undefined && h !== undefined, var wh = w !== undefined && h !== undefined,
x2 = x + w - this._1px_x, x2 = x + w,
y2 = y + h - this._1px_y, y2 = y + h,
_x = this._mft.transformPointX(x, y), _x = this._mft.transformPointX(x, y),
_y = this._mft.transformPointY(x, y); _y = this._mft.transformPointY(x, y);
return { return {
x: asc_round(_x), x: asc_round(_x),
y: asc_round(_y), y: asc_round(_y),
w: wh ? asc_round(this._mft.transformPointX(x2, y2) - _x + 1) : undefined, w: wh ? asc_round(this._mft.transformPointX(x2, y2) - _x) : undefined,
h: wh ? asc_round(this._mft.transformPointY(x2, y2) - _y + 1) : undefined h: wh ? asc_round(this._mft.transformPointY(x2, y2) - _y) : undefined
}; };
}; };
......
...@@ -44,21 +44,15 @@ function CPdfPrinter(sUrlPath) ...@@ -44,21 +44,15 @@ function CPdfPrinter(sUrlPath)
this.DocumentRenderer.VectorMemoryForPrint = new CMemory(); this.DocumentRenderer.VectorMemoryForPrint = new CMemory();
this.font = new window["Asc"].FontProperties("Arial", -1); this.font = new window["Asc"].FontProperties("Arial", -1);
this.asc_round = window["Asc"].round;
this.Transform = new CMatrix(); this.Transform = new CMatrix();
this.InvertTransform = new CMatrix(); this.InvertTransform = new CMatrix();
this.sUrlPath = sUrlPath; this.sUrlPath = sUrlPath;
var ppiTest =
$('<div style="position: absolute; width: 10in; height:10in; ' +
'visibility:hidden; padding:0;"/>')
.appendTo("body");
this.dpiX = this.asc_round(ppiTest[0] ? (ppiTest[0].offsetWidth * 0.1) : 96);
this.dpiY = this.asc_round(ppiTest[0] ? (ppiTest[0].offsetHeight * 0.1) : 96);
ppiTest.remove();
this.bIsSimpleCommands = false; this.bIsSimpleCommands = false;
this.width_1px = 0.75;
this.height_1px = 0.75;
} }
CPdfPrinter.prototype = CPdfPrinter.prototype =
...@@ -340,6 +334,20 @@ CPdfPrinter.prototype = ...@@ -340,6 +334,20 @@ CPdfPrinter.prototype =
this.DocumentRenderer._l(x * vector_koef, y2 * vector_koef); this.DocumentRenderer._l(x * vector_koef, y2 * vector_koef);
return this; return this;
}, },
lineHorPrevPx : function (x1, y, x2)
{
y -= this.height_1px;
this.DocumentRenderer._m(x1 * vector_koef, y * vector_koef);
this.DocumentRenderer._l(x2 * vector_koef, y * vector_koef);
return this;
},
lineVerPrevPx : function (x, y1, y2)
{
x -= this.width_1px;
this.DocumentRenderer._m(x * vector_koef, y1 * vector_koef);
this.DocumentRenderer._l(x * vector_koef, y2 * vector_koef);
return this;
},
rect : function(x, y, w, h) rect : function(x, y, w, h)
{ {
......
...@@ -1019,11 +1019,11 @@ ...@@ -1019,11 +1019,11 @@
if (isSO) { if (isSO) {
dy += 1; dy += 1;
y = asc_calcnpt(y1 + l.bl - prop.lm.a * 0.275, ppiy); y = asc_calcnpt(y1 + l.bl - prop.lm.a * 0.275, ppiy);
ctx.lineHor(x1, y - dy * h_1px, x2 + w_1px); ctx.lineHor(x1, y - dy * h_1px, x2 + w_1px); // ToDo вопрос тут
} }
if (ul) { if (ul) {
y = asc_calcnpt(y1 + l.bl + prop.lm.d * 0.4, ppiy); y = asc_calcnpt(y1 + l.bl + prop.lm.d * 0.4, ppiy);
ctx.lineHor(x1, y + dy * h_1px, x2 + w_1px); ctx.lineHor(x1, y + dy * h_1px, x2 + w_1px); // ToDo вопрос тут
} }
ctx.stroke(); ctx.stroke();
} }
......
...@@ -570,7 +570,6 @@ ...@@ -570,7 +570,6 @@
WorksheetView.prototype.changeZoom = function (isUpdate) { WorksheetView.prototype.changeZoom = function (isUpdate) {
if (isUpdate) { if (isUpdate) {
this.cleanSelection(); this.cleanSelection();
this._initConstValues();
this._initCellsArea(false); this._initCellsArea(false);
this._normalizeViewRange(); this._normalizeViewRange();
this._cleanCellsTextMetricsCache(); this._cleanCellsTextMetricsCache();
...@@ -587,7 +586,6 @@ ...@@ -587,7 +586,6 @@
}; };
WorksheetView.prototype.changeZoomResize = function () { WorksheetView.prototype.changeZoomResize = function () {
this.cleanSelection(); this.cleanSelection();
this._initConstValues();
this._initCellsArea(true); this._initCellsArea(true);
this._normalizeViewRange(); this._normalizeViewRange();
this._cleanCellsTextMetricsCache(); this._cleanCellsTextMetricsCache();
...@@ -2091,8 +2089,10 @@ ...@@ -2091,8 +2089,10 @@
var ctx = (drawingCtx) ? drawingCtx : this.drawingCtx; var ctx = (drawingCtx) ? drawingCtx : this.drawingCtx;
var st = this.settings.header.style[style]; var st = this.settings.header.style[style];
var x2 = x + w - this.width_1px; var x2 = x + w;
var y2 = y + h - this.height_1px; var y2 = y + h;
var x2WithoutBorder = x2 - this.width_1px;
var y2WithoutBorder = y2 - this.height_1px;
// background только для видимых // background только для видимых
if (!isZeroHeader) { if (!isZeroHeader) {
...@@ -2106,15 +2106,17 @@ ...@@ -2106,15 +2106,17 @@
.beginPath(); .beginPath();
if (style !== kHeaderDefault && !isColHeader) { if (style !== kHeaderDefault && !isColHeader) {
// Select row (top border) // Select row (top border)
ctx.lineHor(x, y - this.height_1px, x2 + this.width_1px); ctx.lineHorPrevPx(x, y, x2);
} }
// Right border // Right border
ctx.lineVer(x2, y, y2); ctx.lineVerPrevPx(x2, y, y2);
// Bottom border // Bottom border
ctx.lineHor(x, y2, x2 + this.width_1px); ctx.lineHorPrevPx(x, y2, x2);
if (style !== kHeaderDefault && isColHeader) { if (style !== kHeaderDefault && isColHeader) {
// Select col (left border) // Select col (left border)
ctx.lineVer(x - this.width_1px, y, y2 + this.height_1px); ctx.lineVerPrevPx(x, y, y2);
} }
ctx.stroke(); ctx.stroke();
...@@ -2126,9 +2128,9 @@ ...@@ -2126,9 +2128,9 @@
var text = isColHeader ? this._getColumnTitle(index) : this._getRowTitle(index); var text = isColHeader ? this._getColumnTitle(index) : this._getRowTitle(index);
var sr = this.stringRender; var sr = this.stringRender;
var tm = this._roundTextMetrics( sr.measureString(text) ); var tm = this._roundTextMetrics( sr.measureString(text) );
var bl = y2 - (isColHeader ? this.defaultRowDescender : this.rows[index].descender); var bl = y2WithoutBorder - (isColHeader ? this.defaultRowDescender : this.rows[index].descender);
var textX = this._calcTextHorizPos(x, x2, tm, tm.width < w ? khaCenter : khaLeft); var textX = this._calcTextHorizPos(x, x2WithoutBorder, tm, tm.width < w ? khaCenter : khaLeft);
var textY = this._calcTextVertPos(y, y2, bl, tm, kvaBottom); var textY = this._calcTextVertPos(y, y2WithoutBorder, bl, tm, kvaBottom);
if (drawingCtx) { if (drawingCtx) {
ctx.AddClipRect(x, y, w, h); ctx.AddClipRect(x, y, w, h);
ctx.setFillStyle(st.color) ctx.setFillStyle(st.color)
...@@ -2157,9 +2159,8 @@ ...@@ -2157,9 +2159,8 @@
var colStartTmp = Math.max(this.visibleRange.c1, colStart); var colStartTmp = Math.max(this.visibleRange.c1, colStart);
var colEndTmp = Math.min(this.visibleRange.c2, colEnd); var colEndTmp = Math.min(this.visibleRange.c2, colEnd);
for (i = colStartTmp; i <= colEndTmp; ++i) { for (i = colStartTmp; i <= colEndTmp; ++i) {
this.drawingCtx.clearRect( this.drawingCtx.clearRectByX(this.cols[i].left - offsetX, this.headersTop,
this.cols[i].left - offsetX - this.width_1px, this.headersTop, this.cols[i].width, this.headersHeight);
this.cols[i].width + this.width_1px, this.headersHeight);
} }
if (0 !== cFrozen) { if (0 !== cFrozen) {
offsetX = this.cols[0].left - this.cellsLeft; offsetX = this.cols[0].left - this.cellsLeft;
...@@ -2167,9 +2168,8 @@ ...@@ -2167,9 +2168,8 @@
colStart = Math.max(0, colStart); colStart = Math.max(0, colStart);
colEnd = Math.min(cFrozen, colEnd); colEnd = Math.min(cFrozen, colEnd);
for (i = colStart; i <= colEnd; ++i) { for (i = colStart; i <= colEnd; ++i) {
this.drawingCtx.clearRect( this.drawingCtx.clearRectByX(this.cols[i].left - offsetX, this.headersTop,
this.cols[i].left - offsetX - this.width_1px, this.headersTop, this.cols[i].width, this.headersHeight);
this.cols[i].width + this.width_1px, this.headersHeight);
} }
} }
}; };
...@@ -2188,9 +2188,8 @@ ...@@ -2188,9 +2188,8 @@
for (i = rowStartTmp; i <= rowEndTmp; ++i) { for (i = rowStartTmp; i <= rowEndTmp; ++i) {
if (this.height_1px > this.rows[i].height) if (this.height_1px > this.rows[i].height)
continue; continue;
this.drawingCtx.clearRect( this.drawingCtx.clearRectByY(this.headersLeft, this.rows[i].top - offsetY,
this.headersLeft, this.rows[i].top - offsetY - this.height_1px, this.headersWidth, this.rows[i].height);
this.headersWidth, this.rows[i].height + this.height_1px);
} }
if (0 !== rFrozen) { if (0 !== rFrozen) {
offsetY = this.rows[0].top - this.cellsTop; offsetY = this.rows[0].top - this.cellsTop;
...@@ -2200,9 +2199,8 @@ ...@@ -2200,9 +2199,8 @@
for (i = rowStart; i <= rowEnd; ++i) { for (i = rowStart; i <= rowEnd; ++i) {
if (this.height_1px > this.rows[i].height) if (this.height_1px > this.rows[i].height)
continue; continue;
this.drawingCtx.clearRect( this.drawingCtx.clearRectByY(this.headersLeft, this.rows[i].top - offsetY,
this.headersLeft, this.rows[i].top - offsetY - this.height_1px, this.headersWidth, this.rows[i].height);
this.headersWidth, this.rows[i].height + this.height_1px);
} }
} }
}; };
...@@ -2249,17 +2247,17 @@ ...@@ -2249,17 +2247,17 @@
.setLineWidth(1).beginPath(); .setLineWidth(1).beginPath();
var w, h; var w, h;
for (var i = range.c1, x = x1 - this.width_1px; i <= range.c2 && x <= x2; ++i) { for (var i = range.c1, x = x1; i <= range.c2 && x <= x2; ++i) {
w = c[i].width; w = c[i].width;
x += w; x += w;
if (w >= this.width_1px) if (w >= this.width_1px)
ctx.lineVer(x, y1, y2); ctx.lineVerPrevPx(x, y1, y2);
} }
for (var j = range.r1, y = y1 - this.height_1px; j <= range.r2 && y <= y2; ++j) { for (var j = range.r1, y = y1; j <= range.r2 && y <= y2; ++j) {
h = r[j].height; h = r[j].height;
y += h; y += h;
if (h >= this.height_1px) if (h >= this.height_1px)
ctx.lineHor(x1, y, x2); ctx.lineHorPrevPx(x1, y, x2);
} }
ctx.stroke(); ctx.stroke();
...@@ -3018,26 +3016,25 @@ ...@@ -3018,26 +3016,25 @@
fHorLine = ctx.dashLineCleverHor; fHorLine = ctx.dashLineCleverHor;
fVerLine = ctx.dashLineCleverVer; fVerLine = ctx.dashLineCleverVer;
} else { } else {
fHorLine = ctx.lineHor; fHorLine = ctx.lineHorPrevPx;
fVerLine = ctx.lineVer; fVerLine = ctx.lineVerPrevPx;
} }
// ToDo заделать отрисовку lock области
if (this.topLeftFrozenCell) { if (this.topLeftFrozenCell) {
var row = this.topLeftFrozenCell.getRow0(); var row = this.topLeftFrozenCell.getRow0();
var col = this.topLeftFrozenCell.getCol0(); var col = this.topLeftFrozenCell.getCol0();
if (0 < row) if (0 < row)
fHorLine.apply(ctx, [0, this.rows[row].top - this.height_1px, ctx.getWidth()]); fHorLine.apply(ctx, [0, this.rows[row].top, ctx.getWidth()]);
else else
fHorLine.apply(ctx, [0, this.headersHeight - this.height_1px, this.headersWidth]); fHorLine.apply(ctx, [0, this.headersHeight, this.headersWidth]);
if (0 < col) if (0 < col)
fVerLine.apply(ctx, [this.cols[col].left - this.width_1px, 0, ctx.getHeight()]); fVerLine.apply(ctx, [this.cols[col].left, 0, ctx.getHeight()]);
else else
fVerLine.apply(ctx, [this.headersWidth - this.width_1px, 0, this.headersHeight - this.height_1px]); fVerLine.apply(ctx, [this.headersWidth, 0, this.headersHeight]);
} else if (this.model.sheetViews[0].asc_getShowRowColHeaders()) { } else if (this.model.sheetViews[0].asc_getShowRowColHeaders()) {
fHorLine.apply(ctx, [0, this.headersHeight - this.height_1px, this.headersWidth]); fHorLine.apply(ctx, [0, this.headersHeight, this.headersWidth]);
fVerLine.apply(ctx, [this.headersWidth - this.width_1px, 0, this.headersHeight - this.height_1px]); fVerLine.apply(ctx, [this.headersWidth, 0, this.headersHeight]);
} }
ctx.stroke(); ctx.stroke();
...@@ -3240,8 +3237,8 @@ ...@@ -3240,8 +3237,8 @@
fHorLine = ctx.dashLineCleverHor; fHorLine = ctx.dashLineCleverHor;
fVerLine = ctx.dashLineCleverVer; fVerLine = ctx.dashLineCleverVer;
} else { } else {
fHorLine = ctx.lineHor; fHorLine = ctx.lineHorPrevPx;
fVerLine = ctx.lineVer; fVerLine = ctx.lineVerPrevPx;
} }
var firstCol = oIntersection.c1 === visibleRange.c1 && !isAllRange; var firstCol = oIntersection.c1 === visibleRange.c1 && !isAllRange;
...@@ -3252,10 +3249,10 @@ ...@@ -3252,10 +3249,10 @@
var drawTopSide = oIntersection.r1 === range.r1; var drawTopSide = oIntersection.r1 === range.r1;
var drawBottomSide = oIntersection.r2 === range.r2; var drawBottomSide = oIntersection.r2 === range.r2;
var x1 = c[oIntersection.c1].left - offsetX - this.width_1px; var x1 = c[oIntersection.c1].left - offsetX;
var x2 = c[oIntersection.c2].left + c[oIntersection.c2].width - offsetX - this.width_1px; var x2 = c[oIntersection.c2].left + c[oIntersection.c2].width - offsetX;
var y1 = r[oIntersection.r1].top - offsetY; var y1 = r[oIntersection.r1].top - offsetY;
var y2 = r[oIntersection.r2].top + r[oIntersection.r2].height - offsetY - this.height_1px; var y2 = r[oIntersection.r2].top + r[oIntersection.r2].height - offsetY;
ctx.setLineWidth(lineWidth).setStrokeStyle(strokeColor); ctx.setLineWidth(lineWidth).setStrokeStyle(strokeColor);
if (fillColor) if (fillColor)
...@@ -3263,24 +3260,24 @@ ...@@ -3263,24 +3260,24 @@
ctx.beginPath(); ctx.beginPath();
if (drawTopSide && !firstRow) if (drawTopSide && !firstRow)
fHorLine.apply(ctx, [x1 + this.width_1px, y1 - this.height_1px, x2 + this.width_1px]); fHorLine.apply(ctx, [x1, y1, x2]);
if (drawBottomSide) if (drawBottomSide)
fHorLine.apply(ctx, [x1 + this.width_1px, y2, x2 + this.width_1px]); fHorLine.apply(ctx, [x1, y2, x2]);
if (drawLeftSide && !firstCol) if (drawLeftSide && !firstCol)
fVerLine.apply(ctx, [x1, y1 - this.width_1px * !firstRow, y2 + this.width_1px]); fVerLine.apply(ctx, [x1, y1, y2]);
if (drawRightSide) if (drawRightSide)
fVerLine.apply(ctx, [x2, y1, y2]); fVerLine.apply(ctx, [x2, y1, y2]);
// Отрисовка квадратов для move/resize // Отрисовка квадратов для move/resize
if (fillColor) { if (fillColor) {
if (drawLeftSide && drawTopSide) if (drawLeftSide && drawTopSide)
ctx.fillRect(x1 + this.width_1px, y1, this.width_4px, this.height_4px); ctx.fillRect(x1 - this.width_1px, y1 - this.height_1px, this.width_4px, this.height_4px);
if (drawRightSide && drawTopSide) if (drawRightSide && drawTopSide)
ctx.fillRect(x2 - this.width_4px, y1, this.width_4px, this.height_4px); ctx.fillRect(x2 - this.width_4px, y1 - this.height_1px, this.width_4px, this.height_4px);
if (drawRightSide && drawBottomSide) if (drawRightSide && drawBottomSide)
ctx.fillRect(x2 - this.width_4px, y2 - this.height_4px, this.width_4px, this.height_4px); ctx.fillRect(x2 - this.width_4px, y2 - this.height_4px, this.width_4px, this.height_4px);
if (drawLeftSide && drawBottomSide) if (drawLeftSide && drawBottomSide)
ctx.fillRect(x1 + this.width_1px, y2 - this.height_4px, this.width_4px, this.height_4px); ctx.fillRect(x1 - this.width_1px, y2 - this.height_4px, this.width_4px, this.height_4px);
} }
ctx.closePath().stroke(); ctx.closePath().stroke();
......
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