From 5ac1502ccd03cc857f5398225cc8f52c1344853d Mon Sep 17 00:00:00 2001 From: Antoine Vandecreme Date: Mon, 24 Oct 2016 22:03:31 +0200 Subject: [PATCH] Take pixelDensityRatio into account when rotating --- src/drawer.js | 22 +++++++++++++--------- src/tiledimage.js | 30 ++++++++++++++++++------------ 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/drawer.js b/src/drawer.js index 7029320d..9440c280 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -477,13 +477,14 @@ $.Drawer.prototype = { context.fillStyle = this.debugGridColor; if ( this.viewport.degrees !== 0 ) { - this._offsetForRotation(this.viewport.degrees); + this._offsetForRotation({degrees: this.viewport.degrees}); } if (tiledImage.getRotation() !== 0) { - this._offsetForRotation( - tiledImage.getRotation(), - tiledImage.viewport.pixelFromPointNoRotate( - tiledImage._getRotationPoint(true), true)); + this._offsetForRotation({ + degrees: tiledImage.getRotation(), + point: tiledImage.viewport.pixelFromPointNoRotate( + tiledImage._getRotationPoint(true), true) + }); } context.strokeRect( @@ -588,13 +589,16 @@ $.Drawer.prototype = { }, // private - _offsetForRotation: function(degrees, point, useSketch) { - point = point || this.getCanvasCenter(); - var context = this._getContext(useSketch); + _offsetForRotation: function(options) { + var point = options.point ? + options.point.times($.pixelDensityRatio) : + this.getCanvasCenter(); + + var context = this._getContext(options.useSketch); context.save(); context.translate(point.x, point.y); - context.rotate(Math.PI / 180 * degrees); + context.rotate(Math.PI / 180 * options.degrees); context.translate(-point.x, -point.y); }, diff --git a/src/tiledimage.js b/src/tiledimage.js index 12d62950..c6659c77 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -1573,15 +1573,18 @@ function drawTiles( tiledImage, lastDrawn ) { // avoid interpolation if (!sketchScale) { if (tiledImage.viewport.degrees !== 0) { - tiledImage._drawer._offsetForRotation( - tiledImage.viewport.degrees, useSketch); + tiledImage._drawer._offsetForRotation({ + degrees: tiledImage.viewport.degrees, + useSketch: useSketch + }); } if (tiledImage._degrees !== 0) { - tiledImage._drawer._offsetForRotation( - tiledImage._degrees, - tiledImage.viewport.pixelFromPointNoRotate( + tiledImage._drawer._offsetForRotation({ + degrees: tiledImage._degrees, + point: tiledImage.viewport.pixelFromPointNoRotate( tiledImage._getRotationPoint(true), true), - useSketch); + useSketch: useSketch + }); } } @@ -1663,15 +1666,18 @@ function drawTiles( tiledImage, lastDrawn ) { if (useSketch) { if (sketchScale) { if (tiledImage.viewport.degrees !== 0) { - tiledImage._drawer._offsetForRotation( - tiledImage.viewport.degrees, false); + tiledImage._drawer._offsetForRotation({ + degrees: tiledImage.viewport.degrees, + useSketch: false + }); } if (tiledImage._degrees !== 0) { - tiledImage._drawer._offsetForRotation( - tiledImage._degrees, - tiledImage.viewport.pixelFromPointNoRotate( + tiledImage._drawer._offsetForRotation({ + degrees: tiledImage._degrees, + point: tiledImage.viewport.pixelFromPointNoRotate( tiledImage._getRotationPoint(true), true), - false); + useSketch: false + }); } } tiledImage._drawer.blendSketch({