Hi,

You need to read the GVT (Graphics vector tree).
The GVT holds the Java Graphics2D info of your SVG, so you can retrieve the coordinates in pairs, as you desire. To do so, you need to walk the GVT tree and extracting the data of the desired types.

Here is an excerpt on how to walk the GVT tree:

svg = new JSVGComponent();
svg.addSVGDocumentLoaderListener(new SVGDocumentLoaderAdapter() {
public void documentLoadingStarted(SVGDocumentLoaderEvent e) {
}
public void documentLoadingCompleted(SVGDocumentLoaderEvent e) {
}
});
svg.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() {
public void gvtBuildStarted(GVTTreeBuilderEvent e) {
}
public void gvtBuildCompleted(GVTTreeBuilderEvent e) {

GVTTreeWalker tw = new GVTTreeWalker(e.getGVTRoot());
GraphicsNode node = tw.firstChild();

//locate the first Canvas element to get the element inside this canvas object
while (!(node instanceof org.apache.batik.gvt.CanvasGraphicsNode)) {
node = tw.nextGraphicsNode();
if (node == null) return;
}



//At this place, node has the root Canvas Graphics node, now, cycle through the
// children (shape objects) of this canvas node
GVTTreeWalker tw = new GVTTreeWalker(Node);
GraphicsNode node = tw.firstChild();


while (node !=null) {
if (node instanceof org.apache.batik.gvt.ShapeNode) {
// ... do something. ShapeNode has a GeneralPath object.
node = tw.nextGraphicsNode();
} else if (node instanceof org.apache.batik.gvt.TextNode) {
// ..... do something
node = tw.nextGraphicsNode();
} else if (node instanceof org.apache.batik.gvt.CanvasGraphicsNode) {
// We have an embedded SVG image inside the root SVG image, do something to process it
// This is the case if your SVG has a <image .....> element
} else {
....
// when done processing the siblings, reach for the next sibling of the parent, unless it is the root object
// which means we are done walking the tree.
node = tw.parentGraphicsNode();
if (node == Node) return;
}

}

}
}


}
});



On May 18, 2004, at 3:26 PM, Antonio Gomes wrote:

hey everybody ..

i have a little problem and i hope u help me !!

i'm rendering a path in a simple svgcanvas, and i wanna to retrieve the
its points.

for example - <path d="M 10 15 L 100 150 L 40 50 Z"/>, i wanna to
retrieve and to record each pair of coordinates, like "10 15", "100 150" and "40 50".

please, how can i do it with batik ?!

thanks !

Antonio Gomes
 


Antônio Gomes - Tonykitinho !!
<x-tad-smaller> Presidente da Comissão de Formatura (ComFor) 2004</x-tad-smaller>
<x-tad-smaller> </x-tad-smaller>
7o Período - C!3nC!@ d@ [EMAIL PROTECTED]@uM - UFAM


Yahoo! Messenger - Fale com seus amigos online. Instale agora!

Reply via email to