[cairo-commit] pycairo/cairo pycairo-surface.c, 1.82, 1.83 pycairo-pattern.c, 1.34, 1.35

Steve Chaplin commit at pdx.freedesktop.org
Wed Dec 27 09:01:08 PST 2006


Committed by: stevech1097

Update of /cvs/cairo/pycairo/cairo
In directory kemper:/tmp/cvs-serv7442/cairo

Modified Files:
	pycairo-surface.c pycairo-pattern.c 
Log Message:
'SC'

Index: pycairo-surface.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-surface.c,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -d -r1.82 -r1.83
--- pycairo-surface.c	21 Dec 2006 04:44:22 -0000	1.82
+++ pycairo-surface.c	27 Dec 2006 17:01:03 -0000	1.83
@@ -45,7 +45,13 @@
 /* Class Surface ---------------------------------------------------------- */
 
 /* PycairoSurface_FromSurface
- * Create a new PycairoSurface from a cairo_surface_t
+ * Create a new
+ *   PycairoImageSurface,
+ *   PycairoPDFSurface,
+ *   PycairoPSSurface,
+ *   PycairoSVGSurface,
+ *   PycairoWin32Surface, or
+ *   PycairoXlibSurface from a cairo_surface_t.
  * surface - a cairo_surface_t to 'wrap' into a Python object.
  *           it is unreferenced if the PycairoSurface creation fails, or if
  *           the cairo_surface_t has an error status
@@ -57,7 +63,7 @@
 PyObject *
 PycairoSurface_FromSurface (cairo_surface_t *surface, PyObject *base)
 {
-    PyTypeObject *type;
+    PyTypeObject *type = NULL;
     PyObject *o;
 
     assert (surface != NULL);

Index: pycairo-pattern.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-pattern.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- pycairo-pattern.c	11 Jun 2006 07:17:26 -0000	1.34
+++ pycairo-pattern.c	27 Dec 2006 17:01:03 -0000	1.35
@@ -39,11 +39,14 @@
 /* Class Pattern ---------------------------------------------------------- */
 
 /* PycairoPattern_FromPattern
- * Create a new PycairoSolidPattern, PycairoSurfacePattern,
- * PycairoLinearGradient or PycairoRadialGradient from a cairo_pattern_t.
+ * Create a new
+ *   PycairoSolidPattern,
+ *   PycairoSurfacePattern,
+ *   PycairoLinearGradient, or
+ *   PycairoRadialGradient 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.
+ *           it is unreferenced if the PycairoPattern creation fails, or if the
+ *           pattern has an error status.
  * Return value: New reference or NULL on failure
  */
 PyObject *
@@ -196,30 +199,22 @@
 static PyObject *
 solid_pattern_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
-    double red, green, blue;
-    double alpha = 1.0;
-    cairo_pattern_t *pattern;
-    PyObject *o;
-
-    if (!PyArg_ParseTuple (args, "ddd|d:SolidPattern.__new__",
-			   &red, &green, &blue, &alpha))
+    double r, g, b, a = 1.0;
+    if (!PyArg_ParseTuple (args, "ddd|d:SolidPattern.__new__", &r, &g, &b, &a))
 	return NULL;
+    return PycairoPattern_FromPattern (cairo_pattern_create_rgba (r, g, b, a));
+}
 
-    o = type->tp_alloc(type, 0);
-    if (o != NULL) {
-	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 *
+solid_pattern_get_rgba (PycairoSolidPattern *o)
+{
+    double red, green, blue, alpha;
+    cairo_pattern_get_rgba (o->pattern, &red, &green, &blue, &alpha);
+    return Py_BuildValue("(dddd)", red, green, blue, alpha);
 }
 
 static PyMethodDef solid_pattern_methods[] = {
+    {"get_rgba",       (PyCFunction)solid_pattern_get_rgba,      METH_NOARGS },
     {NULL, NULL, 0, NULL},
 };
 
@@ -274,25 +269,11 @@
 surface_pattern_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
     PycairoSurface *s;
-    cairo_pattern_t *pattern;
-    PyObject *o;
-
     if (!PyArg_ParseTuple (args, "O!:SurfacePattern.__new__",
 			   &PycairoSurface_Type, &s))
 	return NULL;
-
-    o = type->tp_alloc(type, 0);
-    if (o != NULL) {
-	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;
+    return PycairoPattern_FromPattern (
+	       cairo_pattern_create_for_surface (s->surface));
 }
 
 static PyObject *
@@ -484,25 +465,11 @@
 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 != NULL) {
-	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;
+    return PycairoPattern_FromPattern (
+               cairo_pattern_create_linear (x0, y0, x1, y1));
 }
 
 static PyMethodDef linear_gradient_methods[] = {
@@ -559,26 +526,12 @@
 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 != NULL) {
-	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;
+    return PycairoPattern_FromPattern (
+           cairo_pattern_create_radial (cx0, cy0, radius0, cx1, cy1, radius1));
 }
 
 static PyMethodDef radial_gradient_methods[] = {



More information about the cairo-commit mailing list