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]



Reply via email to