1 /* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
3 * Copyright (c) 2010 Collabora Ltd. <http://www.collabora.co.uk/>
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to
7 * deal in the Software without restriction, including without limitation the
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 * sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 #if PY_VERSION_HEX < 0x03000000
30 #include <pycairo/py3cairo.h>
33 static Pycairo_CAPI_t *Pycairo_CAPI;
35 #include "pygi-foreign.h"
37 #include <pyglib-python-compat.h>
40 cairo_context_to_arg (PyObject *value,
41 GIInterfaceInfo *interface_info,
47 g_assert (transfer == GI_TRANSFER_NOTHING);
49 cr = PycairoContext_GET (value);
59 cairo_context_from_arg (GIInterfaceInfo *interface_info, gpointer data)
61 cairo_t *context = (cairo_t*) data;
63 cairo_reference (context);
65 return PycairoContext_FromContext (context, &PycairoContext_Type, NULL);
69 cairo_context_release (GIBaseInfo *base_info,
72 cairo_destroy ( (cairo_t*) struct_);
78 cairo_surface_to_arg (PyObject *value,
79 GIInterfaceInfo *interface_info,
83 cairo_surface_t *surface;
85 g_assert (transfer == GI_TRANSFER_NOTHING);
87 surface = ( (PycairoSurface*) value)->surface;
89 PyErr_SetString (PyExc_ValueError, "Surface instance wrapping a NULL surface");
93 arg->v_pointer = surface;
98 cairo_surface_from_arg (GIInterfaceInfo *interface_info, gpointer data)
100 cairo_surface_t *surface = (cairo_surface_t*) data;
102 cairo_surface_reference (surface);
104 return PycairoSurface_FromSurface (surface, NULL);
108 cairo_surface_release (GIBaseInfo *base_info,
111 cairo_surface_destroy ( (cairo_surface_t*) struct_);
115 static PyMethodDef _gi_cairo_functions[] = { {0,} };
116 PYGLIB_MODULE_START(_gi_cairo, "_gi_cairo")
118 #if PY_VERSION_HEX < 0x03000000
121 Pycairo_CAPI = (Pycairo_CAPI_t*) PyCapsule_Import("cairo.CAPI", 0);
124 if (Pycairo_CAPI == NULL)
125 return PYGLIB_MODULE_ERROR_RETURN;
127 pygi_register_foreign_struct ("cairo",
129 cairo_context_to_arg,
130 cairo_context_from_arg,
131 cairo_context_release);
133 pygi_register_foreign_struct ("cairo",
135 cairo_surface_to_arg,
136 cairo_surface_from_arg,
137 cairo_surface_release);