Mercurial > enso_osx
view src/quartz_cairo_bridge.m @ 3:911cb701a42e
Moved all c/objc files into a new 'src' directory; other minor refactorings.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sun, 24 Feb 2008 08:51:21 -0600 |
parents | enso_osx/graphics/quartz_cairo_bridge.m@a636a7618da6 |
children | 853d8676221f |
line wrap: on
line source
#include <Python.h> #include <cairo-quartz.h> #include "pycairo.h" #import <AppKit/NSGraphicsContext.h> typedef struct { PyObject_HEAD __strong id objc_object; int flags; } PyObjCObject; static Pycairo_CAPI_t *Pycairo_CAPI; static PyObject *cairo_surface_from_NSGraphicsContext( PyObject *self, PyObject *args ) { PyObjCObject *obj; unsigned int width; unsigned int height; if ( !PyArg_ParseTuple( args, "OII", (PyObject **) &obj, &width, &height ) ) return NULL; NSGraphicsContext *nsContext = (NSGraphicsContext *) obj->objc_object; CGContextRef cgContext = [nsContext graphicsPort]; cairo_surface_t *surface = cairo_quartz_surface_create_for_cg_context( cgContext, width, height ); PyObject *pycairoSurface; pycairoSurface = PycairoSurface_FromSurface( surface, NULL ); if ( pycairoSurface == NULL ) { /* TODO: Cleanup */ /* PycairoSurface_FromSurface() has already set the Python error state. */ return NULL; } return pycairoSurface; } static PyMethodDef OsXQuartzCairoBridgeMethods[] = { { "cairo_surface_from_NSGraphicsContext", cairo_surface_from_NSGraphicsContext, METH_VARARGS, "Convert a NSGraphicsContext object to a Cairo surface." }, {NULL, NULL, 0, NULL} }; PyMODINIT_FUNC initOsXQuartzCairoBridge( void ) { Py_InitModule( "OsXQuartzCairoBridge", OsXQuartzCairoBridgeMethods ); Pycairo_IMPORT; }