Re: Text 'width' and 'height' [was: Happy New Year SVGers]

Hi Jan,

At 10:15 AM 1/11/00 +0100, Jan Aarsaether wrote:
>Chris Lilley wrote:
>> I just wanted to wish all SVG users and implementors a Happy New
>> Vectorial Year,
>Likewise :->
>> and keep those reports of new or updated implementations, use cases,
>> examples, and any sort of spec feedback coming in!
>SVG is a big language (there must be a loooooot of people on the SVG
>committee :-) with lots of alternative ways of doing the same thing.
>But we are now getting close to finishing the job of converting our
>symbol format into SVG. However, we're having trouble with the <text>
>We are not just rendering vector symbols, but creating primitives
>which the user can modify interactively using our symbol editor. In
>the <text> case, it is even possible for the system to change the
>content of the text whenever properties/criteria change (macros).
>Because of this, it is common to 'reserve' a certain rectangular space
>for the <text> element to fit into the rest of the symbol and our
>system does wrapping and clipping within this rectangle before
>painting the primitive.

At the very start of discussions about what features should go into SVG
1.0, the working group decided that fitting text into a rectangle or other
shape was out-of-scope. (You can see the SVG Requirements document at Look at item 10g.) We very explicitly
limited SVG 1.0 to straight-line text and text-on-a-path. This decision was
based on: (a) the fact that we wanted to focus SVG 1.0 on lower-level
constructs, (b) other languages (e.g., XHTML) already do text-wrapping, (c)
SVG is designed to allow XHTML snippets to be placed inside of an SVG
'foreignObject' (of course, don't hold your breadth waiting for
implementations to support this feature) and (d) we thought we had plenty
of features to specify without doing text wrapping/fitting.

>But, SVG only specifies 'x' and 'y' attributes on <text>. We need
>'width' and 'height' (similar to the <rect> element) to be able to
>persistently store our information using SVG. This is especially
>important with 'right' and 'bottom' adjusted texts. We also use the
>rectangle actively by allowing the user to control the background
>color, but we can do without this feature.
>We realize that (most?) SVG renders can do without these additional
>attributes, but I would expect other applications to have similar
>needs as described above. Has anybody stumbled upon this before? Is
>there any chance of appending this to the SVG specs? If not, we would
>have to resort to some kind of hack :-< Or maybe there is some way of
>doing this in the existing specs which we haven't found. Tips and
>feedback would be highly appreciated!

I have two ideas for you to consider:

1) Maybe there is something you can achieve with clever use of CSS units,
values expressed as percentages, viewports established via embedded 'svg'
elements and transformations. (You might say this sounds like a hack.)

2) Download ECMAScript (i.e., JavaScript) embedded inside of the SVG
document which uses the SVG DOM to move/resize objects to fit the text. I
know that the folks at RAL have done a schematics application using
JavaScript and SVG, where the boxes grow automatically to fit the text
inside of the box. Note that the SVG DOM has an interface
SVGTextContentElement, which is a base class for SVGTextElement, and there
are methods 'getLength()' and 'getSubStringLength()', which should prove
very useful to your application.

Jon Ferraiolo
SVG Editor
Adobe Systems Incorporated

>Jan Aarsaether
>METIS GUI Development	
>NCR Norge AS

Received on Tuesday, 11 January 2000 11:10:00 UTC