How to know the length of text in SVG (in advance) ??

P

Peter Jakobi

Hello,

I want to write a program, which will build automatically a chart with
SVG from some data. In the chart there are several arrows with text.

Now I am confronted with a problem: How can I know the length of the
text in advance?? How long does the arrow have to be? The complete text
must be placed above the arrow.

Does anybody have an idea?? How can I know how much place the text will
need in the SVG??

Thanks,
Pet
 
J

Joris Gillis

Hi,

Tempore 10:20:13 said:
How can I know how much place the text will
need in the SVG??
When you have access to the SVG DOM, you can use the 'getComputedTextLength()' method to get the length of an existing SVGTextContentElement object.

When your program does not interact with an SVG renderer (no acces to the DOM), you could try the following:

a) use a fixed-width font
b) calculate a maximum value by multiplying the width of the largest charachter ('M') with the number of characters
c) use another program to estimate the length of the text-string in a specific font.

regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,811
Messages
2,569,693
Members
45,477
Latest member
IsidroSeli

Latest Threads

Top