Re: Are percentage lengths relative to viewport or viewbox?

Oleg,

You're correct that percentage lengths and coordinates within the drawing
are defined relative to the viewBox height and width.

I agree that the wording in the specifications is unclear.

The term viewport is used rather inconsistently in
http://www.w3.org/TR/SVG11/coords.html (and the corresponding SVG2
drafts).  Sometimes it is used to refer to the area in which the viewBox is
fitted, sometimes it is used to refer to the viewport element that
establishes the local coordinate system (with or without a viewBox
attribute), and sometimes to the local viewport as modified by the viewBox.

The viewBox transformation is currently only mentioned in the last
paragraph of the Units section:

> Note that the width and height of the viewport in the user coordinate
> system for the viewport element (in this case, the outermost svg element
> <http://www.w3.org/TR/SVG11/intro.html#TermOutermostSVGElement>) are 4000
> and 2000, respectively, because processing the ‘viewBox’
> <http://www.w3.org/TR/SVG11/coords.html#ViewBoxAttribute> attribute
> results in a transformed user coordinate system.


And that isn't a very clear example, because in that case the percentage
values would work out the same regardless of whether you were using viewBox
or viewport (ie, width and height of the <svg>).

-- AmeliaBR

On 29 December 2014 at 03:11, Олег Максименко <olegmax@gmail.com> wrote:

>
> Reading Specification 1.1 I get the idea that percentage length values are
> defined as relative to the viewport, and viewbox/preserveAspectRatio is
> just some handy feature that is mapped to transformation.
> But playing with some SVG implementations I found that percentages are
> actually relative to viewbox (it become apparent when aspect ratio is
> changed by viewbox/preserveAspectRatio) and replacing viewbox attribute
> with corresponding transformations doesn't work when percentage lengths are
> used in descendant elements.
> E.g. in sample
> http://www.w3.org/TR/SVG/images/coords/PreserveAspectRatio.svg viewport
> is blue rectangle, but rect(0,0,100%,100%) will coincide with red rectangle
> of viewbox.
> Am I missing some nuance in specification?
>
> Thank you,
> Oleg
>

Received on Monday, 29 December 2014 19:02:48 UTC