From 95a8539045fe4dc90d411695695b39575e835d84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ju=CC=88rg=20Lehni?= Date: Fri, 2 Jan 2015 14:38:06 +0100 Subject: [PATCH] Fix size issue on non-resizable HiDPI canvases. Reverting back to original behavior in #586. --- src/view/CanvasView.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/view/CanvasView.js b/src/view/CanvasView.js index 59e23368..77ad4bf8 100644 --- a/src/view/CanvasView.js +++ b/src/view/CanvasView.js @@ -61,11 +61,21 @@ var CanvasView = View.extend(/** @lends CanvasView# */{ _setViewSize: function(size) { var element = this._element, - pixelRatio = this._pixelRatio; + pixelRatio = this._pixelRatio, + width = size.width, + height = size.height; // Upscale the canvas if the pixel ratio is more than 1. - element.width = size.width * pixelRatio; - element.height = size.height * pixelRatio; + element.width = width * pixelRatio; + element.height = height * pixelRatio; if (pixelRatio !== 1) { + // We need to set the correct size on non-resizable canvases through + // their style when HiDPI is active, as otherwise they would appear + // too big. + if (!PaperScope.hasAttribute(element, 'resize')) { + var style = element.style; + style.width = width + 'px'; + style.height = height + 'px'; + } // Scale the context to counter the fact that we've manually scaled // our canvas element. this._context.scale(pixelRatio, pixelRatio);