File: pycairo_c_api.rst

package info (click to toggle)
pycairo 1.27.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,984 kB
  • sloc: ansic: 8,873; python: 3,688; makefile: 32; sh: 4
file content (385 lines) | stat: -rw-r--r-- 10,473 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
.. highlight:: c


***************
C API Reference
***************

.. _api-includes:

Example showing how to import the pycairo API::

  #include "py3cairo.h"

  PyMODINIT_FUNC
  PyInit_client(void)
  {
    PyObject *m;

    m = PyModule_Create(&clientmodule);
    if (m == NULL)
        return NULL;
    if (import_cairo() < 0)
        return NULL;
    /* additional initialization can happen here */
    return m;
  }

In case you want to use the API from another compilation unit::

  #define PYCAIRO_NO_IMPORT
  #include <py3cairo.h>

  ...

.. versionadded:: 1.17.0

    The ``PYCAIRO_NO_IMPORT`` macro is used since 1.17.0


Misc Functions
==============

.. c:function::  int Pycairo_Check_Status(cairo_status_t status)

    :param cairo_status_t status:
    :returns:
        -1 in case of an error, otherwise 0.
        Sets an exception in case of an error.

    Takes a status value and converts it to an exception if it represents an
    error status.


Cairo Context
=============

.. c:type:: PyObject PycairoContext

.. c:member:: cairo_t* PycairoContext.ctx

    The wrapped :any:`cairo_t`

.. c:type:: PyTypeObject *PycairoContext_Type

.. c:macro:: PycairoContext_GET(obj)

    :param PycairoContext obj:
    :returns: :any:`cairo_t` [transfer none]

    Get the :any:`cairo_t` object out of the :any:`PycairoContext`.

.. c:function:: PyObject * PycairoContext_FromContext(cairo_t *ctx, PyTypeObject *type, PyObject *base)

    :param cairo_t ctx:
        a cairo_t to 'wrap' into a Python object.
        It is unreferenced if the PycairoContext creation fails, or if
        the cairo_t has an error status. [transfer full]
    :param PyTypeObject type:
        a pointer to the type to instantiate.
        It can be &PycairoContext_Type, or a PycairoContext_Type subtype.
        (cairo.Context or a cairo.Context subclass)
        [transfer none]
    :param PyObject base:
        the base object used to create the context, or NULL.
        it is referenced to keep it alive while the cairo_t is being used
        [transfer none]
    :returns:
        New reference or NULL on failure and sets an exception
        [transfer full]

    Create a new PycairoContext from a :any:`cairo_t`


Cairo Font Face
===============

.. c:type:: PyObject PycairoFontFace

.. c:member:: cairo_font_face_t* PycairoFontFace.font_face

The wrapped :any:`cairo_font_face_t`

.. c:type:: PyTypeObject *PycairoFontFace_Type

.. c:function:: PyObject * PycairoFontFace_FromFontFace(cairo_font_face_t *font_face)

    :param cairo_font_face_t font_face:
        a cairo_font_face_t to 'wrap' into a Python object.
        it is unreferenced if the PycairoFontFace creation fails
        [transfer full]
    :returns:
        New reference or NULL on failure and sets an exception
        [transfer full]

    Create a new PycairoFontFace from a cairo_font_face_t

.. c:type:: PycairoFontFace PycairoToyFontFace

.. c:type:: PyTypeObject *PycairoToyFontFace_Type


Cairo Font Options
==================

.. c:type:: PyObject PycairoFontOptions

.. c:member:: cairo_font_options_t* PycairoFontOptions.font_options

.. c:type:: PyTypeObject *PycairoFontOptions_Type

.. c:function:: PyObject * PycairoFontOptions_FromFontOptions(cairo_font_options_t *font_options)

    :param cairo_font_options_t font_options:
        a cairo_font_options_t to 'wrap' into a Python object.
        it is unreferenced if the PycairoFontOptions creation fails
        [transfer full]
    :returns:
        New reference or NULL on failure and sets an exception
        [transfer full]

    Create a new PycairoFontOptions from a cairo_font_options_t


Cairo Matrix
============

.. c:type:: PyObject PycairoMatrix

.. c:member:: cairo_matrix_t PycairoMatrix.matrix

.. c:type:: PyTypeObject *PycairoMatrix_Type

.. c:function:: PyObject * PycairoMatrix_FromMatrix(const cairo_matrix_t *matrix)

    :param cairo_matrix_t matrix:
        a cairo_matrix_t to 'wrap' into a Python object.
        the cairo_matrix_t values are copied.
        [transfer none]
    :returns:
        New reference or NULL on failure and sets an exception
        [transfer full]

    Create a new PycairoMatrix from a cairo_matrix_t


Cairo Path
==========

.. c:type:: PyObject PycairoPath

.. c:member:: cairo_path_t* PycairoPath.path

.. c:type:: PyTypeObject *PycairoPath_Type

.. c:function:: PyObject * PycairoPath_FromPath(cairo_path_t *path)

    :param cairo_path_t path:
        a cairo_path_t to 'wrap' into a Python object.
        path is unreferenced if the PycairoPath creation fails, or if path
        is in an error status.
        [transfer full]
    :returns:
        New reference or NULL on failure and sets an exception
        [transfer full]

    Create a new PycairoPath from a cairo_path_t


Cairo Pattern
=============

.. c:type:: PyObject PycairoPattern

.. c:member:: cairo_pattern_t* PycairoPattern.pattern

.. c:type:: PyTypeObject *PycairoPattern_Type

.. c:type:: PycairoPattern PycairoSolidPattern

.. c:type:: PyTypeObject *PycairoSolidPattern_Type

.. c:type:: PycairoPattern PycairoSurfacePattern

.. c:type:: PyTypeObject *PycairoSurfacePattern_Type

.. c:type:: PycairoPattern PycairoGradient

.. c:type:: PyTypeObject *PycairoGradient_Type

.. c:type:: PycairoGradient PycairoLinearGradient

.. c:type:: PyTypeObject *PycairoLinearGradient_Type

.. c:type:: PycairoGradient PycairoRadialGradient

.. c:type:: PyTypeObject *PycairoRadialGradient_Type

.. c:function:: PyObject * PycairoPattern_FromPattern(cairo_pattern_t *pattern, PyObject *base)

    :param cairo_pattern_t pattern:
        a cairo_pattern_t to 'wrap' into a Python object.
        It is unreferenced if the PycairoPattern creation fails, or if the
        pattern has an error status.
        [transfer full]
    :param PyObject base:
        the base object used to create the pattern, or NULL.
        It is referenced to keep it alive while the cairo_pattern_t is being
        used.
        [transfer none]
    :returns:
        New reference or NULL on failure and sets an exception
        [transfer full]

    Create a new PycairoSolidPattern, PycairoSurfacePattern,
    PycairoLinearGradient, or PycairoRadialGradient from a cairo_pattern_t.


Cairo Region
============

.. c:type:: PyObject PycairoRegion

.. c:member:: cairo_region_t* PycairoRegion.region

.. c:type:: PyTypeObject *PycairoRegion_Type

.. c:function:: PyObject * PycairoRegion_FromRegion(cairo_region_t *region)

    :param cairo_region_t region:
        a cairo_region_t to 'wrap' into a Python object.
        region is unreferenced if the PycairoRegion creation fails, or if
        region is in an error status.
    :returns:
        New reference or NULL on failure and sets an exception
        [transfer full]

    Create a new PycairoRegion from a cairo_region_t


Cairo RectangleInt
==================

.. c:type:: PyObject PycairoRectangleInt

.. c:member:: cairo_rectangle_int_t* PycairoRectangleInt.rectangle_int

.. c:type:: PyTypeObject *PycairoRectangleInt_Type

.. c:function:: PyObject * PycairoRectangleInt_FromRectangleInt(const cairo_rectangle_int_t *rectangle_int)

    :param cairo_rectangle_int_t rectangle_int:
        a cairo_rectangle_int_t to 'wrap' into a Python object.
        rectangle_int is unreferenced if the PycairoRectangleInt creation
        fails.
        [transfer none]
    :returns:
        New reference or NULL on failure and sets an exception
        [transfer full]

    Create a new PycairoRectangleInt from a cairo_rectangle_int_t


Scaled Font
===========

.. c:type:: PyObject PycairoScaledFont

.. c:member:: cairo_scaled_font_t* PycairoScaledFont.scaled_font

.. c:type:: PyTypeObject *PycairoScaledFont_Type

.. c:function:: PyObject * PycairoScaledFont_FromScaledFont(cairo_scaled_font_t *scaled_font)

    :param cairo_scaled_font_t scaled_font:
        a cairo_scaled_font_t to 'wrap' into a Python object.
        it is unreferenced if the PycairoScaledFont creation fails
        [transfer full]
    :returns:
        New reference or NULL on failure and sets an exception
        [transfer full]

    Create a new PycairoScaledFont from a cairo_scaled_font_t


Cairo Surface
=============

.. c:type:: PyObject PycairoSurface

.. c:member:: cairo_surface_t* PycairoSurface.surface

.. c:type:: PyTypeObject *PycairoSurface_Type

.. c:type:: PycairoSurface PycairoImageSurface
.. c:type:: PyTypeObject *PycairoImageSurface_Type

.. c:type:: PycairoSurface PycairoPDFSurface
.. c:type:: PyTypeObject *PycairoPDFSurface_Type

.. c:type:: PycairoSurface PycairoPSSurface
.. c:type:: PyTypeObject *PycairoPSSurface_Type

.. c:type:: PycairoSurface PycairoRecordingSurface
.. c:type:: PyTypeObject *PycairoRecordingSurface_Type

.. c:type:: PycairoSurface PycairoSVGSurface
.. c:type:: PyTypeObject *PycairoSVGSurface_Type

.. c:type:: PycairoSurface PycairoWin32Surface
.. c:type:: PyTypeObject *PycairoWin32Surface_Type

.. c:type:: PycairoSurface PycairoXCBSurface
.. c:type:: PyTypeObject *PycairoXCBSurface_Type

.. c:type:: PycairoSurface PycairoXlibSurface
.. c:type:: PyTypeObject *PycairoXlibSurface_Type

.. c:function::  PyObject * PycairoSurface_FromSurface(cairo_surface_t *surface, PyObject *base)

    :param cairo_surface_t surface:
        a cairo_surface_t to 'wrap' into a Python object.
        It is unreferenced if the PycairoSurface creation fails, or if the
        cairo_surface_t has an error status.
        [transfer full]
    :param PyObject base:
        the base object used to create the surface, or NULL.
        It is referenced to keep it alive while the cairo_surface_t is being
        used.
        [transfer none]
    :returns:
        New reference or NULL on failure and sets an exception
        [transfer full]

    Create a new PycairoImageSurface, PycairoPDFSurface, PycairoPSSurface,
    PycairoRecordingSurface, PycairoSVGSurface, PycairoWin32Surface,
    PycairoWin32PrintingSurface, PycairoXCBSurface, or PycairoXlibSurface from
    a cairo_surface_t.


Cairo Types
===========

These are only listed here so they can be referenced in the documentation.

See https://www.cairographics.org/manual/ for details.

.. c:type:: cairo_t
    cairo_status_t
    cairo_surface_t
    cairo_scaled_font_t
    cairo_rectangle_int_t
    cairo_region_t
    cairo_pattern_t
    cairo_matrix_t
    cairo_font_options_t
    cairo_path_t
    cairo_font_face_t


CPython Types
=============

.. c:type:: PyObject

.. c:type:: PyTypeObject