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 Randy Leonard <ra...@hotmail.com> on 2003/04/25 09:02:11 UTC

Re: Text measurement

Ok... finally got around to this, but am having problems.  Using v1.5b5

To recap, I wish to generate a collection of menu items from a single SVG
template.  To make things simple, this document contains a rounded rect
which is clipped to show just it's upper half.  This mimics a menu tab for
now ;)  I then embed a single line of text within this clipped rectangle.
The trick is to measure the text length and adjust the document and recangle
width accordingly.  Here's a code snippet:

    SVGOMTextElement text = (SVGOMTextElement)doc.createElementNS(svgNS,
"text");
    text.setAttributeNS(null, "x", "30");
    text.setAttributeNS(null, "y", "40");
    svgRoot.appendChild(text);
    GenericText textString = new GenericText(aMenuString, doc);
    text.appendChild(textString);
    System.out.println("Length of " + aMenuString + " is " +
text.getTextLength().getBaseVal().getValue());

Unfortunately, the last line of code generates the following exception:

    java.lang.RuntimeException: !!! TODO
    at
org.apache.batik.dom.svg.SVGOMTextContentElement$1.getDefaultValue(Unknown
Source)
    at
org.apache.batik.dom.svg.AbstractSVGAnimatedLength$BaseSVGLength.revalidate(
Unknown Source)
    at org.apache.batik.dom.svg.AbstractSVGLength.getValue(Unknown Source)
    at imageGenerator.createDocument(imageGenerator.java:88)
    at imageGenerator.main(imageGenerator.java:101)
    Exception in thread "main"

I get a similar exception calling getComputedTextLength.

Unfortunately, I do not have the batik source checked out, so please forgive
what may seem as laziness.  But my question is if this is a problem with my
usage of Batik, or if this is a bug with Batik.

Thanks,
Randy


----- Original Message -----
From: "Thomas E Deweese" <th...@kodak.com>
To: <ba...@xml.apache.org>
Sent: Thursday, February 27, 2003 6:38 AM
Subject: RE: Text measurement


> >>>>> "RL" == Randy Leonard <ra...@hotmail.com> writes:
>
> RL> I am new to SVG, so please excuse what may be a simple question.
> RL> I am interested in generating menu buttons for web portal
> RL> applications using Batik.  Some menu buttons will be fixed length,
> RL> others should vary depending upon embedded text.  From my research
> RL> to date, it seems I cannot write SVG which expands/contracts the
> RL> size of the generated image based on text measurement.
>
>     Correct.
>
> RL> As such, it seems I must read an SVG template using SVGDOM and
> RL> manipulate the SVG prior to passing it off to the Transcoder for
> RL> jpeg creation.
>
>     Yup.
>
> RL> My question is... does this seem like a reasonable approach.  If
> RL> so, is there a class which permits text measurement so I can
> RL> adjust the SVG to accomodate variable text size.
>
>     It does seem like a reasonable approach and for most simple text
> should be fairly straight forward.  The part of the SVG DOM that you
> are interested in is the SVGTextContentElement interface in section
> 10.17 of the SVG specification.
>
>     Only last week Batik got support for this interface so you will
> need to use a CVS copy of Batik to do your work (at this point CVS is
> generally better than the last release anyway).  This lets you query
> all the information you could ever want about the text.  You might
> also take a look at SVGLocatable which can give simple bounding box
> information (which may be all you need for your text elements).
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-dev-help@xml.apache.org
>

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