You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by Harald Kuhn <ha...@docufy.de> on 2004/12/06 11:31:12 UTC

getTextLenght in SVGOMTextContentElement and Subclasses

Hi Stephane,

I am trying to get the rendered length of a SVG Text Element. As far as 
i understood, the getTextLength() Method of  SVGTextContentElement is 
supposed to do this.
However when i tried this, a RuntimeException was thrown and by looking 
at the code I found out that the Method returns an implementation of 
AbstractSVGAnimatedLength where getDefaultValue() and getAnimatedValue() 
are not implemented. My question is, wether there are any plans for 
implementing this method(s) ?

Cheers,
Harald



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


Re: getTextLenght in SVGOMTextContentElement and Subclasses

Posted by Thomas DeWeese <Th...@Kodak.com>.
Harald Kuhn wrote:

> first of all, I switched to Batik users as i think that my new Problem 
> is better located there!
> 
> I tried to use getComputedTextLength() as you suggested however I 
> encountered an NullPointerException on the way. I looked into the code 
> and found out that it is thrown inside the getComputedText() Method of 
> SVGTextContentSupport. I isolated this in the following code (using 
> getComputedTextLength directly does have the same result but without a 
> clear StackTrace [unknow source entries!] ). The SVGDocument is obtained 
> via a SVGDocumentLoaderListener 

    This is to early in the build process to access the SVG DOM.
You need to wait until the GVT (graphics tree) is built before
you can use most the SVGDOM, before this it doesn't have any
graphics information.

    I would suggest waiting for the onload event (in fact just add
your code to an onload DOM event listener).  This will ensure that
the DOM is is ready for this.  Also since your content doesn't have
any 'script' attributes you will need to tell Batik to treat the
document as dynamic (setDocumentState(ALWAYS_DYNAMIC)).

> added to a JSVGCanvas which loades the 
> Document (i tried loading the document with setURI(...), 
> loadDocument(..) and with calling both). The Document is a relatively 
> simple SVG Document (source added below).
> 
> Any ideas what i am doing wrong ?
> 
> Cheers,
> Harald
> 
> 
> 
> 
> private void process(SVGDocument document) {
>        NodeList list = document.getElementsByTagName("tspan");
>        for (int i = 0; i < list.getLength(); i++) {
>            // the following code is copied from SVGTextContentSupportss 
> static getComputedTextLength Method                    SVGOMTSpanElement 
> element = (SVGOMTSpanElement) list.item(i);
>            final SVGOMElement svgelt = (SVGOMElement) element;
>            final SVGTextContent context = 
> (SVGTextContent)svgelt.getSVGContext();
>            System.out.println(context); // prints out null with my computer
>            System.out.println("Length is " + 
> context.getComputedTextLength());
>        }
>    }
> 
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <svg xmlns="http://www.w3.org/2000/svg" 
> xmlns:xlink="http://www.w3.org/1999/xlink" width="602" height="302">
> <image x="1" y="1" width="600" height="300" xlink:href="....."/>
> <text xml:space="preserve" style= "font:Verdana;fill: black; 
> font-size:32" >
> <tspan x="213" y="100">Some Example</tspan>
> <tspan x="159" y="130">Text</tspan>
> </text>
> </svg>
> 
> 
> 
> 
> 
> Thomas DeWeese wrote:
> 
>> Hi Harald,
>>
>> Harald Kuhn wrote:
>>
>>> I am trying to get the rendered length of a SVG Text Element. As far 
>>> as i understood, the getTextLength() Method of  SVGTextContentElement 
>>> is supposed to do this.
>>
>>
>>
>>    No you want the "getComputedTextLength" function, "getTextLength"
>> is tied to the "textLength" attribute (which should, if set, be the
>> same as the computed text length but for most content it is not).
>> The "getComputedTextLength()" function _is_ implemented.
>>
>>> However when i tried this, a RuntimeException was thrown and by 
>>> looking at the code I found out that the Method returns an 
>>> implementation of AbstractSVGAnimatedLength where getDefaultValue() 
>>> and getAnimatedValue() are not implemented. My question is, wether 
>>> there are any plans for implementing this method(s) ?
>>
>>
>>
>>    There is (since it's pretty simple for Batik, in fact I'm not
>> sure why it isn't already).  However, as I said above it really
>> wouldn't help you much ;)
> 
> 
> 


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


Re: getTextLenght in SVGOMTextContentElement and Subclasses

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Harald,

Harald Kuhn wrote:

> I am trying to get the rendered length of a SVG Text Element. As far as 
> i understood, the getTextLength() Method of  SVGTextContentElement is 
> supposed to do this.

    No you want the "getComputedTextLength" function, "getTextLength"
is tied to the "textLength" attribute (which should, if set, be the
same as the computed text length but for most content it is not).
The "getComputedTextLength()" function _is_ implemented.

> However when i tried this, a RuntimeException was thrown and by looking 
> at the code I found out that the Method returns an implementation of 
> AbstractSVGAnimatedLength where getDefaultValue() and getAnimatedValue() 
> are not implemented. My question is, wether there are any plans for 
> implementing this method(s) ?

    There is (since it's pretty simple for Batik, in fact I'm not
sure why it isn't already).  However, as I said above it really
wouldn't help you much ;)


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