[whatwg] Size of SVG->Img->Canvas
Tab Atkins Jr.
jackalmage at gmail.com
Thu Nov 17 15:21:27 PST 2011
On Thu, Nov 17, 2011 at 2:56 PM, Gavin Kistner <gkistner at nvidia.com> wrote:
> Imagine an SVG file displayed in an img: <img id="i" src="my.svg" ... >
>
> The SVG file can have an explicit size (height and width attributes, in a variety of CSS units), or it can have no size (defaulting to "100%"). Whether or not the SVG file has explicit units, it may have an intrinsic aspect ratio (via the viewBox attribute).
>
> The img can have an explicit size (height and width attributes) or no size. Separate from these, it may or may not have a separate display size (CSS units).
>
> Now imagine that the user draws this img to a canvas:
>
> myCanvasContext.drawImage( document.querySelector('#i'), 0, 0 );
>
> In each of the eight combinations of (img heightwidth/CSS heightwidth/SVG heightwidth) being present or not, what are the intrinsic dimensions of the "image" drawn to the canvas?
> (Should it always use the raster bitmap created for the img? Should it re-rasterize the sourced SVG at the specified height/width?)
>
> I have a test page showing current behavior here: http://phrogz.net/SVG/svg_to_img_to_canvas.html
>
> Note: Firefox has bug 700533 that currently prevents it from drawing the image to the canvas when the SVG has no height/width.
> https://bugzilla.mozilla.org/show_bug.cgi?id=700533
>
> Note: Chrome v16 on Win7 produces non-deterministic results when the SVG has no height/width; each reload can result in different appearance of the SVG-in-img. This may be bug 16167.
> https://bugs.webkit.org/show_bug.cgi?id=16167
drawImage() pays attention only to the dimensions of the actual image,
not the <img> element.
The correct behavior would be to lean on the sizing algorithm at
<http://dev.w3.org/csswg/css3-images/#default-sizing>. All that needs
to be done is to define the "default object size", which is presumably
the size of the canvas. The 5- and 9-argument cases also define the
"specified size" for the algorithm.
~TJ
More information about the whatwg
mailing list