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 Scott Moore <sc...@netdecide.com> on 2001/10/02 16:24:19 UTC
Text size
I'm using Batik directly in a Java program to create charts and graphs via SVG and transcoding them into PNG files. However, one of the problems I constantly face is how to determine the exact size of a text string. For instance, when drawing a legend, I need to know the size of the legend in order to properly size the graph next to it.
How do I solve this problem? Is there a way to do it directly in SVG? Is there an API in Batik that I can call to get the width of a string in a given font and size?
Any help would be much appreciated!
Scott
Re: Text size
Posted by Vincent Hardy <vi...@sun.com>.
Scott,
Unfortunately, there is no good way of doing this in SVG right now.
There are some round-about ways of using the SVG-DOM which would
provide some solution, but Batik does not support that part of the
SVG DOM yet.
I realize this is a disapointing answer. However, there are some tips
to position text:
a. Using text-anchor, you can center a text on a given position.
b. Using text-length, you can force a string of text to fit in a
given length.
c. Using filter effects, you can create boxes around a text area
if you use object bounding box units.
There are probably other tricks you can use, but these are the ones
from the top of my head. I use a with c. quite a bit and you can see an
example in moonPhases.svg:
<filter id="bgRect" primitiveUnits="objectBoundingBox" x="-.2" y="-.2"
width="1.4" height="1.4" >
<feFlood flood-color="black" flood-opacity=".5" result="bg"/>
...
<feMerge>
<feMergeNode in="bg" />
...
<feMergeNode in="SourceGraphic" />
</feMerge>
</filter>
I hope this helps.
Vincent.
> Scott Moore wrote:
>
> I'm using Batik directly in a Java program to create charts and graphs
> via SVG and transcoding them into PNG files. However, one of the
> problems I constantly face is how to determine the exact size of a
> text string. For instance, when drawing a legend, I need to know the
> size of the legend in order to properly size the graph next to it.
>
> How do I solve this problem? Is there a way to do it directly in
> SVG? Is there an API in Batik that I can call to get the width of a
> string in a given font and size?
>
> Any help would be much appreciated!
>
> Scott
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org