xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Shaw <hertzsprrr...@btopenworld.com>
Subject Re: Obtaining glyph bounding box
Date Wed, 02 Feb 2005 20:15:24 GMT
Thomas DeWeese wrote:

> Hi James,
>    To get back to your original question if all you want is the
> bounding box of elements in the DOM, you can do this right with
> the SVG DOM (svgelem.getBBox()).  The only advantage of this is
> that you can using getElementById to avoid the need to walk the
> whole tree.  Also using the SVG DOM you can even get the
> location/size of individual glyphs from a text node.  Take a look
> at:  samples/tests/spec/scripting/text_content.svg
This method looks promising, but I've failed to make it work.  A 
NullPointerException is raised when I do bbox.getX() (or any other 
method of SVGRect).
I think this is due to a null SVGContext.  Presumably some intermediate 
steps need to be taken before I can invoke the SVGRect methods.

My code looks like this:

Element textNode = doc.createElementNS(SVG_NS, "svg:text");
textNode.setAttributeNS(null, "font-family", "LilyPond-feta-20");
textNode.setAttributeNS(null, "font-size",   "18pt");
textNode.setAttributeNS(null, "x", "0");
textNode.setAttributeNS(null, "y", "0");

Element altGlyph = doc.createElementNS(SVG_NS, "svg:altGlyph");
altGlyph.setAttributeNS(XLINK_NS, "xlink:href", "#sixtyfourthrest");


// not sure if the following two lines are needed
JSVGComponent svg = new JSVGComponent();

SVGRect bbox = ((SVGOMTextElement)textNode).getBBox();
System.out.println("MinX: " + bbox.getX());

James Shaw

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

View raw message