[cairo-commit] pycairo/cairo pycairo-pattern.c, 1.10, 1.11 cairomodule.c, 1.16, 1.17 pycairo-surface.c, 1.12, 1.13

Steve Chaplin commit at pdx.freedesktop.org
Mon Apr 4 09:16:51 PDT 2005


Committed by: stevech1097

Update of /cvs/cairo/pycairo/cairo
In directory gabe:/tmp/cvs-serv21949/cairo

Modified Files:
	pycairo-pattern.c cairomodule.c pycairo-surface.c 
Log Message:
SC 2005/04/04

Index: pycairo-pattern.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-pattern.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- pycairo-pattern.c	4 Apr 2005 13:51:18 -0000	1.10
+++ pycairo-pattern.c	4 Apr 2005 16:16:49 -0000	1.11
@@ -74,16 +74,17 @@
 static PyObject *
 pycairo_pattern_create_for_surface(PyTypeObject *type, PyObject *args)
 {
+    PyCairoPattern *py_pattern;
     PyCairoSurface *py_surface;
-    PyCairoPattern *py_pattern = (PyCairoPattern *)type->tp_alloc(type, 0);
 
-    if (py_pattern) {
-	if (!PyArg_ParseTuple(args, "O!:Pattern.create_for_surface", 
-			      &PyCairoSurface_Type, &py_surface))
-	    return NULL;
+    if (!PyArg_ParseTuple(args, "O!:Pattern.create_for_surface", 
+			  &PyCairoSurface_Type, &py_surface))
+	return NULL;
+
+    py_pattern = (PyCairoPattern *)type->tp_alloc(type, 0);
+    if (py_pattern)
 	py_pattern->pattern = 
 	    cairo_pattern_create_for_surface (py_surface->surface);
-    }
     return (PyObject *)py_pattern;
 }
 
@@ -91,15 +92,17 @@
 static PyObject *
 pycairo_pattern_create_linear(PyTypeObject *type, PyObject *args)
 {
+    PyCairoPattern *py_pattern;
     double x0, y0, x1, y1;
-    PyCairoPattern *py_pattern = (PyCairoPattern *)type->tp_alloc(type, 0);
+    
+    if (!PyArg_ParseTuple(args, "dddd:Pattern.create_linear", 
+			  &x0, &y0, &x1, &y1))
+	return NULL;
 
-    if (py_pattern) {
-	if (!PyArg_ParseTuple(args, "dddd:Pattern.create_linear", 
-			      &x0, &y0, &x1, &y1))
-	    return NULL;
+    py_pattern = (PyCairoPattern *)type->tp_alloc(type, 0);
+    if (py_pattern)
 	py_pattern->pattern = cairo_pattern_create_linear (x0, y0, x1, y1);
-    }
+
     return (PyObject *)py_pattern;
 }
 
@@ -107,16 +110,18 @@
 static PyObject *
 pycairo_pattern_create_radial(PyTypeObject *type, PyObject *args)
 {
+    PyCairoPattern *py_pattern;
     double cx0, cy0, radius0, cx1, cy1, radius1;
-    PyCairoPattern *py_pattern = (PyCairoPattern *)type->tp_alloc(type, 0);
 
-    if (py_pattern) {
-	if (!PyArg_ParseTuple(args, "dddddd:Pattern.create_radial", 
-			      &cx0, &cy0, &radius0, &cx1, &cy1, &radius1))
-	    return NULL;
+    if (!PyArg_ParseTuple(args, "dddddd:Pattern.create_radial", 
+			  &cx0, &cy0, &radius0, &cx1, &cy1, &radius1))
+	return NULL;
+
+    py_pattern = (PyCairoPattern *)type->tp_alloc(type, 0);
+    if (py_pattern)
 	py_pattern->pattern = cairo_pattern_create_radial (cx0, cy0, radius0,
 							   cx1, cy1, radius1);
-    }
+
     return (PyObject *)py_pattern;
 }
 

Index: cairomodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/cairomodule.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- cairomodule.c	2 Apr 2005 13:31:25 -0000	1.16
+++ cairomodule.c	4 Apr 2005 16:16:49 -0000	1.17
@@ -86,56 +86,6 @@
     }
 }
 
-static PyObject *
-pycairo_image_surface_create_for_data(PyObject *self, PyObject *args)
-{
-    char *data;
-    cairo_format_t format;
-    int length, width, height, stride = -1;
-    cairo_surface_t *surface;
-
-    if (!PyArg_ParseTuple(args, "w#iii|i:surface_create_for_image",
-			  &data, &length, &format, &width, &height, &stride))
-	return NULL;
-
-    if (width <= 0) {
-	PyErr_SetString(PyExc_ValueError, "width must be positive");
-	return NULL;
-    }
-    if (height <= 0) {
-	PyErr_SetString(PyExc_ValueError, "height must be positive");
-	return NULL;
-    }
-    /* if stride is missing, calculate it from width */
-    if (stride < 0)
-	switch (format) {
-	case CAIRO_FORMAT_ARGB32:
-	    stride = width * 4;
-	    break;
-	case CAIRO_FORMAT_RGB24:
-	    stride = width * 3;
-	    break;
-	case CAIRO_FORMAT_A8:
-	    stride = width;
-	    break;
-	case CAIRO_FORMAT_A1:
-	    stride = (width + 1) / 8;
-	    break;
-	}
-    if (height * stride > length) {
-	PyErr_SetString(PyExc_TypeError, "buffer is not long enough");
-	return NULL;
-    }
-
-    surface = cairo_image_surface_create_for_data(data, format,
-						  width, height, stride);
-    if (!surface)
-	return PyErr_NoMemory();
-    /* should get surface to hold reference to buffer ... */
-
-    return pycairo_surface_wrap(surface);
-}
-
 #ifdef CAIRO_HAS_PS_SURFACE
 static PyObject *
 pycairo_ps_surface_create(PyObject *self, PyObject *args)
@@ -240,8 +190,6 @@
 
 
 static PyMethodDef cairo_functions[] = {
-    { "image_surface_create_for_data", (PyCFunction)pycairo_image_surface_create_for_data, METH_VARARGS, "" },
-    /* image_surface_create_for_png */
 #if 0
 #ifdef CAIRO_HAS_PDF_SURFACE
     { "pdf_surface_create", (PyCFunction)pycairo_pdf_surface_create, METH_VARARGS, "" },

Index: pycairo-surface.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-surface.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- pycairo-surface.c	30 Mar 2005 00:22:18 -0000	1.12
+++ pycairo-surface.c	4 Apr 2005 16:16:49 -0000	1.13
@@ -70,33 +70,79 @@
 static PyObject *
 pycairo_surface_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
-    PyCairoSurface *self = (PyCairoSurface *)type->tp_alloc(type, 0);
+    PyCairoSurface *self;
+    cairo_format_t format;
+    int width, height;
 
-    if (self)
-      self->surface = NULL;
+    if (!PyArg_ParseTuple(args, "iii:Surface.__new__",
+			  &format, &width, &height))
+	return NULL;
+
+    self = (PyCairoSurface *)type->tp_alloc(type, 0);
+    if (self){
+	self->surface = cairo_image_surface_create (format, width, height);
+	if (!self->surface){
+	    Py_DECREF(self);
+	    return PyErr_NoMemory();
+	}
+    }
     return (PyObject *)self;
 }
 
-static int
-pycairo_surface_init(PyCairoSurface *self, PyObject *args, PyObject *kwargs)
+/* alternative constructor */
+static PyObject *
+pycairo_surface_create_for_data(PyTypeObject *type, PyObject *args)
 {
-    cairo_surface_t *surface;
+    PyCairoSurface *py_surface;
+    char *data;
     cairo_format_t format;
-    int width, height;
+    int length, width, height, stride = -1;
 
-    if (!PyArg_ParseTuple(args, "iii:Surface.__init__",
-			  &format, &width, &height))
-	return -1;
+    if (!PyArg_ParseTuple(args, "w#iii|i:create_for_data",
+			  &data, &length, &format, &width, &height, &stride))
+	return NULL;
 
-    surface = cairo_image_surface_create (format, width, height);
-    if (!surface){
-	PyErr_NoMemory();
-	return -1;
+    if (width <= 0) {
+	PyErr_SetString(PyExc_ValueError, "width must be positive");
+	return NULL;
     }
-    self->surface = surface;
-    return 0;
+    if (height <= 0) {
+	PyErr_SetString(PyExc_ValueError, "height must be positive");
+	return NULL;
+    }
+    /* if stride is missing, calculate it from width */
+    if (stride < 0)
+	switch (format) {
+	case CAIRO_FORMAT_ARGB32:
+	    stride = width * 4;
+	    break;
+	case CAIRO_FORMAT_RGB24:
+	    stride = width * 3;
+	    break;
+	case CAIRO_FORMAT_A8:
+	    stride = width;
+	    break;
+	case CAIRO_FORMAT_A1:
+	    stride = (width + 1) / 8;
+	    break;
+	}
+    if (height * stride > length) {
+	PyErr_SetString(PyExc_TypeError, "buffer is not long enough");
+	return NULL;
+    }
+
+    py_surface = (PyCairoSurface *)type->tp_alloc(type, 0);
+    if (py_surface){
+	py_surface->surface = cairo_image_surface_create_for_data
+	    (data, format, width, height, stride);
+	if (!py_surface->surface) {
+	    Py_DECREF(py_surface);
+	    return PyErr_NoMemory();
+	}
+	/* TODO get surface to hold reference to buffer ... */
+    }
+    return (PyObject *)py_surface;
 }
- 
 
 static PyObject *
 pycairo_surface_create_similar(PyCairoSurface *self, PyObject *args)
@@ -215,8 +261,11 @@
 #endif  /* CAIRO_HAS_PDF_FUNCTIONS */
 
 static PyMethodDef pycairo_surface_methods[] = {
+    { "create_for_data", (PyCFunction)pycairo_surface_create_for_data, 
+                                                METH_VARARGS | METH_CLASS },
     { "create_similar", (PyCFunction)pycairo_surface_create_similar,
       METH_VARARGS },
+    /* (image_)surface_create_for_png */
     { "set_device_offset", (PyCFunction)pycairo_surface_set_device_offset, 
       METH_VARARGS },
     { "set_filter", (PyCFunction)pycairo_surface_set_filter, METH_VARARGS },
@@ -272,7 +321,8 @@
     0,                                  /* tp_descr_get */
     0,                                  /* tp_descr_set */
     0,                                  /* tp_dictoffset */
-    (initproc)pycairo_surface_init,     /* tp_init */
+    //(initproc)pycairo_surface_init,     /* tp_init */
+    (initproc)0,                        /* tp_init */
     (allocfunc)0,                       /* tp_alloc */
     pycairo_surface_new,                /* tp_new */
     0,                                  /* tp_free */




More information about the cairo-commit mailing list