xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Shaw <hertzsprrr...@btopenworld.com>
Subject Re: Obtaining glyph bounding box
Date Tue, 01 Feb 2005 17:32:34 GMT
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: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Mime
View raw message