W3C home > Mailing lists > Public > www-svg@w3.org > September 2003

Unit conversion of percentage values in the SVG DOM

From: Steve Schafer <steve@fenestra.com>
Date: Fri, 19 Sep 2003 11:35:39 -0400
To: www-svg@w3.org
Message-ID: <jf8mmvs6ecu3jaipakagjbmqrq22amvdae@4ax.com>

Consider the following simple example:

 <svg width="8cm" height="4cm" version="1.1"
     <symbol id="mySymbol">
       <rect x="25%" y="25%" width="50%" height="50%"/>
   <use x="2cm" y="1cm" width="4cm" height="2cm"

This renders just fine, of course; it results in a 2cm x 1cm black
rectangle centered in the 8cm x 4cm viewport.

Now imagine that our user agent supports manipulation of the SVG object
tree via the DOM. We can get at the <rect> element with code that looks
something like this:

 defsElement = (SVGDefsElement)doc.documentElement.firsChild;
 symbolElement = (SVGSymbolElement)defsElement.firstChild;
 rectElement = (SVGRectElement)symbolElement.firstChild;

So far so good. But what if we do this:


That is, we're asking for the originally specified length percentage
("25%") to be converted to an absolute length in centimetres. The
problem is that inside a <symbol> element inside a <defs> element, the
enclosing viewport of the <rect> is not well-defined.

So what do we do? The easy way out is to go ahead and use the viewport
established by the <svg> element enclosing the <rect> (which means that
"25%" will be converted to "2cm"). This has the undesirable effect of
changing the appearance of the rendered document--a result that would be
unexpected from a simple change in units.

Another possibility is to raise an exception, but the description for
SVGLength.convertToSpecifiedUnits states "No Exceptions."

These are the only two things I can think of. Any other ideas?

Steve Schafer
Fenestra Technologies Corp
Received on Friday, 19 September 2003 11:41:30 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 March 2017 09:46:57 UTC