xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andres Toussaint <and...@onemileup.com>
Subject Re: SVG into Java Image
Date Wed, 23 Jun 2004 20:03:08 GMT
Hi:

My suggestion is to read the Java Graphics 2D information you need from 
the GVT tree.

Once you load a SVGDocument into a JSCGComponent (you do not need a 
canvas to access the GVT), you can access the GVT by adding a 
GVTTreeBuilderListener to your SVGComponent, in the gvtBuildCompleted 
event.

Once you have the GVT tree, you can walk through it, and retrieve the 
Graphics2D representation of your SVG file.

I use this method to feed a DXF exporter Library that requires Graphics 
2D objects to transform into DXF and it works perfectly.

Basically:

public SomeMethod() {

             JSVGComponent  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) {
		// Now the tree is ready, we have to walk through it
                     GVTTreeWalker tw = new 
GVTTreeWalker(e.getGVTRoot());
                     GraphicsNode node = tw.firstChild();

		////////////////////////////////////////////////////////////////
		////////////////////////////////////////////////////////////////
                     // Walk through the tree to locate and extract the 
Graphics info you want.
		////////////////////////////////////////////////////////////////
		////////////////////////////////////////////////////////////////

                 }
             });

             try {
                 svg.loadSVGDocument(f.toURL().toString());
             }
             catch(Exception e){
                 System.out.println("Could not load SVG file into 
Component.  "+e);

             }
}


On Jun 23, 2004, at 12:48 PM, Arek Stryjski wrote:

> Hi,
>
> I'm wondering that is the simplest way to change SVG into Java Image.
>
> I will need to change XML fragment (one of org.w3c.dom.svg.SVGElement 
> returned
> from org.w3c.dom.events.Event.getTarget()) into java.awt.Image
> In most cases the produced Image will be kind of Icon for element. I 
> don't need
> to save it in any format, I will use it in other swing components.
>
> I was looking at org.apache.batik.transcoder and one way I see, is to 
> implement
> my own ImageTranscoder, TranscoderInput and TranscoderOutput
> However maybe there are some ready classes that could help me to do 
> part of this
> job, or maybe there is some other place in Batik I should look for 
> solution for
> this.
>
> Best regards
> Arek
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
>
>



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


Mime
View raw message