diff --git a/configure.ac b/configure.ac index a6e254bb..951d6b96 100644 --- a/configure.ac +++ b/configure.ac @@ -38,6 +38,8 @@ AC_SUBST(GNOMEPYTHONEXTRAS_DEFSDIR) PYGTK_DEFSDIR=`$PKG_CONFIG --variable=defsdir pygtk-2.0` AC_SUBST(PYGTK_DEFSDIR) +PKG_CHECK_MODULES(PYCAIRO, pycairo) + # # Setup GETTEXT # diff --git a/lib/python/Makefile.am b/lib/python/Makefile.am index be712d70..6f28d335 100644 --- a/lib/python/Makefile.am +++ b/lib/python/Makefile.am @@ -1,6 +1,7 @@ INCLUDES = \ $(PYTHON_INCLUDES) \ $(PYGTK_CFLAGS) \ + $(PYCAIRO_CFLAGS) \ $(LIB_CFLAGS) \ -I $(top_srcdir)/lib/src @@ -11,6 +12,7 @@ pkgpyexec_LTLIBRARIES = _sugar.la _sugar_la_LDFLAGS = -module -avoid-version -R$(MOZILLA_HOME) _sugar_la_LIBADD = \ $(LIB_LIBS) \ + $(PYCAIRO_LIBS) \ $(top_builddir)/lib/src/libsugarprivate.la _sugar_la_SOURCES = \ diff --git a/lib/python/_sugar.defs b/lib/python/_sugar.defs index bead7b48..4ea9b8de 100644 --- a/lib/python/_sugar.defs +++ b/lib/python/_sugar.defs @@ -247,6 +247,15 @@ '("GdkPixbuf*" "pixbuf") ) ) + +(define-function cairo_surface_from_gdk_pixbuf + (c-name "sugar_cairo_surface_from_gdk_pixbuf") + (return-type "cairo_surface_t*") + (parameters + '("GdkPixbuf*" "pixbuf") + ) +) + ;; Enumerations and flags ... diff --git a/lib/python/_sugar.override b/lib/python/_sugar.override index 6e0fe720..8dd90f96 100644 --- a/lib/python/_sugar.override +++ b/lib/python/_sugar.override @@ -13,9 +13,11 @@ headers #include "sugar-download.h" #include "sugar-audio-manager.h" +#include "pycairo.h" #include #include +extern Pycairo_CAPI_t *Pycairo_CAPI; %% modulename gecko @@ -159,3 +161,23 @@ _wrap_sugar_hippo_canvas_image_set_image_from_gdk_pixbuf(PyGObject *self, PyObje return Py_None; } %% +override sugar_cairo_surface_from_gdk_pixbuf kwargs +static PyObject* +_wrap_sugar_cairo_surface_from_gdk_pixbuf(PyGObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "pixbuf", NULL }; + PyGObject *child; + cairo_surface_t *surface; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!:sugar.cairo_surface_from_gdk_pixbuf", kwlist, &PyGdkPixbuf_Type, &child)) + return NULL; + + surface = _cairo_surface_from_pixbuf(GDK_PIXBUF (child->obj)); + if (surface == NULL) { + PyErr_SetString(PyExc_RuntimeError, "pixbuf could not be converted"); + return NULL; + } + + return PycairoSurface_FromSurface(surface, NULL); +} +%% diff --git a/lib/python/_sugarmodule.c b/lib/python/_sugarmodule.c index 4d8511b9..c576efb0 100644 --- a/lib/python/_sugarmodule.c +++ b/lib/python/_sugarmodule.c @@ -5,6 +5,9 @@ /* include this first, before NO_IMPORT_PYGOBJECT is defined */ #include +#include +Pycairo_CAPI_t *Pycairo_CAPI; + void py_sugar_register_classes (PyObject *d); extern PyMethodDef py_sugar_functions[]; @@ -16,6 +19,8 @@ init_sugar(void) init_pygobject (); + Pycairo_IMPORT; + m = Py_InitModule ("_sugar", py_sugar_functions); d = PyModule_GetDict (m);