>>>>> "R" == Riyaz  <[EMAIL PROTECTED]> writes:

R> First of all, thanks Thomas for your reply.  I am using
R> SVGLocatable to get the bounding box of the svg elements as
R> follows:

   You need to use the bridge package (GVTBuilder) to build the
rendering tree.  Without the rendering tree Batik doesn't have any
geometrical information available.  Remember to tell the bridge to
treat the document as dynamic (otherwise the rendering tree will be
created independent of the DOM tree).

R> String parser = XMLResourceDescriptor.getXMLParserClassName();
R> SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
R> Document doc = f.createDocument(uri); //******** create document
R> from svg file
 
R> Element mainmap = doc.getElementById("mainmap"); NodeList svgNodes
R> = mainmap.getElementsByTagName("path"); //******** retrieve needed
R> svg elements from the document for (int i=0;
R> i<svgNodes.getLength(); i++) { Element subElemNode =
R> (Element)svgNodes.item(i);// Get element if (subElemNode instanceof
R> SVGLocatable) { SVGRect bb = ((SVGLocatable)subElemNode).getBBox();
R> //********** get the bounding box of the elements
R> System.out.println(bb.getX()); //*********** ---> Line 45 } }


R> When I print the Id of the elements it shows the correct output but
R> when I get the BBox of that element and try to print it out it
R> gives the following run-time error(line45):

R> exception: null java.lang.NullPointerException at
R> org.apache.batik.dom.svg.SVGLocatableSupport$1.getX(Unknown Source)
R> at CreateSpatial.main(CreateSpatial.java:45)

R> Any tips on this??

R> Thanks, Riyaz.



R> ********************* Hi Jan, Riyaz,

R>    So the first question to ask when you say 'bounding box' is the
R> bounding box in what coordinate system?  And how important is it
R> that the bounding box be 'tight'?

R>    So Jan gives one way of doing it which seems to try and get the
R> bounds in screen coords, (but the code assumes there are no
R> transforms between the element and the root of the SVG tree - this
R> can be fixed by including the results of
R> node.getGlobalTransform()).

R>    You could also just use the SVGLocatable interface on the DOM
R> Element (see the SVG specification).  This would generally be
R> preferable but if you need tight bounds in any coordinate system
R> other than the user coordinate system you will have to use the
R> various GraphicsNode methods (like getTransformedBounds).



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

Reply via email to