[cairo-commit] pycairo/cairo Makefile.am, 1.4, 1.5 cairomodule.c,
1.4, 1.5 pycairo-context.c, 1.6, 1.7 pycairo-pattern.c, NONE,
1.1 pycairo-private.h, 1.2, 1.3 pycairo.h, 1.3, 1.4
Carl Worth
commit at pdx.freedesktop.org
Thu Nov 4 06:45:37 PST 2004
Committed by: cworth
Update of /cvs/cairo/pycairo/cairo
In directory gabe:/tmp/cvs-serv14511/cairo
Modified Files:
Makefile.am cairomodule.c pycairo-context.c pycairo-private.h
pycairo.h
Added Files:
pycairo-pattern.c
Log Message:
Fixes for set_pattern from Steve Chaplin
<stevech1097 at yahoo.com.au>:
* examples/cairo-knockout.py: Bring up-to-date with latest
cairo-knockout.c. Now uses cairo_arc rather than custom arc
approximation, and now uses new cairo.set_pattern.
* cairo/pycairo.h: Add declaration for struct PyCairoPattern.
* cairo/pycairo-context.c (pycairo_set_pattern): Re-enable
pycairo_set_pattern now that it uses PyCairoPattern_Type.
* cairo/cairomodule.c (init_cairo): Add PyCairoPattern_Type
* cairo/pycairo-pattern.c: New file to bind to cairo_pattern_t.
Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/Makefile.am,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- Makefile.am 3 Nov 2004 01:24:05 -0000 1.4
+++ Makefile.am 4 Nov 2004 14:45:35 -0000 1.5
@@ -15,6 +15,7 @@
pycairo-private.h \
pycairo-matrix.c \
pycairo-surface.c \
+ pycairo-pattern.c \
pycairo-font.c \
pycairo-context.c \
cairomodule.c
Index: cairomodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/cairomodule.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- cairomodule.c 14 Nov 2003 15:32:10 -0000 1.4
+++ cairomodule.c 4 Nov 2004 14:45:35 -0000 1.5
@@ -118,6 +118,7 @@
INIT_TYPE(PyCairoMatrix_Type);
INIT_TYPE(PyCairoSurface_Type);
+ INIT_TYPE(PyCairoPattern_Type);
INIT_TYPE(PyCairoFont_Type);
INIT_TYPE(PyCairoContext_Type);
@@ -127,6 +128,7 @@
PyModule_AddObject(mod, "Matrix", (PyObject *)&PyCairoMatrix_Type);
PyModule_AddObject(mod, "Surface", (PyObject *)&PyCairoSurface_Type);
+ PyModule_AddObject(mod, "Pattern", (PyObject *)&PyCairoPattern_Type);
PyModule_AddObject(mod, "Font", (PyObject *)&PyCairoFont_Type);
PyModule_AddObject(mod, "Context", (PyObject *)&PyCairoContext_Type);
Index: pycairo-context.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-context.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- pycairo-context.c 3 Nov 2004 01:24:05 -0000 1.6
+++ pycairo-context.c 4 Nov 2004 14:45:35 -0000 1.7
@@ -201,29 +201,21 @@
return Py_None;
}
-/* XXX: Looks like this function has not been ported from the old
- * cairo_surface_t* version of cairo_set_pattern to the new
- * cairo_pattern_t* version. I don't know enough about python bindings
- * to fix it, but I do know the current version won't work, so out it
- * goes.
- */
-#if 0
static PyObject *
pycairo_set_pattern(PyCairoContext *self, PyObject *args)
{
- PyCairoSurface *surface;
+ PyCairoPattern *pattern;
if (!PyArg_ParseTuple(args, "O!:Context.set_pattern",
- &PyCairoSurface_Type, &surface))
+ &PyCairoPattern_Type, &pattern))
return NULL;
- cairo_set_pattern(self->ctx, surface->surface);
+ cairo_set_pattern(self->ctx, pattern->pattern);
if (pycairo_check_status(cairo_status(self->ctx)))
return NULL;
Py_INCREF(Py_None);
return Py_None;
}
-#endif
static PyObject *
pycairo_set_tolerance(PyCairoContext *self, PyObject *args)
@@ -844,10 +836,7 @@
{ "set_operator", (PyCFunction)pycairo_set_operator, METH_VARARGS },
{ "set_rgb_color", (PyCFunction)pycairo_set_rgb_color, METH_VARARGS },
{ "set_alpha", (PyCFunction)pycairo_set_alpha, METH_VARARGS },
-/* XXX: set_pattern is currently broken. See above. */
-#if 0
{ "set_pattern", (PyCFunction)pycairo_set_pattern, METH_VARARGS },
-#endif
{ "set_tolerance", (PyCFunction)pycairo_set_tolerance, METH_VARARGS },
{ "set_fill_rule", (PyCFunction)pycairo_set_fill_rule, METH_VARARGS },
{ "set_line_width", (PyCFunction)pycairo_set_line_width, METH_VARARGS },
--- NEW FILE: pycairo-pattern.c ---
/* -*- mode: C; c-basic-offset: 4 -*- */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "pycairo-private.h"
PyObject *
pycairo_pattern_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyCairoPattern *self;
self = (PyCairoPattern *)type->tp_alloc(type, 0);
if (self != NULL) {
self->pattern = NULL;
}
return (PyObject *)self;
}
static int
pycairo_pattern_init(PyCairoPattern *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "x0", "y0", "x1", "y1",
"cx0", "cy0", "radius0", "cx1", "cy1", "radius1",
"surface",
NULL };
double x0 = -1.0, y0 = -1.0, x1 = -1.0, y1 = -1.0;
double cx0 =-1.0, cy0 =-1.0, radius0 =-1.0, cx1 =-1.0, cy1 =-1.0, radius1 =-1.0;
PyCairoSurface *surface = NULL;
cairo_pattern_t *pattern = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"|ddddddddddO!:Pattern.__init__", kwlist,
&x0, &y0, &x1, &y1,
&cx0, &cy0, &radius0,
&cx1, &cy1, &radius1,
&PyCairoSurface_Type, &surface
)) /* change to keywords only? */
return -1;
/* three alternative constructors */
if (x0 != -1.0 && y0 != -1.0 && x1 != -1.0 && y1 != -1.0) {
pattern = cairo_pattern_create_linear (x0, y0, x1, y1);
} else if (cx0 != -1.0 && cy0 != -1.0 && radius0 != -1.0 &&
cx1 != -1.0 && cy1 != -1.0 && radius1 != -1.0) {
pattern = cairo_pattern_create_radial (cx0, cy0, radius0,
cx1, cy1, radius1);
} else if (surface != NULL) {
pattern = cairo_pattern_create_for_surface (surface->surface);
} else {
PyErr_SetString(PyExc_ValueError, "incorrect arguments for pattern");
}
if (!pattern) {
PyErr_SetString(PyExc_RuntimeError, "could not create pattern");
return -1;
}
cairo_pattern_reference(pattern);
self->pattern = pattern;
return 0;
}
static void
pycairo_pattern_dealloc(PyCairoPattern *self)
{
if (self->pattern)
cairo_pattern_destroy(self->pattern);
self->pattern = NULL;
if (self->ob_type->tp_free)
self->ob_type->tp_free((PyObject *)self);
else
PyObject_Del(self);
}
/* Pattern methods */
static PyObject *
pycairo_pattern_add_color_stop(PyCairoPattern *self, PyObject *args)
{
double offset, red, green, blue, alpha;
cairo_status_t status;
if (!PyArg_ParseTuple(args, "ddddd:Pattern.add_color_stop",
&offset, &red, &green, &blue, &alpha))
return NULL;
status = cairo_pattern_add_color_stop (self->pattern, offset, red, green,
blue, alpha);
if (pycairo_check_status(status))
return NULL;
Py_INCREF(Py_None);
return Py_None;
}
static PyMethodDef pycairo_pattern_methods[] = {
{ "add_color_stop", (PyCFunction)pycairo_pattern_add_color_stop,
METH_VARARGS },
{ NULL, NULL, 0 }
};
PyTypeObject PyCairoPattern_Type = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
"cairo.Pattern", /* tp_name */
sizeof(PyCairoPattern), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)pycairo_pattern_dealloc, /* tp_dealloc */
(printfunc)0, /* tp_print */
(getattrfunc)0, /* tp_getattr */
(setattrfunc)0, /* tp_setattr */
(cmpfunc)0, /* tp_compare */
(reprfunc)0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
(hashfunc)0, /* tp_hash */
(ternaryfunc)0, /* tp_call */
(reprfunc)0, /* tp_str */
(getattrofunc)0, /* tp_getattro */
(setattrofunc)0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
"Pattern objects", /* tp_doc */
(traverseproc)0, /* tp_traverse */
(inquiry)0, /* tp_clear */
(richcmpfunc)0, /* tp_richcompare */
0, /* tp_weaklistoffset */
(getiterfunc)0, /* tp_iter */
(iternextfunc)0, /* tp_iternext */
pycairo_pattern_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
(PyTypeObject *)0, /* tp_base */
(PyObject *)0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)pycairo_pattern_init, /* tp_init */
(allocfunc)0, /* tp_alloc */
pycairo_pattern_new, /* tp_new */
0, /* tp_free */
(inquiry)0, /* tp_is_gc */
(PyObject *)0, /* tp_bases */
};
Index: pycairo-private.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-private.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- pycairo-private.h 28 Oct 2003 15:53:13 -0000 1.2
+++ pycairo-private.h 4 Nov 2004 14:45:35 -0000 1.3
@@ -12,6 +12,7 @@
extern PyTypeObject PyCairoMatrix_Type;
extern PyTypeObject PyCairoContext_Type;
extern PyTypeObject PyCairoSurface_Type;
+extern PyTypeObject PyCairoPattern_Type;
extern PyTypeObject PyCairoFont_Type;
int pycairo_check_status(cairo_status_t status);
@@ -20,6 +21,8 @@
PyObject *pycairo_matrix_new(cairo_matrix_t *matrix);
PyObject *pycairo_context_new(cairo_t *ctx);
PyObject *pycairo_surface_new(cairo_surface_t *surface);
+/*PyObject *pycairo_pattern_new(cairo_pattern_t *pattern); */
+PyObject *pycairo_pattern_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
PyObject *pycairo_font_new(cairo_font_t *font);
#endif
Index: pycairo.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- pycairo.h 28 Oct 2003 15:53:13 -0000 1.3
+++ pycairo.h 4 Nov 2004 14:45:35 -0000 1.4
@@ -23,6 +23,11 @@
typedef struct {
PyObject_HEAD
+ cairo_pattern_t *pattern;
+} PyCairoPattern;
+
+typedef struct {
+ PyObject_HEAD
cairo_font_t *font;
} PyCairoFont;
More information about the cairo-commit
mailing list