[whatwg] Canvas - Somewhat inconsistent rules in the spec for drawImage
ian at hixie.ch
Wed Oct 16 15:48:48 PDT 2013
On Fri, 20 Sep 2013, Simon Sarris wrote:
> Summary: You can draw zero-sized Images and objects with zero-sized
> source rects to the canvas context. You cannot draw zero-sized Canvases,
> you get an InvalidStateError. According to the spec this is right, but I
> think there should be more consistency in handling these cases.
> The bothersome thing is that:
> 1. Zero-sized Images do not have any such error
I didn't actually think you could create a zero-sized image that was not
in the broken state. But you can, using SVG, in some browsers:
Safari and Chrome don't treat it as 0x0, but Firefox does.
Firefox throws an exception when you try to use it in drawImage(), just
like with a zero-dimension <canvas>.
> 2. calling drawImage with a source rectangle, using
> context.drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh), when the
> source rectangle has zero width or height, does not give an error. Per
> the spec: [...]
> So zero-sized sources are fine if they are an HTMLImageElement or a
> source rectangle, but not fine if they are HTMLCanvasElement.
Zero-sized source rectangles were fine with <canvas> too. It's the actual
<canvas> itself that matters here.
On Sat, 21 Sep 2013, Robert O'Callahan wrote:
> I agree. I commented on this a while ago, and I still think it's simpler
> and more robust for drawing a zero-size "anything" to just draw nothing.
I've changed the spec to allow it explicitly for both images and canvases.
Ian Hickson U+1047E )\._.,--....,'``. fL
http://ln.hixie.ch/ U+263A /, _.. \ _\ ;`._ ,.
Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'
More information about the whatwg