PDA

View Full Version : Simple SVG Parser?



Das Gurke
08-07-2008, 03:48 AM
I guess I know the answer in beforehand, but I thought I would double check before frustrating completly *g*

What SVG Loaders targeting at the OpenVG API are currently around? I am aware that AlexVG implements the TinySVG standard, but for some reason I can not download the demo from their forums (not even after registering) and I have no idea about their licensing terms.

Then there is the svgconv tool, which I did not manage to compile. Others, even in this forum, seem to have similar trouble.

I am not asking for a complete SVG implementation, all I need are the very basic constructs. See the attachment.

The attachment can be rendered via AGGs SVG Test Sample. But AGG is not quite a possible solution to me, as i would like Hardware acceleration. Currently I tend to use the shivaVG (http://ivanleben.blogspot.com/2007/07/shivavg-open-source-ansi-c-openvg.html) implementation (if that matters).

Edit: Hmm, the attachment function does not seem to allow SVGs... Here ist the source of my SVG:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<svg
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.0"
width="100"
height="100"
id="svg2">
<defs
id="defs4" />
<path
d="M 24.656174,97.865133 L 25.22824,22.932957 C 25.486372,7.7008523 37.691293,2.2784149 50.113172,2.1354538 C 63.512353,1.971473 75.05983,11.844893 74.998102,23.238803 L 74.712067,97.865133 L 24.656174,97.865133 z"
id="path2408"
style="fill:#00ff00;fill-rule:evenodd;stroke:#000000;stroke-width:1.36647499px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
d="M 24.921978,21.840945 C 15.608661,21.812246 15.840123,39.757915 24.993878,39.510016"
id="path2414"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1.13771975px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
d="M 24.247024,71.646433 C 14.933707,71.617733 15.165169,89.563402 24.318924,89.315503"
id="path2416"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1.13771975px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
d="M 74.642959,39.195771 C 83.954776,39.37676 83.980006,21.429405 74.823775,21.527592"
id="path2418"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1.13771975px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
d="M 74.922436,88.959699 C 84.234254,89.140689 84.259483,71.193332 75.103253,71.291519"
id="path2420"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1.13771975px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
</svg>

Ivo Moravec
08-08-2008, 04:58 PM
Well, I don't know of and good free ones either.

svgconv... I spent a day trying to install all the packages to get it to successfully compile (windows, vmware, cygwin, etc.). Finally I managed it in cygwin and using GODI (successful installation requires a) pure luck, and b) a system that has never seen any part of ocaml installed in either cygwin or windows [even uninstalling, it leaves a mess in your enviroment variables, preventing a successful re-install]).

More importantly than that though, is that IT'S NOT WORTH THE TROUBLE! Stay away from svgconv! It is hopelessly bad. I cannot stress this enough! For one thing, it only supports filled paths (no stroked paths). Anything else would require a large re-write of just about everything. Linear and Radial paints don't work. rect and circle tags are not supported, neither are named colors, and in general it seems to spit out an error on every second line of a perfectly valid plain svg file (and forget about it if it has sodipodi tags), often producing a 0 byte file as it cannot handle any of the SVG inputs. Claiming it's a beta, is an insult to all betas - version 1.0.5 is even more laughable.

If it's just 1 simple SVG file like that, I highly recommend that you download the OpenVG reference implementation, and construct the data structures by hand in a way compatible with the rendering functions in the tiger example (basically hack up the tiger example). It should be the simplest method for such a small SVG file.

Das Gurke
08-09-2008, 10:06 AM
Sadly its not only that file :( So I will be hacking up my own simple SVG parser. Lets see how far I can take it.

iharrold
09-23-2008, 10:49 AM
I'm in a similar predicament. I have an OpenVG rendering application that I am writing that can take in SVG, JPEG, self defined XML content, and MPEG files and render them with effects.

I chose the OpenVG approach because it seems very promising, but I fear It may be to far ahead of its time at the moment...

I fear I may have to write an SVG parser myself. Creating the data object that stores the content seems to me to be the easiest part though. If anyone has any advice on what parser they have used and what not to use, I would appreciate it.

Thanks!

Das Gurke
09-24-2008, 11:41 PM
I am afraid my solution is not as "flexible" as I planned it. It is tied closer to my application (and even involves the wxWidgets Colour class to easy colour parsing) then it probably should :( But if you want to have a look how I did it (and what I did so far: http://word.gurxite.de/index.php?title=SVG_Support , i agree that its not too much, but the system can easily be extended!) just drop me an email and I can mail you the relevant sourcecode.

This very basic implementation allows the parsing of SVGs of the following style: http://word.gurxite.de/index.php?title= ... _vista.png (http://word.gurxite.de/index.php?title=Image:Wordingamescreen_373_vista.p ng)