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 Kevin POCHAT <kp...@gmail.com> on 2012/02/18 18:51:12 UTC

Need help converting an SVG file into Java (2D) objects

Hello everyone,

I guess as this is my first message to this list, I should present myself a
little bit.
I have 5 years of professionnal experience as Java/Swing developper, am a
technology enthusiast, and especially love everything that is
HMI/GUI/Ergonomy related.
I'm also a would-be independant game developper, and that is the cause of
this message.

I already built a small game engine using batik to transform SVG files into
PNG (depending on game resolution) drawn using an OpenGL back-end (LWJGL).
So far, so good, but what I'm up to these days is to use Inkscape as a
level designing tool as well.

To do so, I use one layer as the graphics source (to be used as map art),
and another one to put some metadata (AI path, areas of various types...).
Now, I'm trying to use batik to parse my SVG files, create my object model
accrodingly, and strip these metadata from the document before PNG
conversion.

My main issue is to find some classes that will be able to parse a <path>
element's "d" attribute contents into an OO API, like CubicCurve2D.
I already managed to retrieve the "d"'s value into a String object, but
PathParser seem to need to work with a yet-to-implement PathHandler
implementor. The metadata stripping part was covered easily too.

Any Cubic curve or Bezier Path API should do the trick. The features I wish
to have are path length, x,y coordinates of point on curve at X% of
length...

Could you guide me towards such an API, or code example ? I really get lost
in the tremendous amount of batik classes, and I hate the genericity of
Node/NodeList/Element/Document type of classes.

Best regards,

Kevin POCHAT

Re: parsing a svg file using batik svg parser

Posted by reka <re...@gmail.com>.
Hi All ,

I m new to this technology.i need to know how to parse a svg file using
batik svg parser.

For eg:

Here is my svg file

<svg width="640" height="480" xmlns="http://www.w3.org/2000/svg">
 <g>
  <title>Layer 1</title>
  <line id="svg_1" y2="395" x2="449" y1="395" x1="449" opacity="0.5"
stroke-linecap="round" stroke-linejoin="null" stroke-dasharray="null"
stroke-width="2" stroke="#000000" fill="none"/>
  <path id="svg_2" d="m 200,159 c-3,53 57,-63 57,-63 c 0,0 108,-16 108,-16 c
0,0 73,79 73,79 c 0,0 -32,77 -32,77 c 0,0 -69,74 -69,74 c 0,0 -92,-18
-92,-18 c 0,0 -78,-27 -78,-27 c 0,0 -18,-85 -18,-85 c 0,0 51,-21 51,-21 z"
stroke-width="2" stroke="#000000" fill="none"/>
 </g>
</svg>


Now i wanna read ie parse and get only the <path> tag value.

can anyone help me on this please.

Many thanks in advance :) 



--
View this message in context: http://batik.2283329.n4.nabble.com/Need-help-converting-an-SVG-file-into-Java-2D-objects-tp4400151p4655597.html
Sent from the Batik - Users mailing list archive at Nabble.com.

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


Re: Need help converting an SVG file into Java (2D) objects

Posted by Thomas DeWeese <th...@gmail.com>.
Hi Kevin,

On Feb 21, 2012, at 1:40 PM, Kevin POCHAT <kp...@gmail.com> wrote:

> Hi Thomas,
> 
> Thank you for your answer.
> In the meantime, I stumbled upon SVG Salamander, another SVG lib for Java, that is way featureless, and way lighter, than Batik. 
   Ok, hope it works out for you.

> On another subject (well, not really another), I'd like to integrate filters and bitmaps (PNG) within my SVG documents (embed the PNG contents, not a href link), but Inkscape doesn't seem to support that. Do you know if there's another (free) editor that allows that.

   I'd be surprised if Inkscape didn't support embedded bitmaps.

> I don't even know if bitmap embedding is possible with SVG.

Yes it is. You use an image element with an xlink:href that uses the 'data:' protocol.

    Thomas DeWeese

> 2012/2/21 Thomas DeWeese <th...@gmail.com>
> Hi Kevin,
> 
> On Feb 18, 2012, at 12:51 PM, Kevin POCHAT <kp...@gmail.com> wrote:
> 
>> Could you guide me towards such an API, or code example ? I really get lost in the tremendous amount of batik classes, and I hate the genericity of Node/NodeList/Element/Document type of classes.
> 
> Sure the various parser implementations generally start with AWT since they produce geom elements from AWT.
> 
> http://xmlgraphics.apache.org/batik/javadoc/org/apache/batik/parser/AWTPathProducer.html#createShape(java.io.Reader,%20int)
> 
>> 
> 

Re: Need help converting an SVG file into Java (2D) objects

Posted by Peter Woodiwiss <pw...@gmail.com>.
Hi Kevin,

Inkscape can embed images.  Got to Extensions->Images->Embed Images..

Pete

On 21/02/2012 18:40, Kevin POCHAT wrote:
> Hi Thomas,
>
> Thank you for your answer.
> In the meantime, I stumbled upon SVG Salamander, another SVG lib for 
> Java, that is way featureless, and way lighter, than Batik. For what I 
> need as of now, it does the job, and the API is way closer to what I 
> expected for the object model of the SVG document. However, the 
> PathIterator used to get points along the path does not give me fixed 
> length segments, but with enough precision, and some easy maths, I 
> should be able to go with it. I might still turn back to Batik for 
> SVG->PNG rendering if Salamander does not implement as many tags as 
> Batik does (my current SVG are very simples : rect, path and gradients 
> only).
>
> On another subject (well, not really another), I'd like to integrate 
> filters and bitmaps (PNG) within my SVG documents (embed the PNG 
> contents, not a href link), but Inkscape doesn't seem to support that. 
> Do you know if there's another (free) editor that allows that. I don't 
> even know if bitmap embedding is possible with SVG.
>
> Best regards,
>
> Kevin POCHAT
>
>
> 2012/2/21 Thomas DeWeese <thomas.deweese@gmail.com 
> <ma...@gmail.com>>
>
>     Hi Kevin,
>
>     On Feb 18, 2012, at 12:51 PM, Kevin POCHAT <kpochat@gmail.com
>     <ma...@gmail.com>> wrote:
>
>>     Could you guide me towards such an API, or code example ? I
>>     really get lost in the tremendous amount of batik classes, and I
>>     hate the genericity of Node/NodeList/Element/Document type of
>>     classes.
>
>     Sure the various parser implementations generally start with AWT
>     since they produce geom elements from AWT.
>
>     http://xmlgraphics.apache.org/batik/javadoc/org/apache/batik/parser/AWTPathProducer.html#createShape(java.io.Reader,%20int)
>     <http://xmlgraphics.apache.org/batik/javadoc/org/apache/batik/parser/AWTPathProducer.html#createShape%28java.io.Reader,%20int%29>
>
>
>

Re: Need help converting an SVG file into Java (2D) objects

Posted by Kevin POCHAT <kp...@gmail.com>.
Hi Thomas,

Thank you for your answer.
In the meantime, I stumbled upon SVG Salamander, another SVG lib for Java,
that is way featureless, and way lighter, than Batik. For what I need as of
now, it does the job, and the API is way closer to what I expected for the
object model of the SVG document. However, the PathIterator used to get
points along the path does not give me fixed length segments, but with
enough precision, and some easy maths, I should be able to go with it. I
might still turn back to Batik for SVG->PNG rendering if Salamander does
not implement as many tags as Batik does (my current SVG are very simples :
rect, path and gradients only).

On another subject (well, not really another), I'd like to integrate
filters and bitmaps (PNG) within my SVG documents (embed the PNG contents,
not a href link), but Inkscape doesn't seem to support that. Do you know if
there's another (free) editor that allows that. I don't even know if bitmap
embedding is possible with SVG.

Best regards,

Kevin POCHAT


2012/2/21 Thomas DeWeese <th...@gmail.com>

> Hi Kevin,
>
> On Feb 18, 2012, at 12:51 PM, Kevin POCHAT <kp...@gmail.com> wrote:
>
> Could you guide me towards such an API, or code example ? I really get
> lost in the tremendous amount of batik classes, and I hate the genericity
> of Node/NodeList/Element/Document type of classes.
>
>
> Sure the various parser implementations generally start with AWT since
> they produce geom elements from AWT.
>
>
> http://xmlgraphics.apache.org/batik/javadoc/org/apache/batik/parser/AWTPathProducer.html#createShape(java.io.Reader,%20int)
>
>

Re: Need help converting an SVG file into Java (2D) objects

Posted by Thomas DeWeese <th...@gmail.com>.
Hi Kevin,

On Feb 18, 2012, at 12:51 PM, Kevin POCHAT <kp...@gmail.com> wrote:

> Could you guide me towards such an API, or code example ? I really get lost in the tremendous amount of batik classes, and I hate the genericity of Node/NodeList/Element/Document type of classes.

Sure the various parser implementations generally start with AWT since they produce geom elements from AWT.

http://xmlgraphics.apache.org/batik/javadoc/org/apache/batik/parser/AWTPathProducer.html#createShape(java.io.Reader,%20int)