CanvasRenderingContext2D.createPattern does not specify image sizing behavior for SVG
In the case where the image passed to createPattern() does not have an intrinsic size, as is the case with svg source images, there needs to be a specified default sizing behavior.
The most straightforward approach would be to use the same sizing algorithm as drawImage(), but that would mean that the pattern size would be dependent on the size of the canvas whose context was used to create the pattern. Maybe that is is okay, or even desirable? Currently, a workaround that avoids unspecified behavior would be to bake the image at a specific resolution using an intermediate canvas.
I don't feel terribly qualified to have an opinion here, but the context-dependent behavior seems reasonably desirable to me.
Is this something we can get guidance from shipping implementations on?
I created a fiddle: https://jsfiddle.net/11anLvjq/1/ to see what is shipping.
In Chrome, the viewBox attribute of the svg ends up being used as an intrinsic size for the image. Kinda makes sense, but this paradigm ignores the "s" in "svg". Also, the edges of the drawing are too blurry, which suggests the image was resampled, meaning the intermediate rasterization was probably done at another resolution.
In Firefox, the call to createPattern throws a NS_ERROR_NOT_AVAILABLE
IE chokes at image load time. Have not figured out why. Probably some incompatible markup detail in the SVG file.
For consistency with how SVG images are sized in every other image context (backgrounds, border-image, markers, shapes, etc) using the default sizing algorithm is the reasonable choice, with the canvas scratch bitmap size as the default object size.
That said, for patterns, it gets a bit silly since the pattern size will be a contain constraint resolved against the canvas size (given an intrinsic aspect ratio) and thus rather big for actual tiling on said canvas. Not sure if this is a real problem.
Using the viewBox for intrinsic size is unprecedented (usually it just provides aspect ratio) in other contexts as far as I know, and just something Blink and WebKit happens to do lacking other options historically.
FYI, https://codereview.chromium.org/1767633002/ is up in relation to this in Blink.
Anyone want to speak on behalf of other (non-Blink) implementations on this issue?
@jetvillegas, can you comment on this?