Debian Codegraph @

cairo/py3cairo.h

raw symbols SCIP
1 /* -*- mode: C; c-basic-offset: 2 -*-
2 *
3 * Pycairo - Python bindings for cairo
4 *
5 * Copyright © 2003 James Henstridge
6 * Copyright © 2004-2011 Steven Chaplin
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it either under the terms of the GNU Lesser General Public
10 * License version 2.1 as published by the Free Software Foundation
11 * (the "LGPL") or, at your option, under the terms of the Mozilla
12 * Public License Version 1.1 (the "MPL"). If you do not alter this
13 * notice, a recipient may use your version of this file under either
14 * the MPL or the LGPL.
15 *
16 * You should have received a copy of the LGPL along with this library
17 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * You should have received a copy of the MPL along with this library
20 * in the file COPYING-MPL-1.1
21 *
22 * The contents of this file are subject to the Mozilla Public License
23 * Version 1.1 (the "License"); you may not use this file except in
24 * compliance with the License. You may obtain a copy of the License at
25 * http://www.mozilla.org/MPL/
26 *
27 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
28 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
29 * the specific language governing rights and limitations.
30 */
31
32 #ifndef _PYCAIRO_H_
33 #define _PYCAIRO_H_
34
35 #include <Python.h>
36
37 #include <cairo.h>
38
39
40 typedef struct {
41 PyObject_HEAD
42 cairo_t *ctx;
43 PyObject *base; /* base object used to create context, or NULL */
44 } PycairoContext;
45
46 typedef struct {
47 PyObject_HEAD
48 cairo_font_face_t *font_face;
49 } PycairoFontFace;
50
51 #define PycairoToyFontFace PycairoFontFace
52
53 typedef struct {
54 PyObject_HEAD
55 cairo_font_options_t *font_options;
56 } PycairoFontOptions;
57
58 typedef struct {
59 PyObject_HEAD
60 cairo_matrix_t matrix;
61 } PycairoMatrix;
62
63 typedef struct {
64 PyObject_HEAD
65 cairo_path_t *path;
66 } PycairoPath;
67
68 typedef struct {
69 PyObject_HEAD
70 cairo_pattern_t *pattern;
71 PyObject *base; /* base object used to create pattern, or NULL */
72 } PycairoPattern;
73
74 typedef struct {
75 PyObject_HEAD
76 cairo_rectangle_int_t rectangle_int;
77 } PycairoRectangleInt;
78
79 typedef struct {
80 PyObject_HEAD
81 cairo_region_t *region;
82 } PycairoRegion;
83
84 #define PycairoSolidPattern PycairoPattern
85 #define PycairoSurfacePattern PycairoPattern
86 #define PycairoGradient PycairoPattern
87 #define PycairoLinearGradient PycairoPattern
88 #define PycairoRadialGradient PycairoPattern
89
90 typedef struct {
91 PyObject_HEAD
92 cairo_scaled_font_t *scaled_font;
93 } PycairoScaledFont;
94
95 typedef struct {
96 PyObject_HEAD
97 cairo_surface_t *surface;
98 PyObject *base; /* base object used to create surface, or NULL */
99 } PycairoSurface;
100
101 #define PycairoImageSurface PycairoSurface
102 #define PycairoPDFSurface PycairoSurface
103 #define PycairoPSSurface PycairoSurface
104 #define PycairoRecordingSurface PycairoSurface
105 #define PycairoSVGSurface PycairoSurface
106 #define PycairoWin32Surface PycairoSurface
107 #define PycairoWin32PrintingSurface PycairoSurface
108 #define PycairoXCBSurface PycairoSurface
109 #define PycairoXlibSurface PycairoSurface
110
111 /* get C object out of the Python wrapper */
112 #define PycairoContext_GET(obj) (((PycairoContext *)(obj))->ctx)
113
114 /* Define structure for C API. */
115 typedef struct {
116 /* (type object, constructor) pairs */
117 PyTypeObject *Context_Type;
118 PyObject *(*Context_FromContext)(cairo_t *ctx, PyTypeObject *type,
119 PyObject *base);
120 PyTypeObject *FontFace_Type;
121 PyTypeObject *ToyFontFace_Type;
122 PyObject *(*FontFace_FromFontFace)(cairo_font_face_t *font_face);
123 PyTypeObject *FontOptions_Type;
124 PyObject *(*FontOptions_FromFontOptions)(
125 cairo_font_options_t *font_options);
126 PyTypeObject *Matrix_Type;
127 PyObject *(*Matrix_FromMatrix)(const cairo_matrix_t *matrix);
128 PyTypeObject *Path_Type;
129 PyObject *(*Path_FromPath)(cairo_path_t *path);
130
131 PyTypeObject *Pattern_Type;
132 PyTypeObject *SolidPattern_Type;
133 PyTypeObject *SurfacePattern_Type;
134 PyTypeObject *Gradient_Type;
135 PyTypeObject *LinearGradient_Type;
136 PyTypeObject *RadialGradient_Type;
137 PyObject *(*Pattern_FromPattern)(cairo_pattern_t *pattern, PyObject *base);
138
139 PyTypeObject *ScaledFont_Type;
140 PyObject *(*ScaledFont_FromScaledFont)(cairo_scaled_font_t *scaled_font);
141
142 PyTypeObject *Surface_Type;
143 PyTypeObject *ImageSurface_Type;
144 PyTypeObject *PDFSurface_Type;
145 PyTypeObject *PSSurface_Type;
146 PyTypeObject *SVGSurface_Type;
147 PyTypeObject *Win32Surface_Type;
148 PyTypeObject *Win32PrintingSurface_Type;
149 PyTypeObject *XCBSurface_Type;
150 PyTypeObject *XlibSurface_Type;
151 PyObject *(*Surface_FromSurface)(cairo_surface_t *surface, PyObject *base);
152
153 /* misc functions */
154 int (*Check_Status)(cairo_status_t status);
155
156 PyTypeObject *RectangleInt_Type;
157 PyObject *(*RectangleInt_FromRectangleInt)(
158 const cairo_rectangle_int_t *rectangle_int);
159
160 PyTypeObject *Region_Type;
161 PyObject *(*Region_FromRegion)(cairo_region_t *region);
162
163 PyTypeObject *RecordingSurface_Type;
164 } Pycairo_CAPI_t;
165
166
167 #ifndef _INSIDE_PYCAIRO_
168
169 /* Macros for accessing the C API */
170 #define PycairoContext_Type *(Pycairo_CAPI->Context_Type)
171 #define PycairoContext_FromContext (Pycairo_CAPI->Context_FromContext)
172 #define PycairoFontFace_Type *(Pycairo_CAPI->FontFace_Type)
173 #define PycairoToyFontFace_Type *(Pycairo_CAPI->ToyFontFace_Type)
174 #define PycairoFontFace_FromFontFace (Pycairo_CAPI->FontFace_FromFontFace)
175 #define PycairoFontOptions_Type *(Pycairo_CAPI->FontOptions_Type)
176 #define PycairoFontOptions_FromFontOptions \
177 (Pycairo_CAPI->FontOptions_FromFontOptions)
178 #define PycairoMatrix_Type *(Pycairo_CAPI->Matrix_Type)
179 #define PycairoMatrix_FromMatrix (Pycairo_CAPI->Matrix_FromMatrix)
180 #define PycairoPath_Type *(Pycairo_CAPI->Path_Type)
181 #define PycairoPath_FromPath (Pycairo_CAPI->Path_FromPath)
182
183 #define PycairoPattern_Type *(Pycairo_CAPI->Pattern_Type)
184 #define PycairoSolidPattern_Type *(Pycairo_CAPI->SolidPattern_Type)
185 #define PycairoSurfacePattern_Type *(Pycairo_CAPI->SurfacePattern_Type)
186 #define PycairoGradient_Type *(Pycairo_CAPI->Gradient_Type)
187 #define PycairoLinearGradient_Type *(Pycairo_CAPI->LinearGradient_Type)
188 #define PycairoRadialGradient_Type *(Pycairo_CAPI->RadialGradient_Type)
189 #define PycairoPattern_FromPattern (Pycairo_CAPI->Pattern_FromPattern)
190
191 #define PycairoRectangleInt_Type *(Pycairo_CAPI->RectangleInt_Type)
192 #define PycairoRectangleInt_FromRectangleInt \
193 (Pycairo_CAPI->RectangleInt_FromRectangleInt)
194
195 #define PycairoRegion_Type *(Pycairo_CAPI->Region_Type)
196 #define PycairoRegion_FromRegion (Pycairo_CAPI->Region_FromRegion)
197
198 #define PycairoScaledFont_Type *(Pycairo_CAPI->ScaledFont_Type)
199 #define PycairoScaledFont_FromScaledFont \
200 (Pycairo_CAPI->ScaledFont_FromScaledFont)
201
202 #define PycairoSurface_Type *(Pycairo_CAPI->Surface_Type)
203 #define PycairoImageSurface_Type *(Pycairo_CAPI->ImageSurface_Type)
204
205 #ifdef CAIRO_HAS_PDF_SURFACE
206 #define PycairoPDFSurface_Type *(Pycairo_CAPI->PDFSurface_Type)
207 #endif
208
209 #ifdef CAIRO_HAS_PS_SURFACE
210 #define PycairoPSSurface_Type *(Pycairo_CAPI->PSSurface_Type)
211 #endif
212
213 #ifdef CAIRO_HAS_RECORDING_SURFACE
214 #define PycairoRecordingSurface_Type \
215 *(Pycairo_CAPI->RecordingSurface_Type)
216 #endif
217
218 #ifdef CAIRO_HAS_SVG_SURFACE
219 #define PycairoSVGSurface_Type *(Pycairo_CAPI->SVGSurface_Type)
220 #endif
221
222 #ifdef CAIRO_HAS_WIN32_SURFACE
223 #define PycairoWin32Surface_Type *(Pycairo_CAPI->Win32Surface_Type)
224 #define PycairoWin32PrintingSurface_Type \
225 *(Pycairo_CAPI->Win32PrintingSurface_Type)
226 #endif
227
228 #ifdef CAIRO_HAS_XCB_SURFACE
229 #define PycairoXCBSurface_Type *(Pycairo_CAPI->XCBSurface_Type)
230 #endif
231
232 #ifdef CAIRO_HAS_XLIB_SURFACE
233 #define PycairoXlibSurface_Type *(Pycairo_CAPI->XlibSurface_Type)
234 #endif
235
236 #define PycairoSurface_FromSurface (Pycairo_CAPI->Surface_FromSurface)
237
238 #define Pycairo_Check_Status (Pycairo_CAPI->Check_Status)
239
240 #ifdef PYCAIRO_NO_IMPORT
241
242 extern Pycairo_CAPI_t *Pycairo_CAPI;
243
244 #else
245
246 /* To access the Pycairo C API, the client module should call 'import_cairo()'
247 * from the init<module> function, and check the return value, < 0 means the
248 * import failed.
249 */
250 Pycairo_CAPI_t *Pycairo_CAPI;
251
252 /* Return -1 on error, 0 on success.
253 * PyCapsule_Import will set an exception if there's an error.
254 */
255 static inline int
256 import_cairo(void)
257 {
258 Pycairo_CAPI = (Pycairo_CAPI_t*) PyCapsule_Import("cairo.CAPI", 0);
259 return (Pycairo_CAPI != 0) ? 0 : -1;
260 }
261
262 #endif
263
264 #endif /* ifndef _INSIDE_PYCAIRO_ */
265
266 #endif /* ifndef _PYCAIRO_H_ */