xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathan wood <jonathanshaww...@gmail.com>
Subject Re: Convert SVG to Java-Shapes?
Date Mon, 11 Oct 2010 20:12:49 GMT
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 <java.jago@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 <jonathanshawwood@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 <java.jago@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
>
>

Mime
View raw message