You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Arek Stryjski <de...@krzyzowki.net.pl> on 2004/06/23 19:48:16 UTC

SVG into Java Image

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


Re: SVG into Java Image

Posted by Arek Stryjski <de...@krzyzowki.net.pl>.
Cytowanie Andres <an...@onemileup.com>:

> HI:
> 
> The way i do it is I assign an EXTRA attribute to the SVG element, 
> which i call UID (unique ID) with a specific value identifying each 
> element. So when the user clicks on a SVG Dynamic element on the 
> canvas, you can get its ID, and thus you can identify the item.
> 

Yes identifying item then user click on it is not problem. But how to find
GraphicsNode for SVGElement with some id just then document is loaded (in
gvtBuildCompleted() method)?

Arek

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


Re: SVG into Java Image

Posted by Tonny Kohar <to...@kiyut.com>.
Hi,
> >
> > Thank you for your help. Code you post work perfectly in situation I 
> > describe
> > last time (then user clicks on Canvas). Then I call:
> >
> > GVTTreeWalker tw = new GVTTreeWalker(e.getGVTRoot());
> > GraphicsNode root = tw.firstChild();
> > GraphicsNode node = root.nodeHitAt(point);
> > ...
> >
> > But that in situation if I don't know position of elements on the 
> > canvas. Is it
> > possible to easy found SVG element with some id on GVTTree?

You can use 
- bridgeContext.getElement(graphicsNode); // return DOM Node/Element
- bridgeContext.getGraphicsNode(svgElement); // return GVT Graphics node

to get the coresponding GVT Graphics Node with the DOM Node/Element

Best Regards
Tonny Kohar
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com



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


Re: SVG into Java Image

Posted by Andres <an...@onemileup.com>.
HI:

The way i do it is I assign an EXTRA attribute to the SVG element, 
which i call UID (unique ID) with a specific value identifying each 
element. So when the user clicks on a SVG Dynamic element on the 
canvas, you can get its ID, and thus you can identify the item.

Andres.



On Thursday, June 24, 2004, at 09:10  AM, Arek Stryjski wrote:

> Cytowanie Andres Toussaint <an...@onemileup.com>:
>
>>
>> My suggestion is to read the Java Graphics 2D information you need 
>> from
>> the GVT tree.
>> ...
>>                      // Walk through the tree to locate and extract 
>> the
>> ...
>
> Thank you for your help. Code you post work perfectly in situation I 
> describe
> last time (then user clicks on Canvas). Then I call:
>
> GVTTreeWalker tw = new GVTTreeWalker(e.getGVTRoot());
> GraphicsNode root = tw.firstChild();
> GraphicsNode node = root.nodeHitAt(point);
> ...
>
> But that in situation if I don't know position of elements on the 
> canvas. Is it
> possible to easy found SVG element with some id on GVTTree?
>
> 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


Re: SVG into Java Image

Posted by Arek Stryjski <de...@krzyzowki.net.pl>.
Cytowanie Andres Toussaint <an...@onemileup.com>:

> 
> My suggestion is to read the Java Graphics 2D information you need from 
> the GVT tree.
> ...
>                      // Walk through the tree to locate and extract the 
> ...

Thank you for your help. Code you post work perfectly in situation I describe
last time (then user clicks on Canvas). Then I call:

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

But that in situation if I don't know position of elements on the canvas. Is it
possible to easy found SVG element with some id on GVTTree? 

Best regards
Arek

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


Re: SVG into Java Image

Posted by Andres Toussaint <an...@onemileup.com>.
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