[cairo-commit] pycairo/cairo cairomodule.c, 1.48,
1.49 pycairo-context.c, 1.64, 1.65 pycairo.h, 1.41,
1.42 pycairo-private.h, 1.32, 1.33 pycairo-pattern.c, 1.27, 1.28
Steve Chaplin
commit at pdx.freedesktop.org
Mon Aug 29 07:52:33 PDT 2005
Committed by: stevech1097
Update of /cvs/cairo/pycairo/cairo
In directory gabe:/tmp/cvs-serv22702/cairo
Modified Files:
cairomodule.c pycairo-context.c pycairo.h pycairo-private.h
pycairo-pattern.c
Log Message:
'SC'
Index: cairomodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/cairomodule.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- cairomodule.c 22 Aug 2005 06:37:37 -0000 1.48
+++ cairomodule.c 29 Aug 2005 14:52:30 -0000 1.49
@@ -78,7 +78,15 @@
&PycairoFontOptions_Type, PycairoFontOptions_FromFontOptions,
&PycairoMatrix_Type, PycairoMatrix_FromMatrix,
&PycairoPath_Type, PycairoPath_FromPath,
- &PycairoPattern_Type, PycairoPattern_FromPattern,
+
+ &PycairoPattern_Type,
+ &PycairoSolidPattern_Type,
+ &PycairoSurfacePattern_Type,
+ &PycairoGradient_Type,
+ &PycairoLinearGradient_Type,
+ &PycairoRadialGradient_Type,
+ PycairoPattern_FromPattern,
+
&PycairoScaledFont_Type, PycairoScaledFont_FromScaledFont,
&PycairoSurface_Type,
@@ -143,9 +151,26 @@
PycairoPath_Type.tp_base = &PyBaseObject_Type;
if (PyType_Ready(&PycairoPath_Type) < 0)
return;
+
PycairoPattern_Type.tp_base = &PyBaseObject_Type;
if (PyType_Ready(&PycairoPattern_Type) < 0)
return;
+ PycairoSolidPattern_Type.tp_base = &PycairoPattern_Type;
+ if (PyType_Ready(&PycairoSolidPattern_Type) < 0)
+ return;
+ PycairoSurfacePattern_Type.tp_base = &PycairoPattern_Type;
+ if (PyType_Ready(&PycairoSurfacePattern_Type) < 0)
+ return;
+ PycairoGradient_Type.tp_base = &PycairoPattern_Type;
+ if (PyType_Ready(&PycairoGradient_Type) < 0)
+ return;
+ PycairoLinearGradient_Type.tp_base = &PycairoGradient_Type;
+ if (PyType_Ready(&PycairoLinearGradient_Type) < 0)
+ return;
+ PycairoRadialGradient_Type.tp_base = &PycairoGradient_Type;
+ if (PyType_Ready(&PycairoRadialGradient_Type) < 0)
+ return;
+
PycairoScaledFont_Type.tp_base = &PyBaseObject_Type;
if (PyType_Ready(&PycairoScaledFont_Type) < 0)
return;
@@ -188,6 +213,21 @@
*/
Py_INCREF(&PycairoPattern_Type);
PyModule_AddObject(m, "Pattern", (PyObject *)&PycairoPattern_Type);
+ Py_INCREF(&PycairoSolidPattern_Type);
+ PyModule_AddObject(m, "SolidPattern",
+ (PyObject *)&PycairoSolidPattern_Type);
+ Py_INCREF(&PycairoSurfacePattern_Type);
+ PyModule_AddObject(m, "SurfacePattern",
+ (PyObject *)&PycairoSurfacePattern_Type);
+ Py_INCREF(&PycairoGradient_Type);
+ PyModule_AddObject(m, "Gradient", (PyObject *)&PycairoGradient_Type);
+ Py_INCREF(&PycairoLinearGradient_Type);
+ PyModule_AddObject(m, "LinearGradient",
+ (PyObject *)&PycairoLinearGradient_Type);
+ Py_INCREF(&PycairoRadialGradient_Type);
+ PyModule_AddObject(m, "RadialGradient",
+ (PyObject *)&PycairoRadialGradient_Type);
+
Py_INCREF(&PycairoScaledFont_Type);
PyModule_AddObject(m, "ScaledFont", (PyObject *)&PycairoScaledFont_Type);
Index: pycairo-context.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-context.c,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- pycairo-context.c 19 Aug 2005 02:46:54 -0000 1.64
+++ pycairo-context.c 29 Aug 2005 14:52:30 -0000 1.65
@@ -379,7 +379,10 @@
{
cairo_pattern_t *pattern = cairo_get_source (o->ctx);
cairo_pattern_reference (pattern);
- return PycairoPattern_FromPattern (pattern);
+ /* bug #2765 - "How do we identify surface (and pattern) types?"
+ * should pass pattern type as arg2
+ */
+ return PycairoPattern_FromPattern (pattern, NULL);
}
static PyObject *
Index: pycairo.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo.h,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- pycairo.h 23 Jul 2005 04:41:41 -0000 1.41
+++ pycairo.h 29 Aug 2005 14:52:30 -0000 1.42
@@ -1,4 +1,4 @@
-/* -*- mode: C; c-basic-offset: 4 -*-
+/* -*- mode: C; c-basic-offset: 4 -*-
*
* Pycairo - Python bindings for cairo
*
@@ -67,6 +67,12 @@
cairo_pattern_t *pattern;
} PycairoPattern;
+#define PycairoSolidPattern PycairoPattern
+#define PycairoSurfacePattern PycairoPattern
+#define PycairoGradient PycairoPattern
+#define PycairoLinearGradient PycairoPattern
+#define PycairoRadialGradient PycairoPattern
+
typedef struct {
PyObject_HEAD
cairo_scaled_font_t *scaled_font;
@@ -101,8 +107,16 @@
PyObject *(*Matrix_FromMatrix)(const cairo_matrix_t *matrix);
PyTypeObject *Path_Type;
PyObject *(*Path_FromPath)(cairo_path_t *path);
+
PyTypeObject *Pattern_Type;
- PyObject *(*Pattern_FromPattern)(cairo_pattern_t *pattern);
+ PyTypeObject *SolidPattern_Type;
+ PyTypeObject *SurfacePattern_Type;
+ PyTypeObject *Gradient_Type;
+ PyTypeObject *LinearGradient_Type;
+ PyTypeObject *RadialGradient_Type;
+ PyObject *(*Pattern_FromPattern)(cairo_pattern_t *pattern,
+ PyTypeObject *type);
+
PyTypeObject *ScaledFont_Type;
PyObject *(*ScaledFont_FromScaledFont)(cairo_scaled_font_t *scaled_font);
@@ -111,7 +125,7 @@
PyTypeObject *PDFSurface_Type;
PyTypeObject *PSSurface_Type;
PyTypeObject *Win32Surface_Type;
- PyObject *(*Surface_FromSurface)(cairo_surface_t *surface,
+ PyObject *(*Surface_FromSurface)(cairo_surface_t *surface,
PyTypeObject *type, PyObject *base);
/* misc functions */
@@ -133,8 +147,15 @@
#define PycairoMatrix_FromMatrix (Pycairo_CAPI->Matrix_FromMatrix)
#define PycairoPath_Type *(Pycairo_CAPI->Path_Type)
#define PycairoPath_FromPath (Pycairo_CAPI->Path_FromPath)
+
#define PycairoPattern_Type *(Pycairo_CAPI->Pattern_Type)
+#define PycairoSolidPattern_Type *(Pycairo_CAPI->SolidPattern_Type)
+#define PycairoSurfacePattern_Type *(Pycairo_CAPI->SurfacePattern_Type)
+#define PycairoGradient_Type *(Pycairo_CAPI->Gradient_Type)
+#define PycairoLinearGradient_Type *(Pycairo_CAPI->LinearGradient_Type)
+#define PycairoRadialGradient_Type *(Pycairo_CAPI->RadialGradient_Type)
#define PycairoPattern_FromPattern (Pycairo_CAPI->Pattern_FromPattern)
+
#define PycairoScaledFont_Type *(Pycairo_CAPI->ScaledFont_Type)
#define PycairoScaledFont_FromScaledFont \
(Pycairo_CAPI->ScaledFont_FromScaledFont)
Index: pycairo-private.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-private.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- pycairo-private.h 23 Jul 2005 04:41:41 -0000 1.32
+++ pycairo-private.h 29 Aug 2005 14:52:30 -0000 1.33
@@ -1,4 +1,4 @@
-/* -*- mode: C; c-basic-offset: 4 -*-
+/* -*- mode: C; c-basic-offset: 4 -*-
*
* Pycairo - Python bindings for cairo
*
@@ -59,7 +59,13 @@
PyObject *PycairoPath_FromPath (cairo_path_t *path);
extern PyTypeObject PycairoPattern_Type;
-PyObject *PycairoPattern_FromPattern (cairo_pattern_t *pattern);
+extern PyTypeObject PycairoSolidPattern_Type;
+extern PyTypeObject PycairoSurfacePattern_Type;
+extern PyTypeObject PycairoGradient_Type;
+extern PyTypeObject PycairoLinearGradient_Type;
+extern PyTypeObject PycairoRadialGradient_Type;
+PyObject *PycairoPattern_FromPattern (cairo_pattern_t *pattern,
+ PyTypeObject *type);
extern PyTypeObject PycairoScaledFont_Type;
PyObject *PycairoScaledFont_FromScaledFont (cairo_scaled_font_t *scaled_font);
@@ -79,7 +85,7 @@
extern PyTypeObject PycairoWin32Surface_Type;
#endif
-PyObject *PycairoSurface_FromSurface (cairo_surface_t *surface,
+PyObject *PycairoSurface_FromSurface (cairo_surface_t *surface,
PyTypeObject *type,
PyObject *base);
Index: pycairo-pattern.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-pattern.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- pycairo-pattern.c 19 Aug 2005 02:46:55 -0000 1.27
+++ pycairo-pattern.c 29 Aug 2005 14:52:30 -0000 1.28
@@ -36,15 +36,20 @@
#include "pycairo-private.h"
+/* Class Pattern ---------------------------------------------------------- */
+
/* PycairoPattern_FromPattern
* Create a new PycairoPattern from a cairo_pattern_t
* pattern - a cairo_pattern_t to 'wrap' into a Python object.
* pattern is unreferenced if the PycairoPattern creation fails, or
* if the pattern is in an error status.
+ * type - the type of the object to instantiate; it can be NULL,
+ * meaning a base cairo.Pattern type, or it can be a subclass of
+ * cairo.Pattern
* Return value: New reference or NULL on failure
*/
PyObject *
-PycairoPattern_FromPattern (cairo_pattern_t *pattern)
+PycairoPattern_FromPattern (cairo_pattern_t *pattern, PyTypeObject *type)
{
PyObject *o;
@@ -55,11 +60,14 @@
return NULL;
}
- o = PycairoPattern_Type.tp_alloc (&PycairoPattern_Type, 0);
- if (o)
+ if (type == NULL)
+ type = &PycairoPattern_Type;
+ o = PycairoPattern_Type.tp_alloc (type, 0);
+ if (o) {
((PycairoPattern *)o)->pattern = pattern;
- else
+ } else {
cairo_pattern_destroy (pattern);
+ }
return o;
}
@@ -89,105 +97,207 @@
}
static PyObject *
-pattern_create_for_surface (PyTypeObject *type, PyObject *args)
+pattern_get_matrix (PycairoPattern *o)
{
- PycairoSurface *s;
- cairo_pattern_t *pattern;
-
- if (!PyArg_ParseTuple (args, "O!:Pattern.create_for_surface",
- &PycairoSurface_Type, &s))
- return NULL;
-
- pattern = cairo_pattern_create_for_surface (s->surface);
- return PycairoPattern_FromPattern (pattern);
+ cairo_matrix_t matrix;
+ cairo_pattern_get_matrix (o->pattern, &matrix);
+ return PycairoMatrix_FromMatrix (&matrix);
}
static PyObject *
-pattern_create_linear (PyTypeObject *type, PyObject *args)
+pattern_set_matrix (PycairoPattern *o, PyObject *args)
{
- double x0, y0, x1, y1;
- cairo_pattern_t *pattern;
+ PycairoMatrix *m;
- if (!PyArg_ParseTuple(args, "dddd:Pattern.create_linear",
- &x0, &y0, &x1, &y1))
+ if (!PyArg_ParseTuple (args, "O!:Pattern.set_matrix",
+ &PycairoMatrix_Type, &m))
return NULL;
- pattern = cairo_pattern_create_linear (x0, y0, x1, y1);
- return PycairoPattern_FromPattern (pattern);
+ cairo_pattern_set_matrix (o->pattern, &m->matrix);
+ Py_RETURN_NONE;
}
+static PyMethodDef pattern_methods[] = {
+ /* methods never exposed in a language binding:
+ * cairo_pattern_destroy()
+ * cairo_pattern_reference()
+ *
+ * cairo_pattern_status()
+ * - not needed since Pycairo handles status checking
+ */
+ {"get_matrix", (PyCFunction)pattern_get_matrix, METH_NOARGS },
+ {"set_matrix", (PyCFunction)pattern_set_matrix, METH_VARARGS },
+ {NULL, NULL, 0, NULL},
+};
+
+PyTypeObject PycairoPattern_Type = {
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.Pattern", /* tp_name */
+ sizeof(PycairoPattern), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ (destructor)pattern_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,/* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ pattern_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PyBaseObject_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)pattern_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
+};
+
+
+/* Class SolidPattern ----------------------------------------------------- */
+
static PyObject *
-pattern_create_radial (PyTypeObject *type, PyObject *args)
+solid_pattern_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
{
+ double red, green, blue;
+ double alpha = 1.0;
cairo_pattern_t *pattern;
- double cx0, cy0, radius0, cx1, cy1, radius1;
+ PyObject *o;
- if (!PyArg_ParseTuple(args, "dddddd:Pattern.create_radial",
- &cx0, &cy0, &radius0, &cx1, &cy1, &radius1))
+ if (!PyArg_ParseTuple (args, "ddd|d:SolidPattern.__new__",
+ &red, &green, &blue, &alpha))
return NULL;
- pattern = cairo_pattern_create_radial (cx0, cy0, radius0,
- cx1, cy1, radius1);
- return PycairoPattern_FromPattern (pattern);
+ o = type->tp_alloc(type, 0);
+ if (o) {
+ pattern = cairo_pattern_create_rgba (red, green, blue, alpha);
+
+ if (Pycairo_Check_Status (cairo_pattern_status (pattern))) {
+ cairo_pattern_destroy (pattern);
+ Py_DECREF(o);
+ return NULL;
+ }
+ ((PycairoSolidPattern *)o)->pattern = pattern;
+ }
+ return o;
}
-static PyObject *
-pattern_add_color_stop_rgb (PycairoPattern *o, PyObject *args)
-{
- double offset, red, green, blue;
+static PyMethodDef solid_pattern_methods[] = {
+ {NULL, NULL, 0, NULL},
+};
- if (!PyArg_ParseTuple(args, "dddd:Pattern.add_color_stop_rgb",
- &offset, &red, &green, &blue))
- return NULL;
+PyTypeObject PycairoSolidPattern_Type = {
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.SolidPattern", /* tp_name */
+ sizeof(PycairoSolidPattern), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ solid_pattern_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PyPattern_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)solid_pattern_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
+};
- cairo_pattern_add_color_stop_rgb (o->pattern, offset, red, green, blue);
- if (Pycairo_Check_Status (cairo_pattern_status (o->pattern)))
- return NULL;
- Py_RETURN_NONE;
-}
+/* Class SurfacePattern --------------------------------------------------- */
static PyObject *
-pattern_add_color_stop_rgba (PycairoPattern *o, PyObject *args)
+surface_pattern_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
{
- double offset, red, green, blue, alpha;
+ PycairoSurface *s;
+ cairo_pattern_t *pattern;
+ PyObject *o;
- if (!PyArg_ParseTuple(args, "ddddd:Pattern.add_color_stop_rgba",
- &offset, &red, &green, &blue, &alpha))
+ if (!PyArg_ParseTuple (args, "O!:SurfacePattern.__new__",
+ &PycairoSurface_Type, &s))
return NULL;
- cairo_pattern_add_color_stop_rgba (o->pattern, offset, red,
- green, blue, alpha);
- if (Pycairo_Check_Status (cairo_pattern_status (o->pattern)))
- return NULL;
- Py_RETURN_NONE;
+ o = type->tp_alloc(type, 0);
+ if (o) {
+ pattern = cairo_pattern_create_for_surface (s->surface);
+
+ if (Pycairo_Check_Status (cairo_pattern_status (pattern))) {
+ cairo_pattern_destroy (pattern);
+ Py_DECREF(o);
+ return NULL;
+ }
+ ((PycairoSurfacePattern *)o)->pattern = pattern;
+ }
+ return o;
}
static PyObject *
-pattern_get_extend (PycairoPattern *o)
+surface_pattern_get_extend (PycairoSurfacePattern *o)
{
return PyInt_FromLong (cairo_pattern_get_extend (o->pattern));
}
static PyObject *
-pattern_get_filter (PycairoPattern *o)
+surface_pattern_get_filter (PycairoSurfacePattern *o)
{
return PyInt_FromLong (cairo_pattern_get_filter (o->pattern));
}
static PyObject *
-pattern_get_matrix (PycairoPattern *o)
-{
- cairo_matrix_t matrix;
- cairo_pattern_get_matrix (o->pattern, &matrix);
- return PycairoMatrix_FromMatrix (&matrix);
-}
-
-static PyObject *
-pattern_set_extend (PycairoPattern *o, PyObject *args)
+surface_pattern_set_extend (PycairoSurfacePattern *o, PyObject *args)
{
int extend;
- if (!PyArg_ParseTuple(args, "i:Pattern.set_extend", &extend))
+ if (!PyArg_ParseTuple(args, "i:SurfacePattern.set_extend", &extend))
return NULL;
cairo_pattern_set_extend (o->pattern, extend);
@@ -195,64 +305,202 @@
}
static PyObject *
-pattern_set_filter (PycairoPattern *o, PyObject *args)
+surface_pattern_set_filter (PycairoSurfacePattern *o, PyObject *args)
{
int filter;
- if (!PyArg_ParseTuple (args, "i:Pattern.set_filter", &filter))
+ if (!PyArg_ParseTuple (args, "i:SurfacePattern.set_filter", &filter))
return NULL;
cairo_pattern_set_filter (o->pattern, filter);
Py_RETURN_NONE;
}
+static PyMethodDef surface_pattern_methods[] = {
+ {"get_extend", (PyCFunction)surface_pattern_get_extend, METH_NOARGS },
+ {"get_filter", (PyCFunction)surface_pattern_get_filter, METH_NOARGS },
+ {"set_extend", (PyCFunction)surface_pattern_set_extend, METH_VARARGS },
+ {"set_filter", (PyCFunction)surface_pattern_set_filter, METH_VARARGS },
+ {NULL, NULL, 0, NULL},
+};
+
+PyTypeObject PycairoSurfacePattern_Type = {
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.SurfacePattern", /* tp_name */
+ sizeof(PycairoSurfacePattern), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ surface_pattern_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PycairoPattern_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)surface_pattern_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
+};
+
+/* Class Gradient --------------------------------------------------------- */
+
+static PyObject *
+gradient_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PyErr_SetString(PyExc_TypeError,
+ "The Gradient type cannot be instantiated");
+ return NULL;
+}
+
+static PyObject *
+gradient_add_color_stop_rgb (PycairoGradient *o, PyObject *args)
+{
+ double offset, red, green, blue;
+
+ if (!PyArg_ParseTuple(args, "dddd:Gradient.add_color_stop_rgb",
+ &offset, &red, &green, &blue))
+ return NULL;
+
+ cairo_pattern_add_color_stop_rgb (o->pattern, offset, red, green, blue);
+ if (Pycairo_Check_Status (cairo_pattern_status (o->pattern)))
+ return NULL;
+ Py_RETURN_NONE;
+}
+
static PyObject *
-pattern_set_matrix (PycairoPattern *o, PyObject *args)
+gradient_add_color_stop_rgba (PycairoGradient *o, PyObject *args)
{
- PycairoMatrix *m;
+ double offset, red, green, blue, alpha;
- if (!PyArg_ParseTuple (args, "O!:Pattern.set_matrix",
- &PycairoMatrix_Type, &m))
+ if (!PyArg_ParseTuple(args, "ddddd:Gradient.add_color_stop_rgba",
+ &offset, &red, &green, &blue, &alpha))
return NULL;
- cairo_pattern_set_matrix (o->pattern, &m->matrix);
+ cairo_pattern_add_color_stop_rgba (o->pattern, offset, red,
+ green, blue, alpha);
+ if (Pycairo_Check_Status (cairo_pattern_status (o->pattern)))
+ return NULL;
Py_RETURN_NONE;
}
-static PyMethodDef pattern_methods[] = {
- /* methods never exposed in a language binding:
- * cairo_pattern_destroy()
- * cairo_pattern_reference()
- *
- * cairo_pattern_status()
- * - not needed since Pycairo handles status checking
- */
- {"add_color_stop_rgb",(PyCFunction)pattern_add_color_stop_rgb,
+static PyMethodDef gradient_methods[] = {
+ {"add_color_stop_rgb",(PyCFunction)gradient_add_color_stop_rgb,
METH_VARARGS },
- {"add_color_stop_rgba",(PyCFunction)pattern_add_color_stop_rgba,
+ {"add_color_stop_rgba",(PyCFunction)gradient_add_color_stop_rgba,
METH_VARARGS },
- {"create_for_surface",(PyCFunction)pattern_create_for_surface,
- METH_VARARGS | METH_CLASS },
- {"create_linear", (PyCFunction)pattern_create_linear,
- METH_VARARGS | METH_CLASS },
- {"create_radial", (PyCFunction)pattern_create_radial,
- METH_VARARGS | METH_CLASS },
- {"get_extend", (PyCFunction)pattern_get_extend, METH_NOARGS },
- {"get_filter", (PyCFunction)pattern_get_filter, METH_NOARGS },
- {"get_matrix", (PyCFunction)pattern_get_matrix, METH_NOARGS },
- {"set_extend", (PyCFunction)pattern_set_extend, METH_VARARGS },
- {"set_filter", (PyCFunction)pattern_set_filter, METH_VARARGS },
- {"set_matrix", (PyCFunction)pattern_set_matrix, METH_VARARGS },
{NULL, NULL, 0, NULL},
};
-PyTypeObject PycairoPattern_Type = {
+PyTypeObject PycairoGradient_Type = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
- "cairo.Pattern", /* tp_name */
- sizeof(PycairoPattern), /* tp_basicsize */
+ "cairo.Gradient", /* tp_name */
+ sizeof(PycairoGradient), /* tp_basicsize */
0, /* tp_itemsize */
- (destructor)pattern_dealloc, /* tp_dealloc */
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,/* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ gradient_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PycairoPattern_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)gradient_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
+};
+
+/* Class LinearGradient --------------------------------------------------- */
+
+static PyObject *
+linear_gradient_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ double x0, y0, x1, y1;
+ cairo_pattern_t *pattern;
+ PyObject *o;
+
+ if (!PyArg_ParseTuple(args, "dddd:LinearGradient.__new__",
+ &x0, &y0, &x1, &y1))
+ return NULL;
+
+ o = type->tp_alloc(type, 0);
+ if (o) {
+ pattern = cairo_pattern_create_linear (x0, y0, x1, y1);
+
+ if (Pycairo_Check_Status (cairo_pattern_status (pattern))) {
+ cairo_pattern_destroy (pattern);
+ Py_DECREF(o);
+ return NULL;
+ }
+ ((PycairoLinearGradient *)o)->pattern = pattern;
+ }
+ return o;
+}
+
+static PyMethodDef linear_gradient_methods[] = {
+ {NULL, NULL, 0, NULL},
+};
+
+PyTypeObject PycairoLinearGradient_Type = {
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.LinearGradient", /* tp_name */
+ sizeof(PycairoLinearGradient), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ 0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
@@ -275,17 +523,93 @@
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
- pattern_methods, /* tp_methods */
+ linear_gradient_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
- 0, /* &PyBaseObject_Type, */ /* tp_base */
+ 0, /* &PycairoGradient_Type, */ /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
- (newfunc)pattern_new, /* tp_new */
+ (newfunc)linear_gradient_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
+};
+
+/* Class RadialGradient --------------------------------------------------- */
+
+static PyObject *
+radial_gradient_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ cairo_pattern_t *pattern;
+ double cx0, cy0, radius0, cx1, cy1, radius1;
+ PyObject *o;
+
+ if (!PyArg_ParseTuple(args, "dddddd:RadialGradient.__new__",
+ &cx0, &cy0, &radius0, &cx1, &cy1, &radius1))
+ return NULL;
+
+ o = type->tp_alloc(type, 0);
+ if (o) {
+ pattern = cairo_pattern_create_radial (cx0, cy0, radius0,
+ cx1, cy1, radius1);
+ if (Pycairo_Check_Status (cairo_pattern_status (pattern))) {
+ cairo_pattern_destroy (pattern);
+ Py_DECREF(o);
+ return NULL;
+ }
+ ((PycairoRadialGradient *)o)->pattern = pattern;
+ }
+ return o;
+}
+
+static PyMethodDef radial_gradient_methods[] = {
+ {NULL, NULL, 0, NULL},
+};
+
+PyTypeObject PycairoRadialGradient_Type = {
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.RadialGradient", /* tp_name */
+ sizeof(PycairoRadialGradient), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ radial_gradient_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PycairoGradient_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)radial_gradient_new, /* tp_new */
0, /* tp_free */
0, /* tp_is_gc */
0, /* tp_bases */
More information about the cairo-commit
mailing list