Thomas DeWeese wrote:
You would need to get the area associated with an 'a' element and export that as a polygon for the client side image map.
As first approximation, I'm making do with just finding the bounding box of an SVG element and using that to produce the coords for a client-side image map tag.
Right now I'm looking at some older list emails and the slideshow example application, trying to figure out whether I'll be able to do a Locatable.getBBox() call on a named element. I get that you need to render the document first, somehow, but I'm a bit confused about whether and when the SVGDocument gets updated.
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.
Does the following code make any sense?
It makes some :)
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'.
It still throws a NullPointerException at the box.getX() stage. Should I be accessing something else than the SVGDocument Nodes?
No that part seems about right. I suspect that for some reason the nodes in m_doc are not the ones that Batik is using (it might copy the document so it uses the Batik DOM implementation).
What is the class type of the Box returned by getBBox?
What is the stack trace of the NPE?
(This is very messy; don't anyone try to use as is.)
m_doc contains a valid SVGDocument with id'ed nodes. I am able to render it elsewhere. m_icons contains information about clickable items; the main things are the id (same as that of an SVG element) and the link target.
public void extractLinkAreas( int width, int height ) { // BridgeContext / Renderer setup swiped from slideshow demo. 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); // Some of the above may be superfluous.
// Find SVG elements corresponding to our IconData entries: JXPathContext ctx = JXPathContext.newContext(m_doc); ctx.setLenient(true); for( int i = 0; i < m_icons.size(); i++ ) { IconData id = (IconData)m_icons.get(i); Pointer templatePtr = ctx.getPointer( "id('" + id.getTemplateName() + "')" ); Node potentialLinkArea = (Node)templatePtr.getNode(); // If a link target is associated, get the clickable area. if( id.getLinkTarget() != null && potentialLinkArea instanceof SVGLocatable ) { SVGRect box = ((SVGLocatable)potentialLinkArea).getBBox(); // Collect into list here... 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]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]