Baron, Randy {PRG~Basel} wrote:

Hi,
   Maybe you have to wait until the rendereing is completed in order to
call the getWidth() function?  I had a similar problem and solved it by
sticking the code inside a GVTTreeRendererAdapter, something like:

Hi John, Randy,


   Randy, you have the right idea but I don't think he is displaying the
SVG at all.  So he doesn't have a JSVGComponent to display with
(or to register the listener with).

   John, what you want to do is build the GVT tree (the rendering tree
that contains all of the geometric information).  A good example of
how this is done can be seen in the slideshow application.  The
basic areas of interest are the constructor (lines 108-111) and
the Render thread where it actually builds the GVT tree (lines 149, 156).

   One major difference is that you will need to tell the BridgeContext
to build a 'dynamic' document:

ctx.setDynamicState(BridgeContext.DYNAMIC);

GVTTreeRendererAdapter gvtadap =  new GVTTreeRendererAdapter() {
       public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
           RunnableQueue rq =
someCanvas.getUpdateManager().getUpdateRunnableQueue();
           if (rq != null) {
              rq.invokeLater(new Runnable() {
                 public void run() {
                      // do your getWidth call here.
                 }
              });
           }
       }
}

-Randy

-----Original Message-----
From: john doe [mailto:[EMAIL PROTECTED] Sent: Thursday, October 30, 2003 12:18 PM
To: [EMAIL PROTECTED]
Subject: bbox.getWidth() problem



Hello,


I'm developing a java web application which generates
svg using Batik's SVG DOM library. Therefore I need to get the width of text elements to
wrap text dynamically while generating the svg
document.
The problem is that when I try to get the bounding box
of a text element a NullPointerException is thrown.


Here is the part of my source code which throws the
exception:
...
if (textElement instanceof SVGLocatable) {
SVGRect bbox = ((SVGLocatable)textElement).getBBox();
System.out.println(bbox.getWidth()); // <-- exception
}
...

Here is the interesting part of the thrown exception:
java.lang.NullPointerException at
org.apache.batik.dom.svg.SVGLocatableSupport$1.getWidth(Unknown
Source)
....

Any help and suggestions to solve the problem is
greatly appreciated!

Thanks,
Stefan

__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/

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





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to