I've also come across a similar scenario where by a text element containing
just space causes an exception when I attempt to calculate the bounding box.

For my situation such text elements with spaces can be ignored so I just do
a check to avoid the exception.

For you I would suggest looking into the SVG specification or SVG CSS
specification as there may be ways in which the length of a space can be
derived by calculations based on style sheet values. For example, there is
and attribute called horiz-adv-x which might give you a clue to how wide a
space should be. The height doesn't matter - you could derive this from the
height of the rest of the text.

So I would suggest removing trailing spaces (but keeping a record of them in
a String) to avoid the exception you get from batik. Do your calculation to
get the rectangle. The query your document's CSS values to work out the size
of a space and multiply this by the number of spaces in that String and add
this to the rectangle dimensions.


madprog wrote:
> 
> Hello,
> 
> I am having a problem with the SVGOMTextElement.getSubStringLength  
> method.
> In the following code, this.selectMask is a SVGOMRectElement and  
> this.text a SVGOMTextElement.
> It tries to set the width of the <rect> element to the length of the  
> text showed in the <text> element.
> 
> 1: try {
> 2:     this.selectMask.setAttribute("width",  
> Float.toString(this.text.getSubStringLength(start, length)));
> 3: } catch (NullPointerException npe) {
> 4:     System.out.println("selection: '" +  
> this.text.getTextContent().substring(start, start + length) + "'");
> 5:     npe.printStackTrace();
> 6: }
> 
> The output is following:
> 
> selection: 'Hello, '
> java.lang.NullPointerException
>          at  
> org 
> .apache 
> .batik 
> .bridge 
> .SVGTextElementBridge.getSubStringLength(SVGTextElementBridge.java:2723)
>          at  
> org 
> .apache 
> .batik 
> .bridge 
> .SVGTextElementBridge.getSubStringLength(SVGTextElementBridge.java:2385)
>          at  
> org 
> .apache 
> .batik 
> .dom 
> .svg 
> .SVGTextContentSupport.getSubStringLength(SVGTextContentSupport.java: 
> 260)
>          at  
> org 
> .apache 
> .batik 
> .dom 
> .svg 
> .SVGOMTextContentElement 
> .getSubStringLength(SVGOMTextContentElement.java:195)
>          at (attached source code, line 2)
>          ...
> 
> The exception is raised only when the substring is at the end of the  
> text content, and when this content is ended by a space character (' ').
> 
> Is this a bug ? If it is not, do I have to trim the substring, and get  
> the length of this new string from the <text> element ?
> Is not there a way to have this space included in the calculation ?
> 
> Paul
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Problem-with-the-SVGOMTextElement.getSubStringLength-method-tp16568076p17021835.html
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to