Debian Codegraph @

docs/c_api/pycairo_c_api.rst

raw
1 .. highlight:: c
2
3
4 ***************
5 C API Reference
6 ***************
7
8 .. _api-includes:
9
10 Example showing how to import the pycairo API::
11
12 #include "py3cairo.h"
13
14 PyMODINIT_FUNC
15 PyInit_client(void)
16 {
17 PyObject *m;
18
19 m = PyModule_Create(&clientmodule);
20 if (m == NULL)
21 return NULL;
22 if (import_cairo() < 0)
23 return NULL;
24 /* additional initialization can happen here */
25 return m;
26 }
27
28 In case you want to use the API from another compilation unit::
29
30 #define PYCAIRO_NO_IMPORT
31 #include <py3cairo.h>
32
33 ...
34
35 .. versionadded:: 1.17.0
36
37 The ``PYCAIRO_NO_IMPORT`` macro is used since 1.17.0
38
39
40 Misc Functions
41 ==============
42
43 .. c:function:: int Pycairo_Check_Status(cairo_status_t status)
44
45 :param cairo_status_t status:
46 :returns:
47 -1 in case of an error, otherwise 0.
48 Sets an exception in case of an error.
49
50 Takes a status value and converts it to an exception if it represents an
51 error status.
52
53
54 Cairo Context
55 =============
56
57 .. c:type:: PyObject PycairoContext
58
59 .. c:member:: cairo_t* PycairoContext.ctx
60
61 The wrapped :any:`cairo_t`
62
63 .. c:type:: PyTypeObject *PycairoContext_Type
64
65 .. c:macro:: PycairoContext_GET(obj)
66
67 :param PycairoContext obj:
68 :returns: :any:`cairo_t` [transfer none]
69
70 Get the :any:`cairo_t` object out of the :any:`PycairoContext`.
71
72 .. c:function:: PyObject * PycairoContext_FromContext(cairo_t *ctx, PyTypeObject *type, PyObject *base)
73
74 :param cairo_t ctx:
75 a cairo_t to 'wrap' into a Python object.
76 It is unreferenced if the PycairoContext creation fails, or if
77 the cairo_t has an error status. [transfer full]
78 :param PyTypeObject type:
79 a pointer to the type to instantiate.
80 It can be &PycairoContext_Type, or a PycairoContext_Type subtype.
81 (cairo.Context or a cairo.Context subclass)
82 [transfer none]
83 :param PyObject base:
84 the base object used to create the context, or NULL.
85 it is referenced to keep it alive while the cairo_t is being used
86 [transfer none]
87 :returns:
88 New reference or NULL on failure and sets an exception
89 [transfer full]
90
91 Create a new PycairoContext from a :any:`cairo_t`
92
93
94 Cairo Font Face
95 ===============
96
97 .. c:type:: PyObject PycairoFontFace
98
99 .. c:member:: cairo_font_face_t* PycairoFontFace.font_face
100
101 The wrapped :any:`cairo_font_face_t`
102
103 .. c:type:: PyTypeObject *PycairoFontFace_Type
104
105 .. c:function:: PyObject * PycairoFontFace_FromFontFace(cairo_font_face_t *font_face)
106
107 :param cairo_font_face_t font_face:
108 a cairo_font_face_t to 'wrap' into a Python object.
109 it is unreferenced if the PycairoFontFace creation fails
110 [transfer full]
111 :returns:
112 New reference or NULL on failure and sets an exception
113 [transfer full]
114
115 Create a new PycairoFontFace from a cairo_font_face_t
116
117 .. c:type:: PycairoFontFace PycairoToyFontFace
118
119 .. c:type:: PyTypeObject *PycairoToyFontFace_Type
120
121
122 Cairo Font Options
123 ==================
124
125 .. c:type:: PyObject PycairoFontOptions
126
127 .. c:member:: cairo_font_options_t* PycairoFontOptions.font_options
128
129 .. c:type:: PyTypeObject *PycairoFontOptions_Type
130
131 .. c:function:: PyObject * PycairoFontOptions_FromFontOptions(cairo_font_options_t *font_options)
132
133 :param cairo_font_options_t font_options:
134 a cairo_font_options_t to 'wrap' into a Python object.
135 it is unreferenced if the PycairoFontOptions creation fails
136 [transfer full]
137 :returns:
138 New reference or NULL on failure and sets an exception
139 [transfer full]
140
141 Create a new PycairoFontOptions from a cairo_font_options_t
142
143
144 Cairo Matrix
145 ============
146
147 .. c:type:: PyObject PycairoMatrix
148
149 .. c:member:: cairo_matrix_t PycairoMatrix.matrix
150
151 .. c:type:: PyTypeObject *PycairoMatrix_Type
152
153 .. c:function:: PyObject * PycairoMatrix_FromMatrix(const cairo_matrix_t *matrix)
154
155 :param cairo_matrix_t matrix:
156 a cairo_matrix_t to 'wrap' into a Python object.
157 the cairo_matrix_t values are copied.
158 [transfer none]
159 :returns:
160 New reference or NULL on failure and sets an exception
161 [transfer full]
162
163 Create a new PycairoMatrix from a cairo_matrix_t
164
165
166 Cairo Path
167 ==========
168
169 .. c:type:: PyObject PycairoPath
170
171 .. c:member:: cairo_path_t* PycairoPath.path
172
173 .. c:type:: PyTypeObject *PycairoPath_Type
174
175 .. c:function:: PyObject * PycairoPath_FromPath(cairo_path_t *path)
176
177 :param cairo_path_t path:
178 a cairo_path_t to 'wrap' into a Python object.
179 path is unreferenced if the PycairoPath creation fails, or if path
180 is in an error status.
181 [transfer full]
182 :returns:
183 New reference or NULL on failure and sets an exception
184 [transfer full]
185
186 Create a new PycairoPath from a cairo_path_t
187
188
189 Cairo Pattern
190 =============
191
192 .. c:type:: PyObject PycairoPattern
193
194 .. c:member:: cairo_pattern_t* PycairoPattern.pattern
195
196 .. c:type:: PyTypeObject *PycairoPattern_Type
197
198 .. c:type:: PycairoPattern PycairoSolidPattern
199
200 .. c:type:: PyTypeObject *PycairoSolidPattern_Type
201
202 .. c:type:: PycairoPattern PycairoSurfacePattern
203
204 .. c:type:: PyTypeObject *PycairoSurfacePattern_Type
205
206 .. c:type:: PycairoPattern PycairoGradient
207
208 .. c:type:: PyTypeObject *PycairoGradient_Type
209
210 .. c:type:: PycairoGradient PycairoLinearGradient
211
212 .. c:type:: PyTypeObject *PycairoLinearGradient_Type
213
214 .. c:type:: PycairoGradient PycairoRadialGradient
215
216 .. c:type:: PyTypeObject *PycairoRadialGradient_Type
217
218 .. c:function:: PyObject * PycairoPattern_FromPattern(cairo_pattern_t *pattern, PyObject *base)
219
220 :param cairo_pattern_t pattern:
221 a cairo_pattern_t to 'wrap' into a Python object.
222 It is unreferenced if the PycairoPattern creation fails, or if the
223 pattern has an error status.
224 [transfer full]
225 :param PyObject base:
226 the base object used to create the pattern, or NULL.
227 It is referenced to keep it alive while the cairo_pattern_t is being
228 used.
229 [transfer none]
230 :returns:
231 New reference or NULL on failure and sets an exception
232 [transfer full]
233
234 Create a new PycairoSolidPattern, PycairoSurfacePattern,
235 PycairoLinearGradient, or PycairoRadialGradient from a cairo_pattern_t.
236
237
238 Cairo Region
239 ============
240
241 .. c:type:: PyObject PycairoRegion
242
243 .. c:member:: cairo_region_t* PycairoRegion.region
244
245 .. c:type:: PyTypeObject *PycairoRegion_Type
246
247 .. c:function:: PyObject * PycairoRegion_FromRegion(cairo_region_t *region)
248
249 :param cairo_region_t region:
250 a cairo_region_t to 'wrap' into a Python object.
251 region is unreferenced if the PycairoRegion creation fails, or if
252 region is in an error status.
253 :returns:
254 New reference or NULL on failure and sets an exception
255 [transfer full]
256
257 Create a new PycairoRegion from a cairo_region_t
258
259
260 Cairo RectangleInt
261 ==================
262
263 .. c:type:: PyObject PycairoRectangleInt
264
265 .. c:member:: cairo_rectangle_int_t* PycairoRectangleInt.rectangle_int
266
267 .. c:type:: PyTypeObject *PycairoRectangleInt_Type
268
269 .. c:function:: PyObject * PycairoRectangleInt_FromRectangleInt(const cairo_rectangle_int_t *rectangle_int)
270
271 :param cairo_rectangle_int_t rectangle_int:
272 a cairo_rectangle_int_t to 'wrap' into a Python object.
273 rectangle_int is unreferenced if the PycairoRectangleInt creation
274 fails.
275 [transfer none]
276 :returns:
277 New reference or NULL on failure and sets an exception
278 [transfer full]
279
280 Create a new PycairoRectangleInt from a cairo_rectangle_int_t
281
282
283 Scaled Font
284 ===========
285
286 .. c:type:: PyObject PycairoScaledFont
287
288 .. c:member:: cairo_scaled_font_t* PycairoScaledFont.scaled_font
289
290 .. c:type:: PyTypeObject *PycairoScaledFont_Type
291
292 .. c:function:: PyObject * PycairoScaledFont_FromScaledFont(cairo_scaled_font_t *scaled_font)
293
294 :param cairo_scaled_font_t scaled_font:
295 a cairo_scaled_font_t to 'wrap' into a Python object.
296 it is unreferenced if the PycairoScaledFont creation fails
297 [transfer full]
298 :returns:
299 New reference or NULL on failure and sets an exception
300 [transfer full]
301
302 Create a new PycairoScaledFont from a cairo_scaled_font_t
303
304
305 Cairo Surface
306 =============
307
308 .. c:type:: PyObject PycairoSurface
309
310 .. c:member:: cairo_surface_t* PycairoSurface.surface
311
312 .. c:type:: PyTypeObject *PycairoSurface_Type
313
314 .. c:type:: PycairoSurface PycairoImageSurface
315 .. c:type:: PyTypeObject *PycairoImageSurface_Type
316
317 .. c:type:: PycairoSurface PycairoPDFSurface
318 .. c:type:: PyTypeObject *PycairoPDFSurface_Type
319
320 .. c:type:: PycairoSurface PycairoPSSurface
321 .. c:type:: PyTypeObject *PycairoPSSurface_Type
322
323 .. c:type:: PycairoSurface PycairoRecordingSurface
324 .. c:type:: PyTypeObject *PycairoRecordingSurface_Type
325
326 .. c:type:: PycairoSurface PycairoSVGSurface
327 .. c:type:: PyTypeObject *PycairoSVGSurface_Type
328
329 .. c:type:: PycairoSurface PycairoWin32Surface
330 .. c:type:: PyTypeObject *PycairoWin32Surface_Type
331
332 .. c:type:: PycairoSurface PycairoXCBSurface
333 .. c:type:: PyTypeObject *PycairoXCBSurface_Type
334
335 .. c:type:: PycairoSurface PycairoXlibSurface
336 .. c:type:: PyTypeObject *PycairoXlibSurface_Type
337
338 .. c:function:: PyObject * PycairoSurface_FromSurface(cairo_surface_t *surface, PyObject *base)
339
340 :param cairo_surface_t surface:
341 a cairo_surface_t to 'wrap' into a Python object.
342 It is unreferenced if the PycairoSurface creation fails, or if the
343 cairo_surface_t has an error status.
344 [transfer full]
345 :param PyObject base:
346 the base object used to create the surface, or NULL.
347 It is referenced to keep it alive while the cairo_surface_t is being
348 used.
349 [transfer none]
350 :returns:
351 New reference or NULL on failure and sets an exception
352 [transfer full]
353
354 Create a new PycairoImageSurface, PycairoPDFSurface, PycairoPSSurface,
355 PycairoRecordingSurface, PycairoSVGSurface, PycairoWin32Surface,
356 PycairoWin32PrintingSurface, PycairoXCBSurface, or PycairoXlibSurface from
357 a cairo_surface_t.
358
359
360 Cairo Types
361 ===========
362
363 These are only listed here so they can be referenced in the documentation.
364
365 See https://www.cairographics.org/manual/ for details.
366
367 .. c:type:: cairo_t
368 cairo_status_t
369 cairo_surface_t
370 cairo_scaled_font_t
371 cairo_rectangle_int_t
372 cairo_region_t
373 cairo_pattern_t
374 cairo_matrix_t
375 cairo_font_options_t
376 cairo_path_t
377 cairo_font_face_t
378
379
380 CPython Types
381 =============
382
383 .. c:type:: PyObject
384
385 .. c:type:: PyTypeObject