[cairo-commit] pycairo/cairo pycairo-surface.c,1.27,1.28

Steve Chaplin commit at pdx.freedesktop.org
Tue Apr 26 20:54:04 PDT 2005


Committed by: stevech1097

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

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

Index: pycairo-surface.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-surface.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- pycairo-surface.c	25 Apr 2005 04:12:31 -0000	1.27
+++ pycairo-surface.c	27 Apr 2005 03:54:02 -0000	1.28
@@ -208,20 +208,15 @@
 
 #ifdef CAIRO_HAS_PNG_FUNCTIONS
 static PyObject *
-surface_write_png(PyCairoSurface *s, PyObject *args)
+surface_write_to_png(PyCairoSurface *s, PyObject *args)
 {
-    /*PyObject *file_object;*/
-    char *filename;
+    const char *filename;
     cairo_status_t status;
 
-    /*if (!PyArg_ParseTuple(args, "O!:Surface.write_png",
-      &PyFile_Type, &file_object)) */
-    if (!PyArg_ParseTuple(args, "S:Surface.write_png",
-			  filename))
+    if (!PyArg_ParseTuple(args, "s:Surface.write_to_png", &filename))
 	return NULL;
 
-    /*status = cairo_surface_write_png(s->surface, PyFile_AsFile(file_object));*/
-    status = cairo_surface_write_png(s->surface, filename);
+    status = cairo_surface_write_to_png(s->surface, filename);
     if (pycairo_check_status(status))
 	return NULL;
     Py_RETURN_NONE;
@@ -238,7 +233,8 @@
     { "set_matrix",     (PyCFunction)surface_set_matrix,        METH_VARARGS },
     { "set_repeat",     (PyCFunction)surface_set_repeat,        METH_VARARGS },
 #ifdef CAIRO_HAS_PNG_FUNCTIONS
-    { "write_png",      (PyCFunction)surface_write_png,         METH_VARARGS },
+    { "write_to_png",   (PyCFunction)surface_write_to_png,      METH_VARARGS },
+    /* write_to_png_stream */
 #endif
     { NULL, NULL, 0 }
 };
@@ -458,19 +454,14 @@
 image_surface_create_from_png(PyTypeObject *type, PyObject *args)
 {
     PyObject *s;
-    /*PyObject *file_object;*/
     char *filename;
     cairo_surface_t *surface;
-    /*int width=0, height=0;*/
 
-    /*if (!PyArg_ParseTuple(args, "O!:Surface.create_from_png",
-      &PyFile_Type, &file_object))*/
     if (!PyArg_ParseTuple(args, "S:Surface.create_from_png",
 			  filename))
 	return NULL;
 
     surface = cairo_image_surface_create_from_png(filename);
-	/*(PyFile_AsFile(file_object), &width, &height);*/
     if (!surface) {
 	PyErr_SetString(PyExc_ValueError, "invalid PNG file or memory could "
 			"not be allocated for operation");
@@ -479,18 +470,21 @@
     s = PyCairoImageSurface_FromImageSurface(surface, NULL);
     if (!s)
 	cairo_surface_destroy(surface);
-
-    /*return Py_BuildValue("O(ii)", s, width, height);
-     * Py_BuildValue increments object ref count, which we don't want
-     * proposed solution of returning object only (with getter for width,height) is better 
-     *
-     * wrapping cairo_image_surface_create_from_png() gives a seg fault
-     * since cairo_image_surface_create_from_png() calls fclose(file)
-     */
-    return (PyObject *)s;
+    return s;
 }
 #endif /* CAIRO_HAS_PNG_FUNCTIONS */
 
+static PyObject *
+image_surface_get_height(PyCairoImageSurface *s)
+{
+    return Py_BuildValue("i", cairo_image_surface_get_height(s->surface));
+}
+
+static PyObject *
+image_surface_get_width(PyCairoImageSurface *s)
+{
+    return Py_BuildValue("i", cairo_image_surface_get_width(s->surface));
+}
 
 static PyMethodDef image_surface_methods[] = {
 #ifdef HAVE_NUMPY
@@ -504,10 +498,17 @@
 #ifdef CAIRO_HAS_PNG_FUNCTIONS
     { "create_from_png", (PyCFunction)image_surface_create_from_png, 
                                                    METH_VARARGS | METH_CLASS },
+    /* create_from_png_stream */
 #endif
     { NULL, NULL, 0 }
 };
 
+static PyGetSetDef image_surface_getsets[] = {
+    { "height",   (getter)image_surface_get_height,     (setter)0 },
+    { "width",    (getter)image_surface_get_width,      (setter)0 },
+    { NULL, (getter)0, (setter)0 }
+};
+
 PyTypeObject PyCairoImageSurface_Type = {
     PyObject_HEAD_INIT(&PyType_Type)
     0,                                  /* ob_size */
@@ -539,7 +540,7 @@
     0,                                  /* tp_iternext */
     image_surface_methods,              /* tp_methods */
     0,                                  /* tp_members */
-    0,                                  /* tp_getset */
+    image_surface_getsets,              /* tp_getset */
     &PyCairoSurface_Type,               /* tp_base */
     0,                                  /* tp_dict */
     0,                                  /* tp_descr_get */




More information about the cairo-commit mailing list