xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas DeWeese <Thomas.DeWe...@Kodak.com>
Subject Re: SVGContext is null
Date Wed, 08 Sep 2004 09:41:11 GMT
Hi Urs,

Urs Reupke wrote:

> yesterday I hit upon a problem when trying to get the computed text 
> length by calling SVGOMTextElement.getComputedTextLength() - a 
> NullPointerException occured, which, as close scrutiny revealed, had 
> it's origin in the missing SVGContext of the element.

> Now, I am somewhat at a loss - I thought an elements context was 
> implicitly set upon creation, no need for me to tamper with it, so I 
> have no idea how to solve the problem. Do I need to set the svgContext 
> manually?

    No, but if you are loading a 'static' SVG document (no script
tags or event attributes) then you need to tell Batik that you still
want access to the SVGDOM (which is provided by the context objects).
This can be done in the canvas with setDocumentState(ALWAYS_DYNAMIC),
or if you are just loading the document yourself you need to use
the GVTBuilder and the BridgeContext (the BridgeContext has a
method 'setDynamicState' - which can take the value 'DYNAMIC').

> The exception occurs in method breakText(SVGOMTextElement), which is 
> called by afterLoad() - see code below.
> Can you give me a pointer how to solve the problem?
> 
> Thanks a lot
> -Urs
> 
> Code Excerpt:
> 
> private void breakText(SVGOMTextElement text) {
>        float textLength=text.getComputedTextLength();    //This is where 
> things go haywire
>        if textLength<120{...}
>        else if textLength>120 {...}
>        ...}
> 
> protected void afterLoad() {
>    SVGOMTextElement currentNode;
>    this.graphic=canvas.getSVGDocument();
>    NodeList textNodes = graphic.getElementsByTagName("text");
>    int number=textNodes.getLength();
>    for(int i = 0; i < number; i++) {
>        currentNode=(SVGOMTextElement) textNodes.item(i);
>        //Check whether the Text Element is in the right group.
>        if 
> (((SVGOMGElement)currentNode.getParentNode().getParentNode().getParentNode()).getAttribute("id").matches("cascade"))

> {
>            addOnClick(currentNode); //adds an EventListener to handle 
> "OnClick" events.
>            breakText(currentNode); //breaks the text if it is to long
>        }
>    }
> }
> 
> 
> ---------------------------------------------------------------------
> 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


Mime
View raw message