[wxPython-users] ANN: wxpsvg, SVG rendering for wxPython
Christopher Barker
Chris.Barker at noaa.gov
Tue Jul 3 11:56:18 PDT 2007
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:
<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" />
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.
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.
> 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.
> and you can get a hitbox from a
> path that makes hittesting trivial.
Or better yet, wx.GraphicsPath.Contains()
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.
-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 at noaa.gov
More information about the wxpython-users
mailing list