W3C home > Mailing lists > Public > www-svg@w3.org > April 2012

Re: 'image' and 'foreignObject' with 'viewBox' attribute?

From: Dirk Schulze <dschulze@adobe.com>
Date: Sun, 15 Apr 2012 07:28:58 -0700
To: Nikolas Zimmermann <zimmermann@kde.org>
CC: SVG public list <www-svg@w3.org>
Message-ID: <A468E150-9A6A-486C-9297-B6B1FBB5204D@adobe.com>

On Apr 15, 2012, at 2:01 AM, Nikolas Zimmermann wrote:

> 
> Am 15.04.2012 um 00:28 schrieb Dirk Schulze:
> 
>> Hi,
>> 
>> The section "7.7 The ‘viewBox’ attribute"[1] has the following definition: "All elements that establish a new viewport (see elements that establish viewports), plus the ‘marker’, ‘pattern’ and ‘view’ elements have attribute ‘viewBox’."
>> 
>> Elements that establish viewports are [2]:
>> 	• The ‘svg’ element
>> 	• A ‘symbol’ element define new viewports whenever they are instanced by a ‘use’ element.
>> 	• An ‘image’ element that references an SVG file will result in the establishment of a temporary new viewport since the referenced resource by definition will have an ‘svg’ element.
>> 	• A ‘foreignObject’ element creates a new viewport for rendering the content that is within the element.
>> 
>> Therefore the specification demands that 'foreingObject'[3] as well as 'image'[4] (referencing an SVG file) should allow the attribute 'viewBox'. But none of the element definitions allow the attribute 'viewBox'.
> 
> That's partially correct, you can't specify a viewBox manually on an image, but in the text it states how to figure out the viewBox for an <image> element pretty clearly:
> 
> The value of the ‘viewBox’ attribute to use when evaluating the ‘preserveAspectRatio’ attribute is defined by the referenced content. For content that clearly identifies a viewBox (e.g. an SVG file with the ‘viewBox’ attribute on the outermost svg element) that value should be used. For most raster content (PNG, JPEG) the bounds of the image should be used (i.e. the‘image’ element has an implicit ‘viewBox’ of '0 0 raster-image-width raster-image-height'). Where no value is readily available (e.g. an SVG file with no ‘viewBox’ attribute on the outermost svg element) the ‘preserveAspectRatio’ attribute is ignored, and only the translation due to the ‘x’ & ‘y’ attributes of the viewport is used to display the content.
> 
> As image element support the pAR attribute, they must define a viewBox to be able to resolve the pAR.
> Specifying a viewBox directly on a <image> element is unsupported - either there's an implicit viewBox provided by the extents of the referenced image, or by the outermost <svg> element, when referencing an external SVG file.
> 

So the fix is quite easy. Just use the term 'viewBox' without 'attribute' like done later in the specification text, where the text explicitly differs between 'viewBox' and the 'viewBox' attribute?:

"a ‘viewBox’ does not affect the ‘x’, ‘y’, ‘width’ and ‘height’ attributes (or in the case of the‘marker’ element, the ‘markerWidth’ and ‘markerHeight’ attributes) on the element with the ‘viewBox’ attribute."

Dirk

> Cheers,
> Niko
> 
Received on Sunday, 15 April 2012 14:29:35 GMT

This archive was generated by hypermail 2.3.1 : Friday, 8 March 2013 15:54:50 GMT