C API Reference

This manual documents the API used by C and C++ programmers who want to write extension modules that use pycairo.

To access the Pycairo C API under Python 2

Edit the client module file to add the following lines:

/* All function, type and macro definitions needed to use the Pycairo/C API
 * are included in your code by the following line
 */
#include "Pycairo.h"

/* define a variable for the C API */
static Pycairo_CAPI_t *Pycairo_CAPI;

/* import pycairo - add to the init<module> function */
Pycairo_IMPORT;

To access the Pycairo C API under Python 3

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;
}

Pycairo Objects

PycairoContext
PycairoFontFace
PycairoToyFontFace
PycairoFontOptions
PycairoMatrix
PycairoPath
PycairoPattern
PycairoRegion
PycairoRectangleInt
PycairoSolidPattern
PycairoSurfacePattern
PycairoGradient
PycairoLinearGradient
PycairoRadialGradient
PycairoScaledFont
PycairoSurface
PycairoImageSurface
PycairoPDFSurface
PycairoPSSurface
PycairoRecordingSurface
PycairoSVGSurface
PycairoWin32Surface
PycairoXCBSurface
PycairoXlibSurface

Pycairo Types

PyTypeObject *Context_Type
PyTypeObject *FontFace_Type
PyTypeObject *ToyFontFace_Type
PyTypeObject *FontOptions_Type
PyTypeObject *Matrix_Type
PyTypeObject *Path_Type
PyTypeObject *Pattern_Type
PyTypeObject *Region_Type
PyTypeObject *RectangleInt_Type
PyTypeObject *SolidPattern_Type
PyTypeObject *SurfacePattern_Type
PyTypeObject *Gradient_Type
PyTypeObject *LinearGradient_Type
PyTypeObject *RadialGradient_Type
PyTypeObject *ScaledFont_Type
PyTypeObject *Surface_Type
PyTypeObject *ImageSurface_Type
PyTypeObject *PDFSurface_Type
PyTypeObject *PSSurface_Type
PyTypeObject *RecordingSurface_Type
PyTypeObject *SVGSurface_Type
PyTypeObject *Win32Surface_Type
PyTypeObject *XCBSurface_Type
PyTypeObject *XlibSurface_Type

Functions

cairo_t * PycairoContext_GET(PycairoContext *obj)

get the C cairo_t * object out of the PycairoContext *obj

PyObject * PycairoContext_FromContext(cairo_t *ctx, PyTypeObject *type, PyObject *base)
PyObject * PycairoFontFace_FromFontFace(cairo_font_face_t *font_face)
PyObject * PycairoFontOptions_FromFontOptions(cairo_font_options_t *font_options)
PyObject * PycairoMatrix_FromMatrix(const cairo_matrix_t *matrix)
PyObject * PycairoPath_FromPath(cairo_path_t *path)
PyObject * PycairoPattern_FromPattern(cairo_pattern_t *pattern, PyObject *base)
PyObject * PycairoRegion_FromRegion(cairo_region_t *region)
PyObject * PycairoRectangleInt_FromRectangleInt(const cairo_rectangle_int_t *rectangle_int)
PyObject * PycairoScaledFont_FromScaledFont(cairo_scaled_font_t *scaled_font)
PyObject * PycairoSurface_FromSurface(cairo_surface_t *surface, PyObject *base)
int Pycairo_Check_Status(cairo_status_t status)

Cairo Types

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

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