Prevent issues with repeated PaperScript execution on same canvas and HiDPI related scaling.

This commit is contained in:
Jürg Lehni 2013-11-24 23:08:08 +01:00
parent da9e1f8de7
commit 02f46b7ac2

View file

@ -59,14 +59,15 @@ var View = Base.extend(Callback, /** @lends View# */{
}; };
DomEvent.add(window, this._windowHandlers); DomEvent.add(window, this._windowHandlers);
} else { } 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 // If the element is invisible, we cannot directly access
// element.width / height, because they would appear 0. // element.width / height, because they would appear 0.
// Reading the attributes still works. // Reading the attributes should still work.
size = new Size(parseInt(element.getAttribute('width'), 10), if (size.isNaN() || size.isZero())
parseInt(element.getAttribute('height'), 10)); size = new Size(parseInt(element.getAttribute('width'), 10),
// If no size was specified on the canvas, read it from CSS parseInt(element.getAttribute('height'), 10));
if (size.isNaN())
size = DomElement.getSize(element);
} }
// Set canvas size even if we just deterined the size from it, since // 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 // it might have been set to a % size, in which case it would use some