[whatwg] Canvas patterns, and miscellaneous other things

Philip Taylor excors+whatwg at gmail.com
Sat Jun 23 10:49:47 PDT 2007

What should happen if you try drawing a 0x0-pixel repeating pattern?
(I can't find a way to make a 0x0 image that any browser will load,
but the spec says you can make a 0x0 canvas. Firefox and Opera can't
make a 0x0 canvas - it acts like it's 300x150 pixels instead. Safari
returns null from createPattern when it's 0x0.)

On a somewhat related note: What should "canvas.width = canvas.height
= 0; canvas.toDataURL()" do, given that you can never make a valid 0x0
PNG? (Firefox and Opera make the canvas 300x150 pixels instead, so you
can't actually get it that small. Safari can make it that small, but
doesn't implement toDataURL.)

Similarly, what should toDataURL do when the canvas is really large
and the browser doesn't want to give you a data URI? (Opera returns
'undefined' if it's >= 30001 pixels in any dimension, and crashes if
it's 30000 in each dimension. Firefox (2 and trunk) crashes or hangs
on Linux if it's >= 32768 pixels in any dimension, and crashes on
Windows if it's >= 65536 pixels).

More generally, the spec says "If the user agent does not support the
requested type, it must return the image using the PNG format" - what
if it does support the requested type, but still doesn't want to give
you a data URI, e.g. because it's the wrong size (too large, too
small, not a multiple of 4, etc) or because of other environmental
factors (e.g. it wants you to do
getContext('vendor-2d').enableVectorCapture() before
toDataURL('image/svg+xml'))? (Presumably it would be some combination
of falling back to PNG (if you asked for something else), returning
undefined, and throwing exceptions.)

"If the empty string or null is specified, repeat must be assumed." -
why allow null, but not undefined or missing? (It would seem quite
reasonable for createPattern(img) to default to a repeating pattern).
(Currently all implementations throw exceptions for undefined/missing,
and Opera and Safari throw for null.)

'complete' for images is underspecified, so it's not possible to test
the related createPattern/drawImage requirements. (Is it set before
onload is called? Can it be set as soon as the Image() constructor
returns? Can it be set at an arbitrary point during execution of the
script that called the Image() constructor? Is it reset when you
change src? etc. Implementations all seem to disagree in lots of

About radial gradients: "If x0 = x1 and y0 = y1 and r0 = r1, then the
radial gradient must paint nothing." - that conflicts with the
previous "must" for following the algorithm, so it's not precise about
which you must do. It should probably say "If ... then the radial
gradient must paint nothing. Otherwise, radial gradients must be
rendered by following these steps:".

"<code title="dom-attr-complete">complete</code>" (twice) - looks like
it should be dom-img-complete, so it points to #complete.

"createPattern(image, repetition)" - the parameters should be in <var>s.

"The images are not be scaled by this process" - s/be //

"interface HTMLCanvasElement : HTMLElement {
          attribute unsigned long width;
          attribute unsigned long height;"
 ^ incorrect indentation (should have two more spaces).

Somewhere totally unrelated:
"interface HTMLDetailsElement : HTMLElement {
   attribute boolean open;"
 ^ incorrect indentation (should have nine more spaces).

Philip Taylor
excors at gmail.com

More information about the whatwg mailing list