Debian Codegraph @

cairo/private.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_PRIVATE_H_
33 #define _PYCAIRO_PRIVATE_H_
34
35 #ifdef _PYCAIRO_H_
36 # error "don't include py3cairo.h and pycairo-private.h together"
37 #endif
38
39 #define _INSIDE_PYCAIRO_
40 #include <Python.h>
41
42 #include "py3cairo.h"
43
44 #define PYCAIRO_STRINGIFY(s) PYCAIRO_STRINGIFY_ARG(s)
45 #define PYCAIRO_STRINGIFY_ARG(s) #s
46
47 int init_error(PyObject *module);
48
49 int Pycairo_fspath_converter (PyObject *obj, char** result);
50 int Pycairo_fspath_none_converter (PyObject *obj, char** result);
51 int Pycairo_writer_converter (PyObject *obj, PyObject** file);
52 int Pycairo_reader_converter (PyObject *obj, PyObject** file);
53 int Pycairo_is_fspath (PyObject *obj);
54
55 cairo_glyph_t * _PycairoGlyphs_AsGlyphs (PyObject *py_object, int *num_glyphs);
56 int _PyGlyph_AsGlyph (PyObject *pyobj, cairo_glyph_t *glyph);
57 int _PyTextCluster_AsTextCluster (PyObject *pyobj,
58 cairo_text_cluster_t *cluster);
59
60 int _conv_pyobject_to_ulong (PyObject *pyobj, unsigned long *result);
61
62 PyObject* Pycairo_richcompare (void* a, void *b, int op);
63
64 extern PyTypeObject PycairoContext_Type;
65 PyObject *PycairoContext_FromContext (cairo_t *ctx, PyTypeObject *type,
66 PyObject *base);
67
68 extern PyTypeObject PycairoFontFace_Type;
69 extern PyTypeObject PycairoToyFontFace_Type;
70 PyObject *PycairoFontFace_FromFontFace (cairo_font_face_t *font_face);
71
72 extern PyTypeObject PycairoFontOptions_Type;
73 PyObject *PycairoFontOptions_FromFontOptions (
74 cairo_font_options_t *font_options);
75
76 extern PyTypeObject PycairoMatrix_Type;
77 PyObject *PycairoMatrix_FromMatrix (const cairo_matrix_t *matrix);
78
79 extern PyTypeObject PycairoPath_Type;
80 PyObject *PycairoPath_FromPath (cairo_path_t *path);
81
82 extern PyTypeObject PycairoPathiter_Type;
83
84 extern PyTypeObject PycairoPattern_Type;
85 extern PyTypeObject PycairoSolidPattern_Type;
86 extern PyTypeObject PycairoSurfacePattern_Type;
87 extern PyTypeObject PycairoGradient_Type;
88 extern PyTypeObject PycairoLinearGradient_Type;
89 extern PyTypeObject PycairoRadialGradient_Type;
90 PyObject *PycairoPattern_FromPattern (cairo_pattern_t *pattern,
91 PyObject *base);
92
93 typedef PycairoPattern PycairoMeshPattern;
94 extern PyTypeObject PycairoMeshPattern_Type;
95
96 typedef PycairoPattern PycairoRasterSourcePattern;
97 extern PyTypeObject PycairoRasterSourcePattern_Type;
98
99 extern PyTypeObject PycairoRectangleInt_Type;
100 PyObject *PycairoRectangleInt_FromRectangleInt (
101 const cairo_rectangle_int_t *rectangle_int);
102
103 extern PyTypeObject PycairoRegion_Type;
104 PyObject *PycairoRegion_FromRegion (cairo_region_t *region);
105
106 extern PyTypeObject PycairoDevice_Type;
107 PyObject *PycairoDevice_FromDevice (cairo_device_t *device);
108 extern PyTypeObject PycairoScriptDevice_Type;
109
110 extern PyTypeObject PycairoScaledFont_Type;
111 PyObject *PycairoScaledFont_FromScaledFont (cairo_scaled_font_t *scaled_font);
112
113 extern PyTypeObject PycairoSurface_Type;
114 extern PyTypeObject PycairoImageSurface_Type;
115 extern PyTypeObject PycairoMappedImageSurface_Type;
116
117 extern PyTypeObject PycairoGlyph_Type;
118 typedef PyTupleObject PycairGlyph;
119
120 extern PyTypeObject PycairoRectangle_Type;
121 typedef PyTupleObject PycairRectangle;
122
123 extern PyTypeObject PycairoTextCluster_Type;
124 typedef PyTupleObject PycairTextCluster;
125
126 extern PyTypeObject PycairoTextExtents_Type;
127 typedef PyTupleObject PycairoTextExtents;
128
129 typedef struct {
130 PyObject_HEAD
131 cairo_device_t *device;
132 } PycairoDevice;
133
134 #ifdef CAIRO_HAS_SCRIPT_SURFACE
135 typedef PycairoDevice PycairoScriptDevice;
136 extern PyTypeObject PycairoScriptSurface_Type;
137 #endif
138
139 #ifdef CAIRO_HAS_PDF_SURFACE
140 extern PyTypeObject PycairoPDFSurface_Type;
141 #endif
142
143 #ifdef CAIRO_HAS_PS_SURFACE
144 extern PyTypeObject PycairoPSSurface_Type;
145 #endif
146
147 #ifdef CAIRO_HAS_RECORDING_SURFACE
148 extern PyTypeObject PycairoRecordingSurface_Type;
149 #endif
150
151 #ifdef CAIRO_HAS_SVG_SURFACE
152 extern PyTypeObject PycairoSVGSurface_Type;
153 #endif
154
155 #ifdef CAIRO_HAS_WIN32_SURFACE
156 extern PyTypeObject PycairoWin32Surface_Type;
157 extern PyTypeObject PycairoWin32PrintingSurface_Type;
158 #endif
159
160 #ifdef CAIRO_HAS_XCB_SURFACE
161 extern PyTypeObject PycairoXCBSurface_Type;
162 #endif
163
164 #ifdef CAIRO_HAS_XLIB_SURFACE
165 extern PyTypeObject PycairoXlibSurface_Type;
166 #endif
167
168 #ifdef CAIRO_HAS_TEE_SURFACE
169 typedef PycairoSurface PycairoTeeSurface;
170 extern PyTypeObject PycairoTeeSurface_Type;
171 #endif
172
173 PyObject *PycairoSurface_FromSurface (cairo_surface_t *surface,
174 PyObject *base);
175
176 int Pycairo_Check_Status (cairo_status_t status);
177
178 /* error checking macros */
179 #define RETURN_NULL_IF_CAIRO_ERROR(status) \
180 do { \
181 if (status != CAIRO_STATUS_SUCCESS) { \
182 Pycairo_Check_Status (status); \
183 return NULL; \
184 } \
185 } while (0)
186
187 #define RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(ctx) \
188 do { \
189 cairo_status_t status = cairo_status (ctx); \
190 if (status != CAIRO_STATUS_SUCCESS) { \
191 Pycairo_Check_Status (status); \
192 return NULL; \
193 } \
194 } while (0)
195
196 #define RETURN_NULL_IF_CAIRO_PATTERN_ERROR(pattern) \
197 do { \
198 cairo_status_t status = cairo_pattern_status (pattern); \
199 if (status != CAIRO_STATUS_SUCCESS) { \
200 Pycairo_Check_Status (status); \
201 return NULL; \
202 } \
203 } while (0)
204
205 #define RETURN_NULL_IF_CAIRO_REGION_ERROR(region) \
206 do { \
207 cairo_status_t status = cairo_region_status (region); \
208 if (status != CAIRO_STATUS_SUCCESS) { \
209 Pycairo_Check_Status (status); \
210 return NULL; \
211 } \
212 } while (0)
213
214 #define RETURN_NULL_IF_CAIRO_SURFACE_ERROR(surface) \
215 do { \
216 cairo_status_t status = cairo_surface_status (surface); \
217 if (status != CAIRO_STATUS_SUCCESS) { \
218 Pycairo_Check_Status (status); \
219 return NULL; \
220 } \
221 } while (0)
222
223 #define RETURN_NULL_IF_CAIRO_DEVICE_ERROR(device) \
224 do { \
225 cairo_status_t status = cairo_device_status (device); \
226 if (status != CAIRO_STATUS_SUCCESS) { \
227 Pycairo_Check_Status (status); \
228 return NULL; \
229 } \
230 } while (0)
231
232 #define RETURN_NULL_IF_CAIRO_SCALED_FONT_ERROR(sc_font) \
233 do { \
234 cairo_status_t status = cairo_scaled_font_status (sc_font); \
235 if (status != CAIRO_STATUS_SUCCESS) { \
236 Pycairo_Check_Status (status); \
237 return NULL; \
238 } \
239 } while (0)
240
241 #define RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(fo) \
242 do { \
243 cairo_status_t status = cairo_font_options_status (fo); \
244 if (status != CAIRO_STATUS_SUCCESS) { \
245 Pycairo_Check_Status (status); \
246 return NULL; \
247 } \
248 } while (0)
249
250
251 PyObject *error_get_type(void);
252
253 int init_buffer_proxy(void);
254
255 PyObject *buffer_proxy_create_view(PyObject *exporter, void *buf,
256 Py_ssize_t len, int readonly);
257
258 /* int enums */
259
260 int init_enums(PyObject *module);
261 PyObject *int_enum_create(PyTypeObject *type, long value);
262
263 #define DECL_ENUM(name) extern PyTypeObject Pycairo_##name##_Type;
264
265 /* A defined variant of (int)(unsigned int)(u). The cast from unsigned to
266 * signed gives the reverse result of a signed to unsigned cast. */
267 #define _ENSURE_INT(u) ( \
268 ((unsigned int)(u) > INT_MAX) ? \
269 -(int)(UINT_MAX - (unsigned int)(u)) - 1 : (int)(unsigned int)(u) \
270 )
271
272 #define CREATE_INT_ENUM(type_name, value) \
273 (int_enum_create(&Pycairo_##type_name##_Type, _ENSURE_INT(value)))
274
275 #define RETURN_INT_ENUM(type_name, value) \
276 return CREATE_INT_ENUM(type_name, value);
277
278 DECL_ENUM(Antialias)
279 DECL_ENUM(Content)
280 DECL_ENUM(Extend)
281 DECL_ENUM(FillRule)
282 DECL_ENUM(Filter)
283 DECL_ENUM(FontSlant)
284 DECL_ENUM(FontWeight)
285 DECL_ENUM(Format)
286 DECL_ENUM(HintMetrics)
287 DECL_ENUM(HintStyle)
288 DECL_ENUM(LineCap)
289 DECL_ENUM(LineJoin)
290 DECL_ENUM(Operator)
291 DECL_ENUM(PathDataType)
292 DECL_ENUM(RegionOverlap)
293 DECL_ENUM(Status)
294 DECL_ENUM(SubpixelOrder)
295 DECL_ENUM(TextClusterFlags)
296 DECL_ENUM(SurfaceObserverMode)
297 #ifdef CAIRO_HAS_SVG_SURFACE
298 DECL_ENUM(SVGVersion)
299 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 15, 10)
300 DECL_ENUM(SVGUnit)
301 #endif
302 #endif
303 #ifdef CAIRO_HAS_PDF_SURFACE
304 DECL_ENUM(PDFVersion)
305 #endif
306 #ifdef CAIRO_HAS_PS_SURFACE
307 DECL_ENUM(PSLevel)
308 #endif
309 #ifdef CAIRO_HAS_SCRIPT_SURFACE
310 DECL_ENUM(ScriptMode)
311 #endif
312 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 17, 8)
313 DECL_ENUM(ColorMode)
314 #endif
315 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 18, 0)
316 DECL_ENUM(Dither)
317 #endif
318
319 /* Use to disable deprecation warnings temporarily */
320 #ifdef _MSC_VER
321 # define PYCAIRO_BEGIN_IGNORE_DEPRECATED \
322 __pragma (warning (push)) \
323 __pragma (warning (disable : 4996))
324
325 # define PYCAIRO_END_IGNORE_DEPRECATED \
326 __pragma (warning (pop))
327
328 #else
329
330 # define PYCAIRO_BEGIN_IGNORE_DEPRECATED \
331 _Pragma ("GCC diagnostic push") \
332 _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
333
334 # define PYCAIRO_END_IGNORE_DEPRECATED \
335 _Pragma ("GCC diagnostic pop")
336 #endif
337
338 #ifdef __GNUC__
339 #define PYCAIRO_MODINIT_FUNC __attribute__((visibility("default"))) PyMODINIT_FUNC
340 #else
341 #define PYCAIRO_MODINIT_FUNC PyMODINIT_FUNC
342 #endif
343
344 #define PYCAIRO_Py_hash_t_FromVoidPtr(p) ((Py_hash_t)(Py_ssize_t)(p))
345
346 #endif /* _PYCAIRO_PRIVATE_H_ */