xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Urs Reupke" <ursreu...@gmx.net>
Subject SVGContext is null
Date Wed, 08 Sep 2004 08:43:32 GMT
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?
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

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

View raw message