Thanks for the reply TJ.

I'm writing a process that creates an SVG image.  I don't think I can get 
access to the SVGLocatable instance.  The good news is I know exactly how wide 
the bounding box in the image is.  I just need a way of determining the width 
of the text when batik paints it, so I know if it will fit in the available 
space.  

It seems FontMetrics class returns a different value then the actual width.  I 
was able to determine that it works better for some characters and not for 
others.  For example, X and T overflow, but q works fine (even though 
FontMetrics.stringWidth() returns the same value for each of those characters).

Thanks,

Tom

 -----Original Message-----
From:   TJ Teegan [mailto:[EMAIL PROTECTED] 
Sent:   Tuesday, December 28, 2004 11:51 AM
To:     [email protected]
Subject:        RE: calculating the width of text

Hello,

I have never had to do this, so I am not sure how well my suggestion will 
work.  Perhaps someone with more experience can chime in and tell you if 
this would work or not.

I think you can get the bounding box for the image you want to cover, and 
then use that width to determine how much space you have.  To determine how 
much space your text will take get the bounding box for the text element.  
Then adjust your text until its boudnding box matches the images bounding 
box.  I think to get the bounding boxes you should look at the SVGLocatable 
interface in the org.w3c.dom.svg package.

There may be better, or more efficient ways to do this.  I am just 
paraphrasing something I read in this list awhile back.

Hope it helps,
TJ Teegan

>From: "Litton, Tom - CEPM" <[EMAIL PROTECTED]>
>Reply-To: "Batik Users" <[email protected]>
>To: "Batik Users" <[email protected]>
>Subject: calculating the width of text
>Date: Mon, 27 Dec 2004 16:52:56 -0600
>
>I'm trying to calculate the amount of text that can fit into a specified 
>width on an SVG image.  My calculations are based on the 
>FontMetrics.stringWidth method.
>
>For example, I have some text I want to put into a space that is 250 units 
>long.  The FontMetrics.stringWidth gives 249 for the width of the text, 
>however, the text overruns in the image.
>
>I'm assuming this is because the SVG image and the FontMetrics.stringWidth 
>are returning coordinates in different units (or a bug in my code.  Can't 
>ever rule that out).  I believe FontMetrics.stringWidth uses pixels (please 
>correct me if I'm wrong).  What does SVG use by default?  It should be 
>pixels correct?
>
>Is there a reason why the text doesn't line up?  Is there an easier way of 
>determining what text will fit in a given space?
>
>Thanks,
>
>Tom

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to