From 02f46b7ac214c993e28ab6e831875b52ec0fdb01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 24 Nov 2013 23:08:08 +0100 Subject: [PATCH] Prevent issues with repeated PaperScript execution on same canvas and HiDPI related scaling. --- src/ui/View.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ui/View.js b/src/ui/View.js index 56475a3b..401effbd 100644 --- a/src/ui/View.js +++ b/src/ui/View.js @@ -59,14 +59,15 @@ var View = Base.extend(Callback, /** @lends View# */{ }; DomEvent.add(window, this._windowHandlers); } else { + // Try visible size first, since that will help handling previously + // scaled canvases (e.g. when dealing with ratio) + size = DomElement.getSize(element); // If the element is invisible, we cannot directly access // element.width / height, because they would appear 0. - // Reading the attributes still works. - size = new Size(parseInt(element.getAttribute('width'), 10), - parseInt(element.getAttribute('height'), 10)); - // If no size was specified on the canvas, read it from CSS - if (size.isNaN()) - size = DomElement.getSize(element); + // Reading the attributes should still work. + if (size.isNaN() || size.isZero()) + size = new Size(parseInt(element.getAttribute('width'), 10), + parseInt(element.getAttribute('height'), 10)); } // Set canvas size even if we just deterined the size from it, since // it might have been set to a % size, in which case it would use some