xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kristian Spangsege ...@instadia.net>
Subject Re: SVGTextElement.getComputedTextLength()
Date Wed, 26 Jan 2005 12:27:43 GMT
Alright, I found a posting on this list, that explained the matter to 
some extent:

http://mail-archives.apache.org/eyebrowse/ReadMsg?listName=batik-users@xml.apache.org&msgId=2030753

Still I'm left with a "chicken and egg" problem.

All I need to do is to create an SVG document with a piece of text at a 
specific position and followed by a vertical separation line. Problem is 
that I need to know the width of the text before I can place the 
vertical seperation line.

It seems wierd to me, if I'm supposed to first add the separation line 
at some random position, then fire up the DOM, and then calculate the 
desired position of the separation line.

- Is there another method of inquiring on the length of a certain string 
of characters?

- When the sole purpose is to generate an on-disk document, would it be 
a resonable approach to actually fire up the DOM with an empty document 
then construct the SVG elements as needed. I assume that in this case it 
is legal to call getComputedTextLength() immediately after constructing 
the SVGTextElement.

Regards and thanks in advance,
Kristian Spangsege


Kristian Spangsege wrote:
> Hi
> 
> According to the SVG conformance page, the following method is supported 
> by Batik:
> 
> SVGTextElement.getComputedTextLength()
> 
> Yet I have problems with it.
> I would appreciate if someone could point out for me what I'm doing wrong.
> 
> I'm using Batik 1.5.1.
> 
> The Code:
> ----------------------------------------------------------------------
> 
> import org.w3c.dom.svg.*;
> import org.apache.batik.dom.*;
> import org.apache.batik.dom.svg.*;
> 
> public class Test
> {
>   public static void main(String[] args)
>   {
>     SVGOMDocument doc = 
> (SVGOMDocument)SVGDOMImplementation.getDOMImplementation().createDocument(SVGDOMImplementation.SVG_NAMESPACE_URI,

> "svg", null);
> 
>     SVGTextElement text = 
> (SVGTextElement)doc.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, 
> "text");
>     text.appendChild(doc.createTextNode("foo"));
> 
>     System.err.println(text.getComputedTextLength());
>   }
> }
> 
> ----------------------------------------------------------------------
> 
> I get this error:
> 
> ----------------------------------------------------------------------
> 
> Exception in thread "main" java.lang.NullPointerException
>         at 
> org.apache.batik.dom.svg.SVGTextContentSupport.getComputedTextLength(Unknown 
> Source)
>         at 
> org.apache.batik.dom.svg.SVGOMTextContentElement.getComputedTextLength(Unknown 
> Source)
>         at Test.main(Test.java:14)
> 
> ----------------------------------------------------------------------
> 
> Regards and thanks in advance,
> Kristian Spangsege
> 


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