Thomas DeWeese wrote:
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).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
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"); altGlyph.appendChild(doc.createTextNode("?"));
textNode.appendChild(altGlyph); doc.getDocumentElement().appendChild(textNode);
// not sure if the following two lines are needed JSVGComponent svg = new JSVGComponent(); svg.setSVGDocument((SVGDocument)doc);
SVGRect bbox = ((SVGOMTextElement)textNode).getBBox(); System.out.println("MinX: " + bbox.getX());
Thanks James Shaw
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]