[cairo-commit] pycairo/cairo pycairo-surface.c,1.14,1.15
Steve Chaplin
commit at pdx.freedesktop.org
Mon Apr 4 19:24:19 PDT 2005
Committed by: stevech1097
Update of /cvs/cairo/pycairo/cairo
In directory gabe:/tmp/cvs-serv3997/cairo
Modified Files:
pycairo-surface.c
Log Message:
SC 2005/04/05
Index: pycairo-surface.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-surface.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- pycairo-surface.c 4 Apr 2005 17:19:27 -0000 1.14
+++ pycairo-surface.c 5 Apr 2005 02:24:17 -0000 1.15
@@ -144,6 +144,34 @@
return (PyObject *)py_surface;
}
+/* alternative constructor */
+static PyObject *
+pycairo_surface_create_for_png(PyTypeObject *type, PyObject *args)
+{
+ PyCairoSurface *py_surface;
+ PyObject *file_object;
+ int width, height;
+
+ if (!PyArg_ParseTuple(args, "O!:Surface.create_for_png",
+ &PyFile_Type, &file_object))
+ return NULL;
+
+ py_surface = (PyCairoSurface *)type->tp_alloc(type, 0);
+ if (py_surface){
+ py_surface->surface = cairo_image_surface_create_for_png
+ (PyFile_AsFile(file_object), &width, &height);
+ if (!py_surface->surface) {
+ Py_DECREF(py_surface);
+ PyErr_SetString(PyExc_ValueError, "invalid PNG file or memory could not be allocated for operation");
+ return NULL;
+ }
+ }
+ return Py_BuildValue("O(ii)", py_surface, 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 */
+ /* see examples/gtk/png_view.py - causes seg fault ? */
+}
+
static PyObject *
pycairo_surface_create_similar(PyCairoSurface *self, PyObject *args)
{
@@ -263,6 +291,8 @@
static PyMethodDef pycairo_surface_methods[] = {
{ "create_for_data", (PyCFunction)pycairo_surface_create_for_data,
METH_VARARGS | METH_CLASS },
+ { "create_for_png", (PyCFunction)pycairo_surface_create_for_png,
+ METH_VARARGS | METH_CLASS },
{ "create_similar", (PyCFunction)pycairo_surface_create_similar,
METH_VARARGS },
/* (image_)surface_create_for_png */
More information about the cairo-commit
mailing list