You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Dmitrij Sakara <dm...@epfl.ch> on 2004/12/09 19:54:06 UTC

Height and width of a text element.

Hi all.

 

I have some SVG document and would like to insert some text element and
rectangle as a border of the text. The problem is that I can't define
the size of the text (bounding box) before it is to the document and
rendered. Is there some method to obtain height and width of the text
element before it is rendered and even inserted into a document? I have
the filling that this should be a frequent problem.
 
 

___________________________________________
 
Dmitrij SAKARA

STI IPR LICP
Swiss Federal Institute of Technology (EPFL)
Me - Ecublens
CH-1015 Lausanne
Switzerland
 
Tel. : +41 (0)21 / 693 5913
Fax. : +41 (0)21 / 693 3509

e-mail : dmitrij.sakara@epfl.ch

My office at EPFL: http://map.epfl.ch/?room=MEA1382
___________________________________________

 

Re: Height and width of a text element.

Posted by Thomas DeWeese <Th...@Kodak.com>.
Dmitrij Sakara wrote:

> I have some SVG document and would like to insert some text element and 
> rectangle as a border of the text. The problem is that I can’t define 
> the size of the text (bounding box) before it is to the document and 
> rendered. Is there some method to obtain height and width of the text 
> element before it is rendered and even inserted into a document? I have 
> the filling that this should be a frequent problem.

    As soon as the text is inserted into a 'Dynamic' document
you can use the getBBox call to get it's x,y,width & height.
You can't get this information before it is in the rendered
portion of the document because there is not 'graphics peer'.  Also
before it is in the document you couldn't do this since you can't
do the CSS cascade and percentage units wouldn't have a viewport
to reference.

    If you run your code in the update manager you can be sure
that there will not be a rendering until your runnable completes.
So you can append the text, get it's BBox, create your rect and
position it in the document and the complete change will be
rendered atomically.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org