22
22
#include <gtk/gtk.h>
23
23
#include <librsvg/rsvg.h>
25
PyMODINIT_FUNC initsvg(void);
25
PyMODINIT_FUNC initsvg (void);
27
static PyObject* render(PyObject *self, PyObject *args)
27
static PyObject* render (PyObject *self, PyObject *args)
39
if(!PyArg_ParseTuple(args, "O&IIS", parse_gtk_image,
40
&image, &width, &height, &string))
39
if (!PyArg_ParseTuple (args, "O&IIS", parse_gtk_image,
40
&image, &width, &height, &string))
43
if(PyString_AsStringAndSize(string, &buffer, &length) == -1)
43
if (PyString_AsStringAndSize(string, &buffer, &length) == -1)
46
46
if (!(handle = rsvg_handle_new ())) {
47
g_error("Couldn't create handle!");
47
PyErr_SetString (PyExc_RuntimeError, "Couldn't create handle!");
50
if (!rsvg_handle_write (handle, (const guchar *)buffer, length, &error)) {
51
g_error("Error writing buffer to handle: %s\n", error->message);
50
if (!rsvg_handle_write (handle, (const guchar *) buffer, length, &error)) {
51
PyErr_SetString (PyExc_RuntimeError, error->message);
53
54
if (!rsvg_handle_close (handle, &error)) {
54
g_error("Error closing handle: %s\n", error->message);
55
PyErr_SetString (PyExc_RuntimeError, error->message);
56
58
if (!(pbuf = rsvg_handle_get_pixbuf (handle))) {
57
g_error("Error creating pixbuf from handle.");
60
gtk_image_set_from_pixbuf (image, pbuf);
61
g_object_unref (G_OBJECT (pbuf));
59
PyErr_SetString (PyExc_RuntimeError, "Error creating pixbuf from handle.");
63
gtk_image_set_from_pixbuf (image, pbuf);
64
g_object_unref (G_OBJECT (pbuf));
63
65
rsvg_handle_free (handle);
65
67
Py_INCREF(Py_None);
74
static const PyMethodDef methods[] =
76
static const PyMethodDef methods[] = {
76
77
{"render", render, METH_VARARGS, NULL},
77
78
{NULL, NULL, 0, NULL}
80
if(!gdesklets_get_pygobject_type())
81
if (!gdesklets_get_pygobject_type ())
83
Py_InitModule("svg", (PyMethodDef*) methods);
84
Py_InitModule("svg", (PyMethodDef *) methods);
86
if (PyErr_Occurred ())
87
Py_FatalError ("Can't initialise module svg");