Hi James,

   To get back to your original question if all you want is the
bounding box of elements in the DOM, you can do this right with
the SVG DOM (svgelem.getBBox()).  The only advantage of this is
that you can using getElementById to avoid the need to walk the
whole tree.  Also using the SVG DOM you can even get the
location/size of individual glyphs from a text node.  Take a look
at:  samples/tests/spec/scripting/text_content.svg

James Shaw wrote:

Andres Toussaint wrote:

In order to get an instance of the GVT Tree, you need to assign a listener to a JSVGComponent, that will notify you when the GVT Tree is built. At this stage, you can walk the tree until you find the Component you are looking for.


Thankyou, Andres! I've used your code as a basis; I check (node instanceof TextNode), then use its TextPainter to obtain the bounding box.

Here's the code snippet, for anyone else who might have the same problem:

JSVGComponent svg = new JSVGComponent();
svg.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() {

   public void gvtBuildCompleted(GVTTreeBuilderEvent e) {
       GVTTreeWalker tw = new GVTTreeWalker(e.getGVTRoot());
       GraphicsNode node = tw.firstChild();
       while (node != null) {
           if (node instanceof TextNode) {
               TextPainter painter = ((TextNode)node).getTextPainter();
               Rectangle2D bbox = painter.getBounds2D((TextNode) node);
           }
                     node = tw.nextGraphicsNode();
       }
   }
});

svg.setSVGDocument(doc);

James Shaw

---------------------------------------------------------------------
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