C API参考

演示如何导入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;
}

如果您想使用来自其他编译单元的API::

#define PYCAIRO_NO_IMPORT
#include <py3cairo.h>

...

在 1.17.0 版本加入: 这个 PYCAIRO_NO_IMPORT 宏从1.17.0开始使用

其他功能

int Pycairo_Check_Status(cairo_status_t status)
参数:
返回:

如果出现错误,则返回-1,否则为0。在发生错误时设置异常。

获取状态值,如果该值表示错误状态,则将其转换为异常。

开罗环境

typedef PyObject PycairoContext
cairo_t *PycairoContext.ctx

被包裹住的 cairo_t

typedef PyTypeObject *PycairoContext_Type
PycairoContext_GET(obj)
参数:
返回:

cairo_t [transfer none]

vt.得到. cairo_t 对象移出 PycairoContext

PyObject *PycairoContext_FromContext(cairo_t *ctx, PyTypeObject *type, PyObject *base)
参数:
  • ctx (cairo_t) -- 将cairo_t‘包装’到一个Python对象中。如果PycairoContext创建失败,或者cairo_t具有错误状态,则不会引用它。 [transfer full]

  • type (PyTypeObject) -- 指向要实例化的类型的指针。它可以是&PycairoContext_Type或PycairoContext_Type子类型。(cairo.Context或cairo.Context子类) [transfer none]

  • base (PyObject) -- 用于创建上下文的基对象,或为空。引用它是为了在使用cairo_t时使其保持活动状态 [transfer none]

返回:

失败时为新引用或NULL,并设置异常 [transfer full]

创建一个新的PycairoContext cairo_t

开罗字体脸

typedef PyObject PycairoFontFace
cairo_font_face_t *PycairoFontFace.font_face

被包裹住的 cairo_font_face_t

typedef PyTypeObject *PycairoFontFace_Type
PyObject *PycairoFontFace_FromFontFace(cairo_font_face_t *font_face)
参数:
  • font_face (cairo_font_face_t) -- 一个cairo_font_facet要‘包装’到一个Python对象中。如果创建PycairoFontFace失败,则取消引用它 [transfer full]

返回:

失败时为新引用或NULL,并设置异常 [transfer full]

从cairo_FONT_Face_t创建新的PycairoFontFace

typedef PycairoFontFace PycairoToyFontFace
typedef PyTypeObject *PycairoToyFontFace_Type

开罗字体选项

typedef PyObject PycairoFontOptions
cairo_font_options_t *PycairoFontOptions.font_options
typedef PyTypeObject *PycairoFontOptions_Type
PyObject *PycairoFontOptions_FromFontOptions(cairo_font_options_t *font_options)
参数:
  • font_options (cairo_font_options_t) -- 一个cairo_font_Options_t,用于‘包装’到一个Python对象中。如果创建PycairoFontOptions失败,则取消引用它 [transfer full]

返回:

失败时为新引用或NULL,并设置异常 [transfer full]

从cairo_FONT_OPTIONS_t创建新的PycairoFontOptions

开罗矩阵

typedef PyObject PycairoMatrix
cairo_matrix_t PycairoMatrix.matrix
typedef PyTypeObject *PycairoMatrix_Type
PyObject *PycairoMatrix_FromMatrix(const cairo_matrix_t *matrix)
参数:
  • matrix (cairo_matrix_t) -- 要‘包装’成一个Python对象的cairo_matrixt。Cairo_matrixt值被复制。 [transfer none]

返回:

失败时为新引用或NULL,并设置异常 [transfer full]

从cairo_Matrix_t创建新的PycairoMatrix

开罗之路

typedef PyObject PycairoPath
cairo_path_t *PycairoPath.path
typedef PyTypeObject *PycairoPath_Type
PyObject *PycairoPath_FromPath(cairo_path_t *path)
参数:
  • path (cairo_path_t) -- 将cairo_Path_t‘包装’到一个Python对象中。如果PycairoPath创建失败,或者如果路径处于错误状态,则取消引用路径。 [transfer full]

返回:

失败时为新引用或NULL,并设置异常 [transfer full]

从cairo_path_t创建新的PycairoPath

开罗模式

typedef PyObject PycairoPattern
cairo_pattern_t *PycairoPattern.pattern
typedef PyTypeObject *PycairoPattern_Type
typedef PycairoPattern PycairoSolidPattern
typedef PyTypeObject *PycairoSolidPattern_Type
typedef PycairoPattern PycairoSurfacePattern
typedef PyTypeObject *PycairoSurfacePattern_Type
typedef PycairoPattern PycairoGradient
typedef PyTypeObject *PycairoGradient_Type
typedef PycairoGradient PycairoLinearGradient
typedef PyTypeObject *PycairoLinearGradient_Type
typedef PycairoGradient PycairoRadialGradient
typedef PyTypeObject *PycairoRadialGradient_Type
PyObject *PycairoPattern_FromPattern(cairo_pattern_t *pattern, PyObject *base)
参数:
  • pattern (cairo_pattern_t) -- 将cairo_Patterm_t‘包装’到一个Python对象中。如果PycairoPattern创建失败,或者如果模式具有错误状态,则不会引用它。 [transfer full]

  • base (PyObject) -- 用于创建图案的基对象,或为空。引用它是为了在使用cairo_Pattern_t时使其保持活动状态。 [transfer none]

返回:

失败时为新引用或NULL,并设置异常 [transfer full]

从cairo_Pattern_t创建新的PycairoSolidPattern、PycairoSurfacePattern、PycairoLinearGRadient或PycairoRaial GRadient。

开罗地区

typedef PyObject PycairoRegion
cairo_region_t *PycairoRegion.region
typedef PyTypeObject *PycairoRegion_Type
PyObject *PycairoRegion_FromRegion(cairo_region_t *region)
参数:
  • region (cairo_region_t) -- 将cairo_Region_t‘包装’到一个Python对象中。如果创建PycairoRegion失败,或者如果Region处于错误状态,则不引用Region。

返回:

失败时为新引用或NULL,并设置异常 [transfer full]

从cairo_Region_t创建新的PycairoRegion

开罗RecangleInt

typedef PyObject PycairoRectangleInt
cairo_rectangle_int_t *PycairoRectangleInt.rectangle_int
typedef PyTypeObject *PycairoRectangleInt_Type
PyObject *PycairoRectangleInt_FromRectangleInt(const cairo_rectangle_int_t *rectangle_int)
参数:
  • rectangle_int (cairo_rectangle_int_t) -- 一个cairo_rectangelint_t要‘包装’成一个Python对象。如果创建PycairoRecangleInt失败,则取消引用rectangleint。 [transfer none]

返回:

失败时为新引用或NULL,并设置异常 [transfer full]

从cairo_rectangleint_t创建新的PycairoRecangleInt

缩放字体

typedef PyObject PycairoScaledFont
cairo_scaled_font_t *PycairoScaledFont.scaled_font
typedef PyTypeObject *PycairoScaledFont_Type
PyObject *PycairoScaledFont_FromScaledFont(cairo_scaled_font_t *scaled_font)
参数:
  • scaled_font (cairo_scaled_font_t) -- 要‘包装’到一个Python对象中的cairo_scaled_font_t。如果创建PycairoScaledFont失败,则取消引用它 [transfer full]

返回:

失败时为新引用或NULL,并设置异常 [transfer full]

从cairo_scaled_font_t创建新的PycairoScaledFont

开罗地面

typedef PyObject PycairoSurface
cairo_surface_t *PycairoSurface.surface
typedef PyTypeObject *PycairoSurface_Type
typedef PycairoSurface PycairoImageSurface
typedef PyTypeObject *PycairoImageSurface_Type
typedef PycairoSurface PycairoPDFSurface
typedef PyTypeObject *PycairoPDFSurface_Type
typedef PycairoSurface PycairoPSSurface
typedef PyTypeObject *PycairoPSSurface_Type
typedef PycairoSurface PycairoRecordingSurface
typedef PyTypeObject *PycairoRecordingSurface_Type
typedef PycairoSurface PycairoSVGSurface
typedef PyTypeObject *PycairoSVGSurface_Type
typedef PycairoSurface PycairoWin32Surface
typedef PyTypeObject *PycairoWin32Surface_Type
typedef PycairoSurface PycairoXCBSurface
typedef PyTypeObject *PycairoXCBSurface_Type
typedef PycairoSurface PycairoXlibSurface
typedef PyTypeObject *PycairoXlibSurface_Type
PyObject *PycairoSurface_FromSurface(cairo_surface_t *surface, PyObject *base)
参数:
  • surface (cairo_surface_t) -- 将cairo_Surface_t‘包装’到一个Python对象中。如果PycairoSurface创建失败,或者cairo_Surface_t具有错误状态,则不会引用它。 [transfer full]

  • base (PyObject) -- 用于创建曲面的基础对象,或为空。引用它是为了在使用cairo_Surface_t时使其保持活动状态。 [transfer none]

返回:

失败时为新引用或NULL,并设置异常 [transfer full]

从cairo_Surface_t创建新的PycairoImageSurface、PycairoPDFSurface、PycairoPSSurface、PycairoRecordingSurface、PycairoSVGSurface、PycairoWin32Surface、PycairoWin32PrintingSurface、PycairoXCBSurface或PycairoXlibSurface。

开罗类型

此处仅列出这些内容,以便在文档中参考。

有关详细信息,请参阅https://www.cairographics.org/manual/。

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

CPython类型

type PyObject
type PyTypeObject