[prev in list] [next in list] [prev in thread] [next in thread] 

List:       batik-users
Subject:    Re: bbox.getWidth() problem
From:       Thomas DeWeese <Thomas.DeWeese () Kodak ! com>
Date:       2003-10-30 12:45:41
[Download RAW message or body]

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:sly2616@yahoo.com] 
> Sent: Thursday, October 30, 2003 12:18 PM
> To: batik-users@xml.apache.org
> 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: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic