ANN: wxpsvg, SVG rendering for wxPython

There's a lot of work to be done yet, but it can render a useful
subset of SVG documents. Built on top of wxGraphicsContext.

http://code.google.com/p/wxpsvg/

Anyone who's interested in helping, or just in using it and reporting
problems is welcome.

Rendering performance is quite snappy, and about as fast as it can get
in Python. Sadly, parsing and loading performance is not nearly so
good.

See http://code.google.com/p/wxpsvg/wiki/ReadMe for some details on
missing features and dependencies.

Currently only tested on Windows and Gtk.

“This project currently has no downloads.”

The are some users who might wanna use it or abuse it…

:wink:

I for one am interested in drawing boobs with it (abuse it).

Peter

···

On 6/27/07, Chris Mellon arkanes@gmail.com wrote:

There’s a lot of work to be done yet, but it can render a useful
subset of SVG documents. Built on top of wxGraphicsContext.

http://code.google.com/p/wxpsvg/

Anyone who’s interested in helping, or just in using it and reporting
problems is welcome.

Rendering performance is quite snappy, and about as fast as it can get
in Python. Sadly, parsing and loading performance is not nearly so

good.

See http://code.google.com/p/wxpsvg/wiki/ReadMe for some details on
missing features and dependencies.

Currently only tested on Windows and Gtk.


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org

For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org


There is NO FATE, we are the creators.

"This project currently has no downloads."

Try grabbing it out of the SVN repository:
http://code.google.com/p/wxpsvg/source

The are some users who might wanna use it or abuse
it...

:wink:

I for one am interested in drawing boobs with it
(abuse it).

Heh.

Gre7g

···

--- Peter Damoc <pdamoc@gmail.com> wrote:

____________________________________________________________________________________
Finding fabulous fares is fun.
Let Yahoo! FareChase search your favorite travel sites to find flight and hotel bargains.
http://farechase.yahoo.com/promo-generic-14795097

"This project currently has no downloads."

Only in the SVN, right now.

The are some users who might wanna use it or abuse it...

:wink:

I for one am interested in drawing boobs with it (abuse it).

There's no drawing functionality per se, it renders already existing
SVG documents. If you happen to have some boob-related SVG documents
laying around you can render those, though.

···

On 6/27/07, Peter Damoc <pdamoc@gmail.com> wrote:

Already downloaded, already managed to crash the thing trying to look at “animate-elem-03-t.svg”
Maybe the viewer should have a list control with a second column for “this is working” - “this is not working” kind of thing.

Also, I’m no expert in repository management BUT I believe that the tests and compliance files should be outside the implementation directory.

Anyway… great work.
Peter.

···

On 6/27/07, Gre7g Luterman hafeliel@yahoo.com wrote:

— Peter Damoc pdamoc@gmail.com wrote:

“This project currently has no downloads.”

Try grabbing it out of the SVN repository:

http://code.google.com/p/wxpsvg/source


There is NO FATE, we are the creators.

>
> > "This project currently has no downloads."
>
> Try grabbing it out of the SVN repository:
> Google Code Archive - Long-term storage for Google Code Project Hosting.
>

Already downloaded, already managed to crash the thing trying to look at
"animate-elem-03-t.svg"
Maybe the viewer should have a list control with a second column for "this
is working" - "this is not working" kind of thing.

There's something about the PNG file associated with that that crashes
wxImage. The w3c compliance suite is pretty terrible, I'm going to
rework that to get rid of a bunch of the useless tests and add some
more that test the stuff it skips over.

Also, I'm no expert in repository management BUT I believe that the tests
and compliance files should be outside the implementation directory.

"svg" is the package. This way you can run the tests with "python -m svg.tests".

···

On 6/27/07, Peter Damoc <pdamoc@gmail.com> wrote:

On 6/27/07, Gre7g Luterman <hafeliel@yahoo.com> wrote:
> --- Peter Damoc <pdamoc@gmail.com> wrote:

Anyway... great work.
Peter.

--
There is NO FATE, we are the creators.

Right now the boobs are rendered using a very ugly reimplementation of a bezier curve using DrawSpline. I’m sure I can do better with SVG

Alter SVG->Rerender is Drawing functionality in my book.

Peter

···

On 6/27/07, Chris Mellon arkanes@gmail.com wrote:

There’s no drawing functionality per se, it renders already existing
SVG documents. If you happen to have some boob-related SVG documents
laying around you can render those, though.


There is NO FATE, we are the creators.

I see now, my ignorance is corrected. Thanks!

Keep up the good work.
Peter.

···

On 6/27/07, Chris Mellon arkanes@gmail.com wrote:

“svg” is the package. This way you can run the tests with “python -m svg.tests”.


There is NO FATE, we are the creators.

For interested people:

I've checked in a couple screenshots:

(SVG rendering on the left, reference PNG on the right)

http://wxpsvg.googlecode.com/svn/trunk/screenshots/

Recent improvements have improved load times by 10x or more and
improved the reliability of the viewer.

···

On 6/27/07, Chris Mellon <arkanes@gmail.com> wrote:

There's a lot of work to be done yet, but it can render a useful
subset of SVG documents. Built on top of wxGraphicsContext.

Google Code Archive - Long-term storage for Google Code Project Hosting.

Anyone who's interested in helping, or just in using it and reporting
problems is welcome.

Rendering performance is quite snappy, and about as fast as it can get
in Python. Sadly, parsing and loading performance is not nearly so
good.

See Google Code Archive - Long-term storage for Google Code Project Hosting. for some details on
missing features and dependencies.

Currently only tested on Windows and Gtk.

Chris Mellon wrote:

Recent improvements have improved load times by 10x or more

What kind of improvements?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Bottleneck in the loading was parsing the SVG path data. Rewrote the
parser for it to avoid backtracking and spurious matching and got load
times for the butterfly down from 20 seconds to barely more than a
second.

Rendering has always been fast - the SVG tiger has over 120 paths in
it and renders in a tenth of a second on my home machine.

···

On 6/29/07, Robin Dunn <robin@alldunn.com> wrote:

Chris Mellon wrote:

> Recent improvements have improved load times by 10x or more

What kind of improvements?

Peter Damoc wrote:

Right now the boobs are rendered using a very ugly reimplementation of a bezier curve using DrawSpline. I'm sure I can do better with SVG

Alter SVG->Rerender is Drawing functionality in my book.

Sure, but all you really need is to use the GraphicsContext -- You can do Bezier Curves with it. see:

wxGraphicsPath::AddQuadCurveToPoint

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Chris Mellon wrote:
> There's not really that much to seperate. The SVG document is
> compiled into a list of drawing operations. Rendering the SVG is just
> a matter of iterating over the list and executing each operation.

Exactly. Maybe I've got SVG wrong, it it looks to me like somewhat of a
"Object model". That is, the components of the drawing are self
contained objects (though maybe dependent on other objects, like paths).
For instance, the snippet from InkScape SVG output:

There's an SVG object model in the form of the DOM, but it's for
scripting and isn't directly related to the rendering. In SVG, you
draw each element in turn, using a painters algorithm.
For example, your SVG fragment:

<rect

style="opacity:0;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:1.06922174;stroke-opacity:1"
        id="rect6147"
        width="98.345512"
        height="97.730423"
        x="83.533363"
        y="65.635414" />

Is compiled into this list of drawing operations:
wx.GraphicsContext.SetBrush, brush
wx.GraphicsContext.SetPen, pen
wx.GraphicsContext.StrokePath, path
wx.GraphicsContext.FillPath, path

The way my SVGDocument works is that as each element is visited during
parsing, the brush, pen, and path are created from the element
properties, and a list like this is built - it's a tuple of (callable,
arguments). Rendering the document is just a matter of iterating over
this list and making each call.

So this describes a Rectangle with various properties. Sure, you can
just immediately translate that into drawing calls, but you could also
create an object model, and then draw that. Indeed, that's how
FloatCanvas works -- everything in the drawing is an object, that has a
bunch of properties that describe it.

Currently, I'm not trying to expose an object model. SVGDocument is a
rendering interface, which takes an XML fragment and returns an object
that you can use to draw the object represented by that fragment. I
suppose it should have a better name :wink:

The advantage of the object model approach is that you can them work
with that model -- change things, add things, move things around, etc.

Maybe the way to do it is to simply work with an XML DOM, though, rather
than create an entire other object model that is translated to/from SVG.

The SVG standard defines a superset of the XML DOM called the SVG DOM.
It shouldn't be too hard to implement.

> It's not related to SVG per se, but theres a utility in there called
> drawer.py that lets you add operations to a wxGraphicsPath and updates
> a canvas in real time. I wrote it as a way of testing wxGC
> functionality but it might make a basis for a wxGC based drawing tool.

hmm. I'll have to check that out.

> Zooming and hittesting are extremly easy with wxGraphicsContext. You
> just push a scale factor for zoom,

I can't remember why I didn't use DC.SetUserScale to do zooming with
FloatCanvas -- maybe it was the restrictions of integer coords.
GraphicsContext doesn't have that restriction, so that may be a
simplification I can use. Unfortunately, some folks have found that
GraphicsContext is substantially slower than DCs for lots of objects, at
least on some platforms.

I find wxGC to be extremely fast in the general case. I don't know
what's considered "lots" of objects but the SVG tiger has 120+ paths
and renders in a quarter of a second on my underpowered windows work
machine. Just rectangles is a lot faster. An interesting phenomena
I've noticed is that the rendering speed is directly related to the
number of pixels that get pushed - scale the tiger up to 500x500, with
it all visible on screen, and it's slower. Scale it down to 10x10 and
the rendering is lightning fast. Move it off screen so that only a
portion shows, and it's even faster.

> and you can get a hitbox from a
> path that makes hittesting trivial.

Or better yet, wx.GraphicsPath.Contains()

This just creates the hitbox internally - if you're doing a lot of
hittesting, it's less efficent than just saving the box somewhere.

However, if there are a lot (10s of thousands) of objects, calling
Contains() on each one could be kind of poky.

> Scrolling is pretty much the same as anything else.

Support by GraphicsContext.Translate() it looks like.

> a wxGC based floatcanvas would be spectacular, feel free to take any
> code you want.

I hope I'll get a chance to work on this soon, and I'll be sure to check
out your code when I do.

> Theres quite a bit of functionality that needs to be added to the wxGC
> api in order to be able to fully render SVG. Some of it's trivial,
> some will be hard or even impossible.

Let's hope not impossible -- SVG seems to be a pretty good standard, and
a good measure of what should be possible to render with WX.

There's some noise on wx-dev about moving to cairo on all platforms.
Because of it's different back ends, cairo is already basically a
vector graphics API abstraction, and it's got all the features you
need for SVG (obviously), so I wouldn't be sad at all to see that
happen.

···

On 7/3/07, Christopher Barker <Chris.Barker@noaa.gov> wrote: