xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andreas Neumann" <a.neum...@carto.net>
Subject Re: text width and height
Date Wed, 17 Sep 2008 07:43:05 GMT
Hi Tilo,

On every SVG element you can query the bounding box to get the width and
height: .getBBox() - this retunrns an SVGRect element with
x,y,width,height

You can use the SVGTextContentElement interface to query text related
stuff. The following methods may be of interest:

.getComputedTextLength()
.getExtentOfChar() (for individual glyphs)
.getStartPositionOfChar() (for individual glyphs)
.getEndePositionOfChar() (for individual glyphs)

and a couple more ...

See http://phrogz.net/ObjJob/object.asp?id=145 and
http://www.w3.org/TR/SVG11/text.html#DOMInterfaces

Andreas

> Hi @ all,
>
> on Java swing i can use the folowing code to get a text width and height:
>
> Font f = new Font("Arial", Font.BOLD, 1 );
> FontMetrics fm = getFontMetrics(f);
> int textWidth = fm.stringWidth("example text");
> int textHeight = fm.getHeight();
>
> proviede batike a equivalent how can i get the same information for a text
> in the SVG File.
>
> Many thanks for your help
>
> Tilo Behrmann
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>


-- 
Andreas Neumann
Böschacherstrasse 6, CH-8624 GrĂ¼t/Gossau, Switzerland
Email: a.neumann@carto.net, Web:
* http://www.carto.net/ (Carto and SVG resources)
* http://www.carto.net/neumann/ (personal page)
* http://www.svgopen.org/ (SVG Open Conference)
* http://www.geofoto.ch/ (Georeferenced Photos of Switzerland)


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


Mime
View raw message