Skip to content

Latest commit

 

History

History
427 lines (283 loc) · 11.8 KB

pycairo_c_api.rst

File metadata and controls

427 lines (283 loc) · 11.8 KB

c

C API Reference

cairo

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

Pycairo Compiler Flags

To compile a Python extension using Pycairo you need to know where Pycairo and cairo are located and what flags to pass to the compiler and linker.

  1. Variant:

    Only available since version 1.16.0.

    While Pycairo installs a pkg-config file, in case of virtualenvs, installation to the user directory or when using wheels/eggs, pkg-config will not be able to locate the .pc file. The get_include function should work in all cases, as long as Pycairo is in your Python search path.

    Compiler Flags:
    • python -c "import cairo; print(cairo.get_include())"
    • pkg-config --cflags cairo
    Linker Flags:
    • pkg-config --libs cairo
  2. Variant:

    This works with older versions, but with the limitations mentioned above. Use it as a fallback if you want to support older versions or if your module does not require virtualenv/pip support.

    Compiler Flags:
    • pkg-config --cflags pycairo or pkg-config --cflags py3cairo
    Linker Flags:
    • pkg-config --libs pycairo or pkg-config --libs py3cairo

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

Misc Functions

Cairo Context

Cairo Font Face

Cairo Font Options

Cairo Matrix

Cairo Path

Cairo Pattern

Cairo Region

Cairo RectangleInt

Scaled Font

Cairo Surface

Cairo Types

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

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