[cairo-commit] pycairo/cairo cairomodule.c, 1.23, 1.24 pycairo.h,
1.21, 1.22 pycairo-private.h, 1.16, 1.17 pycairo-surface.c,
1.23, 1.24
Steve Chaplin
commit at pdx.freedesktop.org
Thu Apr 14 05:05:28 PDT 2005
- Previous message: [cairo-commit] pycairo ChangeLog,1.85,1.86 NOTES,1.2,1.3
- Next message: [cairo-commit] pycairo/examples context-subclass.py, 1.2,
1.3 gradient.py, 1.3, 1.4 hering.py, 1.3, 1.4 warpedtext.py,
1.6, 1.7
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: stevech1097
Update of /cvs/cairo/pycairo/cairo
In directory gabe:/tmp/cvs-serv19054/cairo
Modified Files:
cairomodule.c pycairo.h pycairo-private.h pycairo-surface.c
Log Message:
SC 2005/04/14
Index: cairomodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/cairomodule.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- cairomodule.c 14 Apr 2005 08:55:40 -0000 1.23
+++ cairomodule.c 14 Apr 2005 12:05:26 -0000 1.24
@@ -212,7 +212,9 @@
INIT_TYPE(PyCairoFontFace_Type);
INIT_TYPE(PyCairoMatrix_Type);
INIT_TYPE(PyCairoPattern_Type);
+
INIT_TYPE(PyCairoSurface_Type);
+ INIT_TYPE(PyCairoImageSurface_Type);
#undef INIT_TYPE
@@ -222,7 +224,9 @@
PyModule_AddObject(mod, "FontFace",(PyObject *)&PyCairoFontFace_Type);
PyModule_AddObject(mod, "Matrix", (PyObject *)&PyCairoMatrix_Type);
PyModule_AddObject(mod, "Pattern", (PyObject *)&PyCairoPattern_Type);
+
PyModule_AddObject(mod, "Surface", (PyObject *)&PyCairoSurface_Type);
+ PyModule_AddObject(mod, "ImageSurface", (PyObject *)&PyCairoImageSurface_Type);
PyModule_AddObject(mod, "_PyCairo_API",
PyCObject_FromVoidPtr(&api, NULL));
Index: pycairo.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- pycairo.h 14 Apr 2005 08:55:40 -0000 1.21
+++ pycairo.h 14 Apr 2005 12:05:26 -0000 1.22
@@ -66,6 +66,8 @@
PyObject *base; /* base object used to create surface, or NULL */
} PyCairoSurface;
+#define PyCairoImageSurface PyCairoSurface
+
struct _PyCairo_FunctionStruct {
int (* check_status)(cairo_status_t status);
PyTypeObject *context_type;
@@ -73,7 +75,7 @@
PyTypeObject *font_type;
PyObject *(* font_wrap)(cairo_font_face_t *font_face);
PyTypeObject *matrix_type;
- PyObject *(* matrix_wrap)(cairo_matrix_t *matrix);
+ PyObject *(* matrix_wrap)(const cairo_matrix_t *matrix);
PyTypeObject *pattern_type;
PyObject *(* pattern_wrap)(cairo_pattern_t *pattern);
PyTypeObject *surface_type;
Index: pycairo-private.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-private.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- pycairo-private.h 14 Apr 2005 08:55:40 -0000 1.16
+++ pycairo-private.h 14 Apr 2005 12:05:26 -0000 1.17
@@ -46,7 +46,9 @@
extern PyTypeObject PyCairoFontFace_Type;
extern PyTypeObject PyCairoMatrix_Type;
extern PyTypeObject PyCairoPattern_Type;
+
extern PyTypeObject PyCairoSurface_Type;
+extern PyTypeObject PyCairoImageSurface_Type;
int pycairo_check_status(cairo_status_t status);
Index: pycairo-surface.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-surface.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- pycairo-surface.c 14 Apr 2005 01:43:48 -0000 1.23
+++ pycairo-surface.c 14 Apr 2005 12:05:26 -0000 1.24
@@ -38,6 +38,8 @@
#include "pycairo-private.h"
#include "pycairo-misc.h"
+/* Class Surface ----------------------------------------------------------- */
+
/* PyCairoSurface_FromSurface
* Create a new PyCairoSurface from a cairo_surface_t
* Return value: New reference (NULL on failure)
@@ -87,111 +89,9 @@
static int
surface_init(PyCairoSurface *s, PyObject *args, PyObject *kwds)
{
- cairo_format_t format;
- int width, height;
-
- if (!PyArg_ParseTuple(args, "iii:Surface.__init__",
- &format, &width, &height))
- return -1;
-
- s->surface = cairo_image_surface_create (format, width, height);
- if (!s->surface){
- Py_DECREF(s);
- PyErr_NoMemory();
- return -1;
- }
- return 0;
-}
-
-#if 0 /* disable until a reference to the buffer is added to the surface */
-/* alternative constructor */
-static PyObject *
-surface_create_for_data(PyTypeObject *type, PyObject *args)
-{
- PyObject *s;
- cairo_surface_t *surface;
- char *data;
- cairo_format_t format;
- int length, width, height, stride = -1;
-
- if (!PyArg_ParseTuple(args, "w#iii|i:Surface.create_for_data",
- &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
- ((unsigned char *)data, format, width, height, stride);
- if (!surface)
- return PyErr_NoMemory();
-
- s = PyCairoSurface_FromSurface(surface, NULL);
- if (!s)
- cairo_surface_destroy(surface);
- return s;
- /* FIXME: get surface to hold a reference to buffer */
-}
-#endif
-
-/* alternative constructor */
-static PyObject *
-surface_create_for_png(PyTypeObject *type, PyObject *args)
-{
- PyObject *s;
- PyObject *file_object;
- cairo_surface_t *surface;
- int width=0, height=0;
-
- if (!PyArg_ParseTuple(args, "O!:Surface.create_for_png",
- &PyFile_Type, &file_object))
- return NULL;
-
- surface = cairo_image_surface_create_for_png
- (PyFile_AsFile(file_object), &width, &height);
- if (!surface) {
- PyErr_SetString(PyExc_ValueError, "invalid PNG file or memory could not be allocated for operation");
- return NULL;
- }
- s = PyCairoSurface_FromSurface(surface, NULL);
- if (!s)
- cairo_surface_destroy(surface);
-
- return Py_BuildValue("O(ii)", s, width, height);
- /*return (PyObject *)s;*/
-
- /* 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_for_png() gives a seg fault
- * since cairo_image_surface_create_for_png() calls fclose(file)
- */
+ PyErr_SetString(PyExc_TypeError,
+ "The BaseSurface type cannot be instantiated");
+ return -1;
}
static PyObject *
@@ -321,14 +221,6 @@
static PyMethodDef surface_methods[] = {
-#if 0
- { "create_for_data",(PyCFunction)surface_create_for_data,
- METH_VARARGS | METH_CLASS },
-#endif
-#ifdef CAIRO_HAS_PNG_FUNCTIONS
- { "create_for_png", (PyCFunction)surface_create_for_png,
- METH_VARARGS | METH_CLASS },
-#endif
{ "create_similar", (PyCFunction)surface_create_similar, METH_VARARGS },
{ "finish", (PyCFunction)surface_finish, METH_NOARGS },
{ "set_device_offset",(PyCFunction)surface_set_device_offset,
@@ -369,7 +261,7 @@
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
NULL, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
@@ -392,3 +284,174 @@
0, /* tp_is_gc */
0, /* tp_bases */
};
+
+
+/* Class ImageSurface ------------------------------------------------------ */
+
+static int
+image_surface_init(PyCairoSurface *s, PyObject *args, PyObject *kwds)
+{
+ cairo_format_t format;
+ int width, height;
+
+ if (!PyArg_ParseTuple(args, "iii:ImageSurface.__init__",
+ &format, &width, &height))
+ return -1;
+
+ s->surface = cairo_image_surface_create (format, width, height);
+ if (!s->surface){
+ Py_DECREF(s);
+ PyErr_NoMemory();
+ return -1;
+ }
+ return 0;
+}
+
+#if 0 /* disable until a reference to the buffer is added to the surface */
+/* alternative constructor */
+static PyObject *
+image_surface_create_for_data(PyTypeObject *type, PyObject *args)
+{
+ PyObject *s;
+ cairo_surface_t *surface;
+ char *data;
+ cairo_format_t format;
+ int length, width, height, stride = -1;
+
+ if (!PyArg_ParseTuple(args, "w#iii|i:Surface.create_for_data",
+ &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
+ ((unsigned char *)data, format, width, height, stride);
+ if (!surface)
+ return PyErr_NoMemory();
+
+ s = PyCairoSurface_FromSurface(surface, NULL);
+ if (!s)
+ cairo_surface_destroy(surface);
+ return s;
+ /* FIXME: get surface to hold a reference to buffer */
+}
+#endif
+
+/* alternative constructor */
+static PyObject *
+image_surface_create_for_png(PyTypeObject *type, PyObject *args)
+{
+ PyObject *s;
+ PyObject *file_object;
+ cairo_surface_t *surface;
+ int width=0, height=0;
+
+ if (!PyArg_ParseTuple(args, "O!:Surface.create_for_png",
+ &PyFile_Type, &file_object))
+ return NULL;
+
+ surface = cairo_image_surface_create_for_png
+ (PyFile_AsFile(file_object), &width, &height);
+ if (!surface) {
+ PyErr_SetString(PyExc_ValueError, "invalid PNG file or memory could "
+ "not be allocated for operation");
+ return NULL;
+ }
+ s = PyCairoSurface_FromSurface(surface, NULL);
+ if (!s)
+ cairo_surface_destroy(surface);
+
+ return Py_BuildValue("O(ii)", s, width, height);
+ /*return (PyObject *)s;*/
+
+ /* 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_for_png() gives a seg fault
+ * since cairo_image_surface_create_for_png() calls fclose(file)
+ */
+}
+
+static PyMethodDef image_surface_methods[] = {
+#if 0
+ { "create_for_data",(PyCFunction)image_surface_create_for_data,
+ METH_VARARGS | METH_CLASS },
+#endif
+#ifdef CAIRO_HAS_PNG_FUNCTIONS
+ { "create_for_png", (PyCFunction)image_surface_create_for_png,
+ METH_VARARGS | METH_CLASS },
+#endif
+ { NULL, NULL, 0 }
+};
+
+PyTypeObject PyCairoImageSurface_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /* ob_size */
+ "cairo.ImageSurface", /* tp_name */
+ sizeof(PyCairoImageSurface), /* 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 */
+ NULL, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ image_surface_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ &PyCairoSurface_Type, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)image_surface_init, /* tp_init */
+ 0, /* tp_alloc */
+ 0, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
+};
- Previous message: [cairo-commit] pycairo ChangeLog,1.85,1.86 NOTES,1.2,1.3
- Next message: [cairo-commit] pycairo/examples context-subclass.py, 1.2,
1.3 gradient.py, 1.3, 1.4 hering.py, 1.3, 1.4 warpedtext.py,
1.6, 1.7
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the cairo-commit
mailing list