[cairo-commit] pycairo/cairo pycairosvg-private.h, 1.3,
1.4 pycairo-private.h, 1.23, 1.24 pycairo-misc.h, 1.2,
1.3 pycairo.h, 1.30, 1.31 pycairosvg.h, NONE, 1.1 Makefile.am,
1.12, 1.13 cairosvgmodule.c, 1.4, 1.5 pycairo-path.c, 1.3,
1.4 pycairo-context.c, 1.51, 1.52
Steve Chaplin
commit at pdx.freedesktop.org
Fri May 13 18:15:08 PDT 2005
- Previous message: [cairo-commit] pycairo/examples/cairo_snippets/snippets
operator_atop_reverse.py, 1.2, 1.3 operator_in_reverse.py, 1.2,
1.3 operator_out_reverse.py, 1.2, 1.3 operator_over_reverse.py,
1.2, 1.3
- Next message: [cairo-commit]
pycairo/examples/svg svgview.py, 1.4, 1.5 svg2png.py, 1.2, 1.3
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: stevech1097
Update of /cvs/cairo/pycairo/cairo
In directory gabe:/tmp/cvs-serv29632/cairo
Modified Files:
pycairosvg-private.h pycairo-private.h pycairo-misc.h
pycairo.h Makefile.am cairosvgmodule.c pycairo-path.c
pycairo-context.c
Added Files:
pycairosvg.h
Log Message:
SC
Index: pycairosvg-private.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairosvg-private.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- pycairosvg-private.h 9 May 2005 09:12:31 -0000 1.3
+++ pycairosvg-private.h 14 May 2005 01:15:06 -0000 1.4
@@ -36,9 +36,11 @@
#endif
#define _INSIDE_PYCAIROSVG_
-#include <svg-cairo.h>
+#include <Python.h>
+
+#include "pycairosvg.h"
#include "pycairo-misc.h"
extern PyTypeObject PycairoSVGContext_Type;
-#endif
+#endif /* _PYCAIROSVG_PRIVATE_H_ */
Index: pycairo-private.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-private.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- pycairo-private.h 10 May 2005 15:34:03 -0000 1.23
+++ pycairo-private.h 14 May 2005 01:15:06 -0000 1.24
@@ -36,6 +36,8 @@
#endif
#define _INSIDE_PYCAIRO_
+#include <Python.h>
+
#include "pycairo.h"
#include "pycairo-misc.h"
Index: pycairo-misc.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-misc.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- pycairo-misc.h 9 May 2005 09:12:31 -0000 1.2
+++ pycairo-misc.h 14 May 2005 01:15:06 -0000 1.3
@@ -31,6 +31,8 @@
#ifndef _PYCAIRO_MISC_H_
#define _PYCAIRO_MISC_H_
+#include <Python.h>
+
#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 4
# define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
# define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True
Index: pycairo.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- pycairo.h 10 May 2005 15:34:03 -0000 1.30
+++ pycairo.h 14 May 2005 01:15:06 -0000 1.31
@@ -35,14 +35,6 @@
#include <cairo.h>
-#ifdef CAIRO_HAS_PDF_SURFACE
-# include <cairo-pdf.h>
-#endif
-/* PS backend support has been removed - the C API is broken
-#ifdef CAIRO_HAS_PS_SURFACE
-# include <cairo-ps.h>
-#endif
-*/
typedef struct {
PyObject_HEAD
@@ -140,9 +132,12 @@
#define Pycairo_check_status (Pycairo_CAPI->check_status)
-/* Define global variable for the C API and a macro for setting it. */
-static Pycairo_CAPI_t *Pycairo_CAPI;
+/* To import the Pycairo C API, edit the client module file to:
+ * 1) add 'Pycairo_IMPORT' to the init<module> function
+ * 2) add the line below to define a global variable for the C API
+ * static Pycairo_CAPI_t *Pycairo_CAPI;
+ */
#define Pycairo_IMPORT \
Pycairo_CAPI = (Pycairo_CAPI_t*) PyCObject_Import("cairo", \
"pycairo_CAPI")
--- NEW FILE: pycairosvg.h ---
(This appears to be a binary file; contents omitted.)
Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/Makefile.am,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- Makefile.am 9 May 2005 09:12:31 -0000 1.12
+++ Makefile.am 14 May 2005 01:15:06 -0000 1.13
@@ -39,6 +39,5 @@
svg_la_LDFLAGS = -module -avoid-version -export-symbols-regex initsvg
svg_la_LIBADD = $(CAIRO_LIBS) $(LIBSVG_CAIRO_LIBS)
svg_la_SOURCES = \
- pycairosvg-context.c \
cairosvgmodule.c
endif
Index: cairosvgmodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/cairosvgmodule.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- cairosvgmodule.c 9 May 2005 09:12:31 -0000 1.4
+++ cairosvgmodule.c 14 May 2005 01:15:06 -0000 1.5
@@ -29,29 +29,16 @@
*/
#include <Python.h>
+#include "structmember.h"
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "pycairosvg-private.h"
-#include "pycairo.h"
-
-
-/* cairo.svg module
- * - no module methods
- * - one module type: cairo.svg.Context()
-*/
-
-
-static PyMethodDef svg_functions[] = {
- {NULL},
-};
-PyDoc_STRVAR(svg_doc,
-"libsvg-cairo bindings."
-);
+static Pycairo_CAPI_t *Pycairo_CAPI;
#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
#define PyMODINIT_FUNC void
@@ -64,7 +51,7 @@
if (PyType_Ready(&PycairoSVGContext_Type) < 0)
return;
- mod = Py_InitModule3 ("cairo.svg", svg_functions, svg_doc);
+ mod = Py_InitModule ("cairo.svg", NULL);
if (mod == NULL)
return;
@@ -73,3 +60,175 @@
Py_INCREF(&PycairoSVGContext_Type);
PyModule_AddObject(mod, "Context", (PyObject *)&PycairoSVGContext_Type);
}
+
+
+
+/* if status reports an error, then return 1 (True) and set the exception */
+static int
+_status_error (svg_cairo_status_t status)
+{
+ switch (status) {
+ case SVG_CAIRO_STATUS_SUCCESS:
+ return 0;
+ case SVG_CAIRO_STATUS_NO_MEMORY:
+ PyErr_NoMemory();
+ return 1;
+ case SVG_CAIRO_STATUS_IO_ERROR:
+ PyErr_SetString(PyExc_IOError, "IO Error");
+ return 1;
+ case SVG_CAIRO_STATUS_FILE_NOT_FOUND:
+ PyErr_SetString(PyExc_RuntimeError, "File not found");
+ return 1;
+ case SVG_CAIRO_STATUS_INVALID_VALUE:
+ PyErr_SetString(PyExc_RuntimeError, "Invalid value");
+ return 1;
+ case SVG_CAIRO_STATUS_INVALID_CALL:
+ PyErr_SetString(PyExc_RuntimeError, "Invalid call");
+ return 1;
+ case SVG_CAIRO_STATUS_PARSE_ERROR:
+ PyErr_SetString(PyExc_RuntimeError, "Parse error");
+ return 1;
+ default:
+ PyErr_SetString(PyExc_RuntimeError, "other cairo.svg error");
+ return 1;
+ }
+}
+
+
+static void
+pycairosvg_dealloc(PycairoSVGContext* self)
+{
+ if (self->ctx) {
+ svg_cairo_destroy(self->ctx);
+ self->ctx = NULL;
+ }
+ self->ob_type->tp_free((PyObject*)self);
+}
+
+
+static PyObject *
+pycairosvg_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PycairoSVGContext *self = (PycairoSVGContext *)type->tp_alloc(type, 0);
+ if (self && _status_error (svg_cairo_create (&self->ctx))) {
+ Py_DECREF(self);
+ return NULL;
+ }
+ return (PyObject *)self;
+}
+
+/* static int pycairosvg_init () not needed */
+
+
+static PyObject *
+pycairosvg_parse (PycairoSVGContext *self, PyObject *args)
+{
+ const char *filename;
+
+ if (!PyArg_ParseTuple(args, "s:Context.parse", &filename))
+ return NULL;
+
+ if (_status_error (svg_cairo_parse (self->ctx, filename)))
+ return NULL;
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+pycairosvg_parse_buffer (PycairoSVGContext *self, PyObject *args)
+{
+ const char *buf;
+ size_t count;
+
+ if (!PyArg_ParseTuple(args, "t#:Context.parse_buffer", &buf, &count))
+ return NULL;
+
+ //svg_cairo_status_t svg_cairo_parse_buffer (svg_cairo_t *svg_cairo, const char *buf, size_t count);
+ if (_status_error (svg_cairo_parse_buffer (self->ctx, buf, count)))
+ return NULL;
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+pycairosvg_render (PycairoSVGContext *self, PyObject *args)
+{
+ PycairoContext *xrs;
+
+ if (!PyArg_ParseTuple(args, "O!:Context.render",
+ &PycairoContext_Type, &xrs))
+ return NULL;
+
+ if (_status_error (svg_cairo_render (self->ctx, xrs->ctx)))
+ return NULL;
+ Py_RETURN_NONE;
+}
+
+
+static PyObject *
+pycairosvg_get_size (PycairoSVGContext *self, void *closure)
+{
+ int width, height;
+
+ svg_cairo_get_size (self->ctx, &width, &height);
+ return Py_BuildValue("ii", width, height);
+}
+
+
+static PyMethodDef pycairosvg_methods[] = {
+ {"parse", (PyCFunction)pycairosvg_parse, METH_VARARGS },
+ {"parse_buffer", (PyCFunction)pycairosvg_parse_buffer, METH_VARARGS },
+ /* parse_file */
+ /* parse_file_chunk_begin */
+ /* parse_file_chunk */
+ /* parse_file_chunk_end */
+ {"render", (PyCFunction)pycairosvg_render, METH_VARARGS },
+ /* set_viewport_dimension */
+ {NULL, NULL, 0, NULL},
+};
+
+static PyGetSetDef pycairosvg_getsets[] = {
+ {"size", (getter)pycairosvg_get_size},
+ {NULL, (getter)0, (setter)0, NULL, NULL},
+};
+
+
+PyTypeObject PycairoSVGContext_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "cairo.svg.Context", /*tp_name*/
+ sizeof(PycairoSVGContext), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ (destructor)pycairosvg_dealloc, /*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 | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ pycairosvg_methods, /* tp_methods */
+ 0, /* tp_members */
+ pycairosvg_getsets, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)0, /* tp_init */
+ 0, /* tp_alloc */
+ pycairosvg_new, /* tp_new */
+};
Index: pycairo-path.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-path.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- pycairo-path.c 10 May 2005 15:34:03 -0000 1.3
+++ pycairo-path.c 14 May 2005 01:15:06 -0000 1.4
@@ -28,6 +28,8 @@
* the specific language governing rights and limitations.
*/
+#include <Python.h>
+
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
@@ -167,45 +169,45 @@
PyTypeObject PycairoPath_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* Number of items for varobject */
- "cairo.Path", /* Name of this type */
- sizeof(PycairoPath), /* Basic object size */
- 0, /* Item size for varobject */
- (destructor)path_dealloc, /* 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 */
- (reprfunc)path_str, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- (getiterfunc)path_iter, /* tp_iter */
- 0, /* tp_iternext */
- 0, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)path_init, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)path_new, /* tp_new */
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /* ob_size */
+ "cairo.Path", /* tp_name */
+ sizeof(PycairoPath), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ (destructor)path_dealloc, /* 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 */
+ (reprfunc)path_str, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ (getiterfunc)path_iter, /* tp_iter */
+ 0, /* tp_iternext */
+ 0, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)path_init, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)path_new, /* tp_new */
};
/*********************** PycairoPath Iterator **************************/
@@ -290,33 +292,33 @@
}
static PyTypeObject PycairoPathiter_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
- "cairo.Pathiter", /* tp_name */
- sizeof(PycairoPathiter), /* tp_basicsize */
- 0, /* tp_itemsize */
- (destructor)pathiter_dealloc, /* 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 */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- PyObject_SelfIter, /* tp_iter */
- (iternextfunc)pathiter_next, /* tp_iternext */
- 0, /* tp_methods */
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /* ob_size */
+ "cairo.Pathiter", /* tp_name */
+ sizeof(PycairoPathiter), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ (destructor)pathiter_dealloc, /* 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 */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ PyObject_SelfIter, /* tp_iter */
+ (iternextfunc)pathiter_next, /* tp_iternext */
+ 0, /* tp_methods */
};
Index: pycairo-context.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-context.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- pycairo-context.c 12 May 2005 00:00:08 -0000 1.51
+++ pycairo-context.c 14 May 2005 01:15:06 -0000 1.52
@@ -28,6 +28,8 @@
* the specific language governing rights and limitations.
*/
+#include <Python.h>
+
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
@@ -1072,6 +1074,11 @@
/* methods never exposed in a language binding:
* cairo_destroy()
* cairo_reference()
+ *
+ * cairo_status()
+ * cairo_status_string()
+ * - not needed since Pycairo calls Pycairo_check_status() to check
+ * for errors and raise exceptions
*/
{"append_path", (PyCFunction)pycairo_append_path, METH_VARARGS},
{"arc", (PyCFunction)pycairo_arc, METH_VARARGS},
- Previous message: [cairo-commit] pycairo/examples/cairo_snippets/snippets
operator_atop_reverse.py, 1.2, 1.3 operator_in_reverse.py, 1.2,
1.3 operator_out_reverse.py, 1.2, 1.3 operator_over_reverse.py,
1.2, 1.3
- Next message: [cairo-commit]
pycairo/examples/svg svgview.py, 1.4, 1.5 svg2png.py, 1.2, 1.3
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the cairo-commit
mailing list