Hi Henric,

"Henric Rosvall" <[EMAIL PROTECTED]> wrote on 03/06/2007 06:18:47 AM:

> I'm trying to implement multiline text just using a text-element and
> some tspans. But in order to do this, I need to know the maximum 
> height that the characters of a line can occupy (so I know at what 
> position to insert the next line).

> Basically I thought I'd set the value of the Text-element to "Og" 
> and then measure the combined height of these characters:

  The code below doesn't set the value of the TextElement.
You need to create/fetch a DOM TextNode with the desired
string.

>    // Get the maximum rowHeight
>    SVGTextElement svgTxt = (SVGTextElement)TextElement;
     TextNode tn = doc.createTextNode("Og");
     svgTxt.appendChild(tn);

>    float minY = Integer.MAX_VALUE;
>    float maxY = Integer.MIN_VALUE;
>    for (int x = 0; x < strToMeasure.length(); x++)
>    {
>     SVGRect r = svgTxt.getExtentOfChar(x);
> 
>     if (r.getY() < minY)
>      minY = r.getY();
>     if (r.getY() + r.getHeight() > maxY)
>      maxY = r.getY() + r.getHeight();
>    }
>    svgTxt.setNodeValue("");
> 
>    float rowOffset = maxY - minY;
> 
> But the getExtentOfChar-method throws an exception:
> org.w3c.dom.DOMException: 
>  at org.apache.batik.dom.AbstractNode.createDOMException(Unknown Source)
>  at org.apache.batik.dom.svg.SVGTextContentSupport.
> getExtentOfChar(Unknown Source)
>  at org.apache.batik.dom.svg.SVGOMTextContentElement.
> getExtentOfChar(Unknown Source)
>  at printit.template.controls.MultilineTextTemplateControl.
> setSVGTextElementText(MultilineTextTemplateControl.java:86)
>  at printit.template.controls.MultilineTextTemplateControl.
> setText(MultilineTextTemplateControl.java:54)
>  at printit.template.controlpanels.MultilineTextControlPanel$1.
> run(MultilineTextControlPanel.java:94)
>  at org.apache.batik.util.RunnableQueue.run(Unknown Source)
>  at java.lang.Thread.run(Unknown Source)
> 
> So, if there is a better way, please tell me. Even a simple unit-
> converter might be bettereven though the distance between the lines 
> might not be that accurate. Otherwise, if there really isn't a 
> better way, do you have any idea what might be wrong? Is it some 
> rendering-issue, like, the string hasn't been rendered, and can 
> therefore not be measured?
> 
> Regards
> Ehhh.... Definately not Henric Rosvall. He's too leet to write code 
> like this :P

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

Reply via email to