You don't need to render the document but you need to build the rendering tree as this contains all the geometry information. When you build the GVT (using a Dynamic BridgeContext) it associates the rendering tree with the DOM.
OK. So I could skip the renderer.updateOffScreen() call, or even more?
It isn't clear where m_doc is coming from. I suspect that this is not a Batik Document. I say that because I would be surprised if the JXPathContext would work with any old DOM (but I could be wrong). If all you are using XPath for is looking up by 'id' you can use 'getElementById'.
No, m_doc is a Batik SVGDocument, all valid and actually transcoded to a PNG before this testing code is called.
XPath is just a copy-paste artefact - it was useful elsewhere, for looking up namespace-attributes. (Yes, XPath seems to work fine with the Batik SVGDocument, and pretty much any DOM. Very handy, if you want to do more comples lookups.) But you're right, in this case I can simplify things with getElementById().
What is the class type of the Box returned by getBBox?
A bit of debugging gives me... org.apache.batik.dom.svg.SVGLocatableSupport
What is the stack trace of the NPE?
2003-11-27 15:52:22,128 [Thread-17] ERROR net.basen.dig.generator.svgmaps.SVGMapGenerator - SVG generation failed: java.lang.NullPointerException
java.lang.NullPointerException
at org.apache.batik.dom.svg.SVGLocatableSupport$1.getX(SVGLocatableSupport.java:67) at net.basen.dig.generator.svgmaps.DynamicMap.extractLinkAreas(DynamicMap.java:424)
...
I compiled Batik with debug=on and dug in a bit deeper. Line 67 is:
return (float)svgelt.getSVGContext().getBBox().getX();
and the null exception is thrown because svgelt.svgContext is null. So, despite the attempt to do the association, looks like I'm not accomplishing some necessary bit. What sets the SVGContext of contained elements? Is there something missing in the rendering tree association, perhaps? (I've copied the code, with the element lookup change, below.)
public List extractLinkAreas( int width, int height )
{
// Testing
UserAgent userAgent = new UserAgentAdapter();
DocumentLoader loader = new DocumentLoader(userAgent);
BridgeContext bctx = new BridgeContext(userAgent, loader);
bctx.setDynamicState(BridgeContext.DYNAMIC);
GVTBuilder builder = new GVTBuilder();
GraphicsNode gvtRoot = builder.build(bctx, m_doc);
StaticRenderer renderer = new StaticRenderer();
renderer.setTree(gvtRoot);
Element elt = m_doc.getRootElement();
renderer.setTransform(ViewBox.getViewTransform(null, elt, width, height));
renderer.updateOffScreen( width, height );
// End testing
for( int i = 0; i < m_icons.size(); i++ )
{
IconData id = (IconData)m_icons.get(i);
Element potentialLinkArea = (Element)m_doc.getElementById( id.getTemplateName() );
if( id.getLinkTarget() != null &&
potentialLinkArea instanceof SVGLocatable )
{
SVGRect box = ((SVGLocatable)potentialLinkArea).getBBox();
log.debug( "Element " + id.getIconName() + " X: " +
box.getX() + " Y: " + box.getY() + " w: " +
box.getWidth() + " h: " + box.getHeight() );
}
}
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]