~ubuntu-branches/ubuntu/jaunty/gdesklets/jaunty-updates

« back to all changes in this revision

Viewing changes to utils/svg.c

  • Committer: Bazaar Package Importer
  • Author(s): Deng Xiyue
  • Date: 2008-09-02 22:00:17 UTC
  • mfrom: (2.1.18 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080902220017-m66bj19l0ll8x7yh
Tags: 0.36-5
* Redo 40_dont_update_mime.diff to use a more compact syntax by 
  Loïc Minier's suggestion.  Thanks lool.
* Regenerate 70_relibtoolize.diff accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <gtk/gtk.h>
23
23
#include <librsvg/rsvg.h>
24
24
 
25
 
PyMODINIT_FUNC initsvg(void);
 
25
PyMODINIT_FUNC initsvg (void);
26
26
 
27
 
static PyObject* render(PyObject *self, PyObject *args)
 
27
static PyObject* render (PyObject *self, PyObject *args)
28
28
{
29
29
  GtkImage *image;
30
30
  GdkPixbuf *pbuf;
36
36
  int length;
37
37
  int width, height;
38
38
 
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))
41
41
    return NULL;
42
42
 
43
 
  if(PyString_AsStringAndSize(string, &buffer, &length) == -1)
 
43
  if (PyString_AsStringAndSize(string, &buffer, &length) == -1)
44
44
    return NULL;
45
45
 
46
46
  if (!(handle = rsvg_handle_new ())) {
47
 
    g_error("Couldn't create handle!");
 
47
    PyErr_SetString (PyExc_RuntimeError, "Couldn't create handle!");
48
48
    return NULL;
49
49
  }
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);
 
52
    return NULL;
52
53
  }
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
    return NULL;
55
57
  }
56
58
  if (!(pbuf = rsvg_handle_get_pixbuf (handle))) {
57
 
    g_error("Error creating pixbuf from handle.");
58
 
  }
59
 
  else {
60
 
    gtk_image_set_from_pixbuf (image, pbuf);
61
 
    g_object_unref (G_OBJECT (pbuf));
62
 
  }
 
59
    PyErr_SetString (PyExc_RuntimeError, "Error creating pixbuf from handle.");
 
60
    return NULL;
 
61
  }
 
62
 
 
63
  gtk_image_set_from_pixbuf (image, pbuf);
 
64
  g_object_unref (G_OBJECT (pbuf));
63
65
  rsvg_handle_free (handle);
64
66
 
65
67
  Py_INCREF(Py_None);
69
71
 
70
72
 
71
73
PyMODINIT_FUNC
72
 
initsvg(void)
 
74
initsvg( void)
73
75
{
74
 
  static const PyMethodDef methods[] =
75
 
    {
 
76
  static const PyMethodDef methods[] = {
76
77
      {"render", render, METH_VARARGS, NULL},
77
78
      {NULL, NULL, 0, NULL}
78
 
    };
 
79
  };
79
80
 
80
 
  if(!gdesklets_get_pygobject_type())
 
81
  if (!gdesklets_get_pygobject_type ())
81
82
    return;
82
83
 
83
 
  Py_InitModule("svg", (PyMethodDef*) methods);
 
84
  Py_InitModule("svg", (PyMethodDef *) methods);
 
85
 
 
86
  if (PyErr_Occurred ())
 
87
    Py_FatalError ("Can't initialise module svg");
84
88
}