Re: Unit conversion of percentage values in the SVG DOM

On Tue, 7 Oct 2003 01:18:52 +1000, Dean Jackson <dean@w3.org> wrote:

>nearly ancient history, but better late than never....

I'm hoping that my other correspondents also subscribe to that
philosophy, as I, too, have a number of stale emails in my inbox
awaiting my replies....

>The enclosing viewport of the <rect> is defined by the <symbol>.

Exactly. That's the problem. The enclosing viewport is defined by the
symbol, but the dimensions of that viewport are determined at the
symbol's point of USE, not the point of its DEFINITION. (This follows
from the semantics of the <use> element as described in SVG 1.1 section
5.6.) Thus, you can't (meaningfully) convert a percentage to an absolute
length on any elements contained within a <symbol> element, because the
<symbol> element provides only the definition of the symbol, and not the
context of its use.

Here's a concrete example:

 <svg width="8cm" height="8cm" version="1.1"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink">
   <defs>
     <symbol id="mySymbol">
       <rect x="25%" y="25%" width="50%" height="50%"/>
     </symbol>
   </defs>
   <use x="2cm" y="1cm" width="4cm" height="2cm"
       xlink:href="#mySymbol"/>
   <use x="2cm" y="5cm" width="2cm" height="2cm"
       xlink:href="#mySymbol"/>
 </svg>

Here, the same symbol is used in two different contexts, and the
interpretation of "x='25%'" on the <rect> contained within the symbol is
different in those two contexts. In the first case, 25% resolves to 1cm,
while in the second it resolves to 0.5cm. And similarly for the width
attribute: 2cm vs. 1cm.

>I thought you said the 25% was displayed as 2cm.

No, I had said that the _width_ of the rectangle in the original code
snippet is displayed as 2cm; the x is displayed as 1cm.

Steve Schafer
Fenestra Technologies Corp
http://www.fenestra.com/

Received on Monday, 6 October 2003 12:49:09 UTC