[cairo] Add get_width()/get_height() to pycairo svg surfaces
Steve
stevech1097 at yahoo.com.au
Tue Jul 29 17:41:51 PDT 2008
On Tue, 2008-07-29 at 01:03 -0700, cairo-request at cairographics.org
wrote:
This addition looks useful, but if getting the width and height from SVG
surfaces is useful for Python users then it would probably be useful for
other language bindings and C cairo users too. In that case it would be
better to add new functions
cairo_svg_surface_get_width
cairo_svg_surface_get_height
into cairo itself so that they become available to all language
bindings.
Regards,
Steve
> This change (ab)uses cairo_clip_extents to recover the size of an svg
> surface -- if you look at the svg clip code, you'll see that this will
> reliably return the size passed in to the surface creation function
> (although it will have passed through a double->short->double
> conversion).
>
> I found this helpful in using pycha to create some SVG pie charts.
>
> (btw, CVS, ick)
>
> Index: cairo/pycairo-surface.c
> ===================================================================
> RCS file: /cvs/cairo/pycairo/cairo/pycairo-surface.c,v
> retrieving revision 1.89
> diff -u -p -r1.89 pycairo-surface.c
> --- cairo/pycairo-surface.c 12 May 2008 12:06:37 -0000 1.89
> +++ cairo/pycairo-surface.c 29 Jul 2008 05:27:09 -0000
> @@ -972,12 +972,34 @@ svg_surface_new (PyTypeObject *type, PyO
> file);
> }
>
> +static PyObject *
> +svg_surface_get_height (PycairoXlibSurface *o)
> +{
> + cairo_t *cr = cairo_create (o->surface);
> + double x1, y1, x2, y2;
> + cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
> + cairo_destroy (cr);
> + return PyInt_FromLong (y2 - y1);
> +}
> +
> +static PyObject *
> +svg_surface_get_width (PycairoXlibSurface *o)
> +{
> + cairo_t *cr = cairo_create (o->surface);
> + double x1, y1, x2, y2;
> + cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
> + cairo_destroy (cr);
> + return PyInt_FromLong (x2 - x1);
> +}
> +
> static PyMethodDef svg_surface_methods[] = {
> /* TODO
> * cairo_svg_surface_restrict_to_version
> * cairo_svg_get_versions
> * cairo_svg_version_to_string
> */
> + {"get_height",(PyCFunction)svg_surface_get_height,
> METH_NOARGS },
> + {"get_width", (PyCFunction)svg_surface_get_width,
> METH_NOARGS },
> {NULL, NULL, 0, NULL},
> };
More information about the cairo
mailing list