xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thomas.dewe...@kodak.com
Subject Re: Text IN a path
Date Tue, 06 Nov 2007 10:50:42 GMT
Hi Jonn,

jon321 <jonn.farr@covalentsoftware.com> wrote on 10/26/2007 11:26:08 AM:

> 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.
> So say I have a path drawing this shape, how do I get the center of it 
> 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 
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.

View raw message