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

Re: return value of a function as attribute value?

From: Antoine Quint <ml@graougraou.com>
Date: Sun, 16 Feb 2003 17:50:46 +0100
Cc: www-svg@w3.org
To: Felix Breuer <felix@fbreuer.de>
Message-Id: <CB6E2C9E-41CE-11D7-A120-000393D124C4@graougraou.com>

Hi Felix,

> I want to have the position of an svg element calculated by the
> rendering application. E.g. consider the following document
>
> <svg id="svg-root" width="100%" height="100%" viewBox="0 0 80 60">
>    <g transform="translate(10,30)">
>      <text x="0" y="0">one</text>
>      <text x="number(../text[1]/@textLength())" y="0">two</text>
>    </g>
> </svg>
>
> Now my questions are:
>
> A) Is the above document a legal SVG document? I.e. does SVG 1.1 allow
> functions (which are defined by XPath) to be evaluated to yield the
> actual value of an attribute or do all attribute values have to be 
> given
> as explicit, literal numbers?

SVG 1.1 does not allow for XPath evaluation to be evaluated within an 
attribute value nor anywhere else in the document.

> B) If this is not a legal document, is there some way to accomplish 
> what
> I want? I.e. is there some way to determine the length of one text
> element and have the position of another text element depend on it?

You can indeed do it through scripting. You're going to want to look at 
the SVGTextContentElement interface within the SVG DOM.

http://www.w3.org/TR/SVG/text.html#DOMInterfaces

In there there is a method to get the length of a string using the 
getComputedTextLength() method. You can also obtain substring length 
and so on. I have written an article on doing simple text wrapping with 
SVG 1.0 and DOM scripting on XML.com, there is some code explained here 
that uses the getComputedTextLength() method:

http://www.xml.com/pub/a/2002/09/11/quint.html

Hope you can get some help from there.

Antoine
-- 
Antoine Quint <antoine.quint@fuchsia-design.com>
SVG Consultant & Research Engineer, Fuchsia Design
W3C SVG Working Group Invited Expert
Journal - http://www.svg.org/blogs/graouts/
Received on Sunday, 16 February 2003 11:53:23 GMT

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