Re: Text measurement

Bonjour Nathalie,

On 23 mars 04, at 16:16, ndumas@insa-rouen.fr wrote:

> i'm actually having a hard time finding information about how to 
> measure a
> string (or a sentence) once a font has been applied.
>
> that is, what is the length of a sentence (in px or so) once it is 
> written
> in a certain font of a certain weigth ?

This is quite simple. There are two mehtods you can call on your <text> 
element:

- getComputedTextLength(): takes into account internationalization 
issues (vertical text for instance)
- getBBox(): just gives you the raw bbox

Antoine
-- 
Antoine Quint <aq@fuchsia-design.com>
W3C SVG Working Group Invited Expert
SVG Consulting, Teaching and Outsourcing

Received on Tuesday, 23 March 2004 10:11:17 UTC