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: AW: text width and height
Date Wed, 17 Sep 2008 08:21:17 GMT
I only know how to do this with ECMAScript/Javascript. I am not a Java
programmer, but it should work similarly.

Suppose you have:

<text id="myText" x="20" y="50">Some Text</text>

in ECMAScript you would do the following:

var myTextContent = document.getElementById("myText").firstChild;
var textLength = myTextContent.getComputedTextLength;

for the bounding box:
var myText = document.getElementById("myText");
var bbox = myText.getBBox();
//you can access the individual values with bbox.x, bbox.y, bbox.width,
bbox.height

I am sure it easy for you as a java programmer to do the same in Java. It
uses the same interfaces.

Andreas



> Have you a example with the SVGTextContentElement interface.
>
> -----Ursprüngliche Nachricht-----
> Von: Andreas Neumann [mailto:a.neumann@carto.net]
> Gesendet: Mittwoch, 17. September 2008 09:43
> An: t.Behrmann@gmx.net
> Cc: Batik User
> Betreff: Re: text width and height
>
>
> 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
>
>
> ---------------------------------------------------------------------
> 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