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 LP <ja...@gmail.com> on 2010/10/11 18:48:06 UTC

Convert SVG to Java-Shapes?

Hi,
when Batik reads in a SVG document and renders it on JSVGCanvas or
into an image via ImageTranscoder, it probably draws and fills
java.awt.Shape Objects most of the time.

These Shape objects exist somewhere in this drawing code and I would
like to get them and use them for further operations.

Is there any way to get those Shapes?

Thanks,
jago

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


Re: Convert SVG to Java-Shapes?

Posted by Tonny Kohar <to...@gmail.com>.
Hi,

On Tue, Oct 12, 2010 at 4:09 AM, LP <ja...@gmail.com> wrote:
> Thanks a lot for your very detailed explanation. It really helped a
> lot for me to understand it. You were right, I did find an easier way
> by using the standard DOM interfaces. Still, GVT seems very
> interesting and I am happy I looked into it.

It is very important to understand Apache Batik architecture
http://xmlgraphics.apache.org/batik/using/architecture.html

>From the architecture diagram above, you will see that GVT is a low
level modules which have close relationship with the renderer
(contrasted with SVG DOM which is on the higher level).

So if you need low level access to the Java Shape used by rendering
engine, you need to go deep into GVT from Bridge. The Bridge is the
linking between DOM and GVT

Cheers
Tonny Kohar
--
Sketsa SVG Editor
imagine, design, create ...
http://www.kiyut.com

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


Re: Convert SVG to Java-Shapes?

Posted by LP <ja...@gmail.com>.
Thanks a lot for your very detailed explanation. It really helped a
lot for me to understand it. You were right, I did find an easier way
by using the standard DOM interfaces. Still, GVT seems very
interesting and I am happy I looked into it.

Thanks again!

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


Re: Convert SVG to Java-Shapes?

Posted by jonathan wood <jo...@gmail.com>.
Sorry for the terse answer...I assumed since you explicitly mentioned
JSVGCanvas and ImageTranscoder that you were familiar with both.

if you are transcoding....obtain a BridgeContext using ImageTranscoder's
(SVGAbstractTranscoder's) protected ctx variable or possibly
createBridgeContext().  I'm not familiar with using the latter, although if
you are maniplulating shapes, it may be easier to extend  BridgeContext.

if using JSVGCanvas, get the BridgeContext using

    myJSVGCanvas.getUpdateManager().getBridgeContext()


In either case, use your SVGDocument to find the node you are interested
in...

    Element el = document.getElementById("my-circle");

Ask the previously retrieved BridgeContext for the GraphicsNode...

   GraphicsNode gn = ctx.getGraphicsNode(el);

Carefully cast a Shape out of the fray...

  Shape shape = ((ShapeNode)gn).getShape();


If I recall correctly, this only works if the BridgeContext is dynamic or
possibly interactive.  Using JSVGCanvas with dynamic
(setDocumentState(ALWAYS_DYNAMIC)) will most likely do the trick for simple
use cases.

All that said, if you are new to Batik, you may find an easier way using the
standard DOM interfaces.  Using the GVT to acquire graphics node info is
usually not required.  Did you have a specific problem you are trying to
solve?




On Mon, Oct 11, 2010 at 3:13 PM, LP <ja...@gmail.com> wrote:

> Oh my...thanks but I am a total Batik Beginner. Most of what you wrote
> I cannot understand or even find.
>
> I managed to read in a SVG file so I am basically starting with a
> SVGDocument object.
>
> 2010/10/11 jonathan wood <jo...@gmail.com>:
> >
> > BridgeContext ctx = (you can get it from the UpdateManager, etc);
> > GraphicsNode gn = ctx.getGraphicsNode(Dom node I an interested in);
> >
> > The nodes you are interested will return a ShapeNode....
> >
> > Shape shape = ((ShapeNode)gn).getShape();
> >
> >
> >
> >
> > On Mon, Oct 11, 2010 at 12:48 PM, LP <ja...@gmail.com> wrote:
> >>
> >> Hi,
> >> when Batik reads in a SVG document and renders it on JSVGCanvas or
> >> into an image via ImageTranscoder, it probably draws and fills
> >> java.awt.Shape Objects most of the time.
> >>
> >> These Shape objects exist somewhere in this drawing code and I would
> >> like to get them and use them for further operations.
> >>
> >> Is there any way to get those Shapes?
> >>
> >> Thanks,
> >> jago
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> >> For additional commands, e-mail:
> batik-users-help@xmlgraphics.apache.org
> >>
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>

Re: Convert SVG to Java-Shapes?

Posted by LP <ja...@gmail.com>.
Oh my...thanks but I am a total Batik Beginner. Most of what you wrote
I cannot understand or even find.

I managed to read in a SVG file so I am basically starting with a
SVGDocument object.

2010/10/11 jonathan wood <jo...@gmail.com>:
>
> BridgeContext ctx = (you can get it from the UpdateManager, etc);
> GraphicsNode gn = ctx.getGraphicsNode(Dom node I an interested in);
>
> The nodes you are interested will return a ShapeNode....
>
> Shape shape = ((ShapeNode)gn).getShape();
>
>
>
>
> On Mon, Oct 11, 2010 at 12:48 PM, LP <ja...@gmail.com> wrote:
>>
>> Hi,
>> when Batik reads in a SVG document and renders it on JSVGCanvas or
>> into an image via ImageTranscoder, it probably draws and fills
>> java.awt.Shape Objects most of the time.
>>
>> These Shape objects exist somewhere in this drawing code and I would
>> like to get them and use them for further operations.
>>
>> Is there any way to get those Shapes?
>>
>> Thanks,
>> jago
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
>> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>>
>
>

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


Re: Convert SVG to Java-Shapes?

Posted by jonathan wood <jo...@gmail.com>.
BridgeContext ctx = (you can get it from the UpdateManager, etc);
GraphicsNode gn = ctx.getGraphicsNode(Dom node I an interested in);

The nodes you are interested will return a ShapeNode....

Shape shape = ((ShapeNode)gn).getShape();




On Mon, Oct 11, 2010 at 12:48 PM, LP <ja...@gmail.com> wrote:

> Hi,
> when Batik reads in a SVG document and renders it on JSVGCanvas or
> into an image via ImageTranscoder, it probably draws and fills
> java.awt.Shape Objects most of the time.
>
> These Shape objects exist somewhere in this drawing code and I would
> like to get them and use them for further operations.
>
> Is there any way to get those Shapes?
>
> Thanks,
> jago
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>