[cairo] Contributing pyCairoChart
stevech1097 at yahoo.com.au
Thu May 25 17:15:08 PDT 2006
On Thu, 2006-05-25 at 14:26 +0200, Martin Lesser wrote:
> Steven Chaplin <stevech1097 at yahoo.com.au> writes:
> > Here's how I would modify it to support output to PNG/PS/PDF/SVG:
> > Make the draw_bars/data/dots/grid/lines methods private, so the public
> > API is just to create a Chart, set its attributes, and output the chart.
> > draw_*() methods are not explicitly called, the drawing is done
> > automatically by the out2png() method.
> There are some parameters I want to keep in the draw_*() methods
> (i.e. "dotting" a data-line) so at the moment I think about an instance
> member "drawn" as list which contains the parts of the chart which are
> already drawn so an explicit call to the draw-methods is no longer
> > Modify Chart.__init__ so it does not create the cairo surface, context
> > and matrix.
> That looks impossible for me: I need the cairo_t at an early stage
> especially for accessing the [text|font]_extents methods of pycairo and
> calculating the drawable area for the data. Additionally it could be an
> option to produce a warning if the text in title and/or legend would be
> too large for the given size of a chart.
> > Rename out2png() to output() and use something like:
> That's a good idea, I did that. But the filename (or fileobject) are now
> part of __init__ which then does a call of _cairosetup.
I've had a few more thoughts about creating PNG/SVG/PS/PDF charts.
Since the ImageSurface can write to a filename or a fileobject (like
sys.stdout) perhaps "write" is a better method name than "output" since
its more consistent with the Python file-like objects write methods.
Also, passing a filename argument and looking for '.svg' does not work
for file objects so it might be better to pass both a filename (or
fileobject) and a format.
(PS/PDF/SVG surfaces do not yet support writing to a file-like objects,
but they should do when I figure out how to write the binding function)
> The current version is available at
> (The documentation has to be updated but this will be done next week)
> > def output (self, _file):
> > ...
> > elif _file.endswith('.svg'):
> > if not cairo.HAS_SVG_SURFACE:
> > raise SystemExit ('cairo was not compiled with SVG support')
> > self.img = cairo.SVGSurface (_file, width_in_points,
> > height_in_points)
> My pycairo does not have the *SVG* members/methods also I compiled with
> SVG-support. But I can import cairo.svg which does not have the needed
> members/methods too. I'm using pycairo-1.0.2 built against cairo-1.1.6
> Did I miss something?
pycairo-1.0.2 has PSSurface and PDFSurface. The SVGSurface was added
after and is in CVS. cairo 1.2.0 should be released soon, then I can
release the corresponding pycairo 1.2.0.
Send instant messages to your online friends http://au.messenger.yahoo.com
More information about the cairo