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.


   I think it would be almost impossible to do this with XSLT.
You really need an engine that understands SVG to get something
that will work with most content.  The Batik engine has all the
pieces needed to do this but while several people have asked
about it no one has done the work.

Abandoned the transformation idea. 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.


Does the following code make any sense?
It still throws a NullPointerException at the box.getX() stage. Should I be accessing something else than the SVGDocument Nodes?


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



Reply via email to