[webkit-dev] Support for SVG preserveAspectRatio in <img>

Leif Arne Storset lstorset at opera.com
Wed Feb 3 05:12:09 PST 2010


Eric Seidel <eric at webkit.org> skreiv Tue, 02 Feb 2010 21:04:33 +0100

> Definitely a bug.
>
> Some of these are on file, some are not:
> http://webkit.org/quality/reporting.html

Thanks, Eric and Dean, for your feedback. I have reported bug 34521 [1].  
Hopefully I will be able to host the test case soon. Best of luck on  
implementation! Feel free to ask me if you have questions or concerns.

-Leif Arne

[1] https://bugs.webkit.org/show_bug.cgi?id=34521

> On Tue, Feb 2, 2010 at 8:17 AM, Leif Arne Storset <lstorset at opera.com>  
> wrote:
>> Hello,
>>
>> While doing some SVG-related work over here I discovered that WebKit's
>> rendering of SVG in <img> tags differs from Opera's. Since WebKit and
>> Opera to my knowledge are the only engines that currently support SVG in
>> <img> we thought it would be worthwhile to make sure we are compatible.
>>
>> As far as I can tell from the latest nightly builds (and the latest  
>> Chrome
>> release on Linux), WebKit will render an SVG in <img> much like a  
>> bitmap:
>> it will resolve the width and height of the image and stretch it to fill
>> the content box. It will respect any viewbox (presumably synthesizing  
>> one
>> if it is missing), but preserveAspectRatio [1] seems not to be applied  
>> to
>> an SVG in <img>, and the default rendering (whether there is a viewbox  
>> or
>> not) is as if preserveAspectRatio="none".
>>
>> Opera (Presto engine) will also resolve image dimensions and synthesize
>> missing viewboxes, and will synthesize a viewBox if it can, as outlined
>> in SVG WG ISSUE-2258 [2], and applies preserveAspectRatio as specified  
>> in
>> SVG 1.1 (note that pAR has a default value 'xMidYMid meet'). The viewBox
>> (whether specified or synthetic) are used together with pAR when  
>> rendering
>> the SVG into the viewport established by the <img> element.
>>
>> The attached images and test case illustrate the two renderings.
>>
>> A quick Google search of webkit.org revealed little on  
>> preserveAspectRatio
>> except a reference to a 2008 bug in SVGImageElement. However, for
>> <svg:image> (that is: <image> elements inside of an <svg>), pAR seems to
>> be applied as per the spec.
>>
>> We believe that not applying the pAR on svg in <img> means that WebKit
>> has invalid rendering behaviour according to the SVG 1.1 specification.
>>
>> To enhance cross-browser compatibility it would be good if WebKit also
>> considered synthesizing viewBoxes as outlined in [2], as this makes it
>> easier to reuse existing svg content created by svg editors such as
>> Inkscape (such content most often has a width and height, but lacks a
>> viewBox).
>>
>> I hope you find these recommendations useful. Please let me know if I  
>> can
>> be of further assistance. If desired I can file a bug in your issue
>> tracker.
>>
>> --
>> Leif Arne Storset
>> Layout developer, Opera Software
>>
>> [1] http://www.w3.org/TR/SVG11/coords.html#PreserveAspectRatioAttribute
>> [2] http://www.w3.org/Graphics/SVG/WG/track/issues/2258
>> _______________________________________________
>> webkit-dev mailing list
>> webkit-dev at lists.webkit.org
>> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev
>>
>>
>


-- 
Leif Arne


More information about the webkit-dev mailing list