Scott Neufeld wrote:
> 
> If you're working in Java, there are a couple of text characteristic classes
> that can help you determine the true length of a line of characters,
> provided that the font exists on the system running the JVM.

Unfortunately that requires more work than meets the eye in the general
case since the text is typically subjected to further transformation by
Java2d in order to apply <text> attributes - it will work only if the
text is not being modified via textLength, letterSpacing, etc. and if
the text is not modified by a filter.  Since java2d's builtin text
layout API doesn't support all that SVG includes, some of the details of
how this is done via java2d are Batik-specific.

The short answer is that in the absence of size constraints on the text
via textLength you cannot know how large the text is until it is
rendered by the target textRenderer - this is because font metrics are
installation-specific.  The 'SVG font' mechanism gives you known font
metrics, because SVG fonts are fonts which are contained within the SVG
file (or in a referenced URI) and in which each glyph is described as an
SVG element.  So, if you are the source of the font (via SVG font) then
you know its size, otherwise you can only "specify" its size (via the
nominal font size in pixels, points, or whatever, in the vertical
direction, and via textLength in the horizontal direction).  The only
way to know the actual bounding box is by asking the textPainter (which
will then have to do most of the work that would be required to render
the text, in order to compute the resulting bounds).

You can query the bounding box of an element (including a text element)
via GVT (various org.apache.batik.gvt.GraphicsNode.getBounds() methods),
in the case of text this should call the underlying TextSpanLayout and
TextPainter routines to do this for you and return the result.  However
the result depends on the TextRenderer, so you must have specified the
target TextRenderer instance first in order to get the correct result.

-Bill 

> -----Original Message-----
> From: Chris Lilley
> To: Batik Users
> Sent: 10/7/01 4:02 PM
> Subject: Re: Text size
> 
> Scott Moore wrote:
> > From: "Chris Lilley" <[EMAIL PROTECTED]>
> > > If you use an SVG font you can iterate through the string and tell
> the
> > > exact width of it by adding all the glyph widths.
> >
> > Oh yeah?  Is this API in Batik?  How do I use it?
> 
> I assumed that this was about generating content to be displayed in
> Batik, not restricted to using Batik as the content generation tool as
> well.
> 
> You can get at the information using the XML DOM, its just attribute
> values.
> 
> --
> Chris
> 
> ---------------------------------------------------------------------
> 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]

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

Reply via email to