kangax/fabric.js — Issue #75: More robust way to create canvas element width and height
Author: nanodocumet
Created: 2011-11-08 23:09:36+00:00
State: open

Current way to apply `width` and `height` when using `_applyCanvasStyle` [https://github.com/kangax/fabric.js/blob/master/src/canvas.class.js#L329] is with:

var width = this.getWidth() || element.width,
height = this.getHeight() || element.height;

which defaults back to width = 300 and height = 150 if no `width` or `height` are set.

The following approach will also consider when the `width` and `height` have been set using the style method instead of the attribute values, defaulting back to canvas defaults if nothing is set:

var width = this.getWidth() || element.getAttribute('width') || parseInt(element.style.width, 10) || element.width,
height = this.getHeight() || element.getAttribute('height') || parseInt(element.style.height, 10) || element.height;

Tested in Chrome, FF 1.6, IE8 Under Windows 7 Home Premium.

I know that the standard just mentions that the `width` and `height` should use the values from the attributes, but it mentions that the element can also be sized arbitrarily by a style sheet, thus, I was thinking that this could still be valid.

Thanks,

Nano.