[reportlab-users] Setting custom shape-attributes via setProperties(...)

Dinu Gherman reportlab-users@reportlab.com
Thu, 16 Oct 2003 14:27:57 +0200


Markus Rechtien:

> I need to store additional attributes with the SVG elements.

This is an obvious requirement and it's amazing nobody came up
earlier with it. I'd like to know what kind of attributes you
actually need, maybe for interaction, or even animation?

> The ReportLab API enables to set custom shape properties
> via the setProperties(..) method.
> To get this additional data into the corrensponding SVG
> element I surely have to extend the renderer (or write my
> own..).

The easiest thing you can do to add anything you like is using
properties with leading underscores as shown here:

   >>> from reportlab.graphics.shapes import String
   >>> s = String(0,0, "foo")
   >>> s._url = "http://www.foo.com"

unless you want to modify the shapes' property attribute maps,
which might also work ok if you're in a slightly adventureous
mood.

You then need to modify renderSVG to make use of such additional
pseudo-properties. Depending on what you need this might be a
tough ride.

> The final question: Is this a valid way that will be
> supported in future or may there occur any changes
> which could make this impossible hereafter ?

The underscore thing is kind of a bypassing mechanism which I'd
expect to be further supported for a long time to come. If you
want a less "hackish" solution, proper attribute maps and vali-
dation stuff etc. I'd be more careful, because that might "some-
how" be converted to something based on Python slots, one day...

As an aside, you might have a need for SVG *elements* which just
don't have any virtual sibling in RLG space. If so, you'll need
some kind of virtual RLG shape which maps to something meaningful
in SVG, but which is ignored in all other renderers (of course,
unless these are "internal" SVG elements used only by the SVG
renderer). It would be nice to support that kind of "ignorance"
in other renderers without having to modify them all on the user
level... Robin?

Dinu

--
Dinu C. Gherman - http://python.net/~gherman
......................................................................
"The best way to predict the future is to invent it." (Alan Kay)