List Info

Thread: Re: Text IN a path




Re: Text IN a path
country flaguser name
United States
2007-11-06 04:50:42

Hi Jonn,

jon321 <jonn.farrcovalentsoftware.com&gt; wrote on 10/26/2007 11:26:08 AM:

&gt; I have a complex svg file that draws a map with various areas. I want to
> programmatically label these areas using batik. Ideally what I want to do is
> put a text label in the center of the area.
&gt; So say I have a path drawing this shape, how do I get the center of it and
> apply a text label to it?

   Assuming you have booted the SVG DOM (see the Wiki if you don't know
what I mean).  They you can use getBBox on just about any SVG element
and it will tell you the location of that element in it's local coordinate
system.  Then it's a trivial matter to calculate it's geometric center.

   However, this is occasionally not useful for mapping applications where the
shape of the element may be such that the geometric center is outside
of the filled region for the shape.  Handling these cases automatically
is far from trivial, so I am forced to leave you with a problem rather
than a solution.

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )