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

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.

Cheers,
Niko

Received on Monday, 16 April 2012 10:21:29 UTC