summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Chaplin <stevech1097@yahoo.com.au>2009-08-24 23:13:32 +0800
committerSteve Chaplin <stevech1097@yahoo.com.au>2009-08-24 23:13:32 +0800
commit8827abf99723d30faf03c8813c9f178bb7c6dc74 (patch)
tree1030430069ddae3705767bcbf9246c4dea01348e
parent9d9ad8f01001df91a131cc811cf733409c813829 (diff)
downloadpy2cairo-8827abf99723d30faf03c8813c9f178bb7c6dc74.tar.gz
Reformat C code to 2-space indents.
-rw-r--r--doc/reference/surfaces.rst4
-rw-r--r--src/cairomodule.c633
-rw-r--r--src/pycairo-context.c2043
-rw-r--r--src/pycairo-font.c854
-rw-r--r--src/pycairo-matrix.c405
-rw-r--r--src/pycairo-path.c460
-rw-r--r--src/pycairo-pattern.c870
-rw-r--r--src/pycairo-private.h104
-rw-r--r--src/pycairo-surface.c1780
-rw-r--r--src/pycairo.h114
10 files changed, 3524 insertions, 3743 deletions
diff --git a/doc/reference/surfaces.rst b/doc/reference/surfaces.rst
index f1779a4..b8cc399 100644
--- a/doc/reference/surfaces.rst
+++ b/doc/reference/surfaces.rst
@@ -383,7 +383,7 @@ is a multi-page vector surface backend.
.. class:: PSSurface(fobj, width_in_points, height_in_points)
:param fobj: a filename or writable file object. None may be used to specify no output. This will generate a *PSSurface* that may be queried and used as a source, without generating a temporary file.
- :type fobj: str, file or file-like object
+ :type fobj: None, str, file or file-like object
:param width_in_points: width of the surface, in points
(1 point == 1/72.0 inch)
:type width_in_points: float
@@ -586,7 +586,7 @@ multi-page vector surface backend
.. class:: SVGSurface(fobj, width_in_points, height_in_points)
:param fobj: a filename or writable file object. None may be used to specify no output. This will generate a *SVGSurface* that may be queried and used as a source, without generating a temporary file.
- :type fobj: str, file or file-like object
+ :type fobj: None, str, file or file-like object
:param width_in_points: width of the surface, in points (1 point == 1/72.0 inch)
:type width_in_points: float
:param height_in_points: height of the surface, in points (1 point == 1/72.0 inch)
diff --git a/src/cairomodule.c b/src/cairomodule.c
index d328985..3d1daca 100644
--- a/src/cairomodule.c
+++ b/src/cairomodule.c
@@ -1,4 +1,4 @@
-/* -*- mode: C; c-basic-offset: 4 -*-
+/* -*- mode: C; c-basic-offset: 2 -*-
*
* Pycairo - Python bindings for cairo
*
@@ -51,448 +51,453 @@ static char pycairo_version_string[] = "1.8.7";
PyObject *CairoError = NULL;
int
-Pycairo_Check_Status (cairo_status_t status)
-{
- if (PyErr_Occurred() != NULL)
- return 1;
+Pycairo_Check_Status (cairo_status_t status) {
+ if (PyErr_Occurred() != NULL)
+ return 1;
- switch (status) {
- case CAIRO_STATUS_SUCCESS:
- return 0;
+ switch (status) {
+ case CAIRO_STATUS_SUCCESS:
+ return 0;
/* if appropriate - translate the status string into Python,
* else - use cairo_status_to_string()
*/
- case CAIRO_STATUS_NO_MEMORY:
- PyErr_NoMemory();
- break;
- case CAIRO_STATUS_READ_ERROR:
- case CAIRO_STATUS_WRITE_ERROR:
- PyErr_SetString(PyExc_IOError, cairo_status_to_string (status));
- break;
- case CAIRO_STATUS_INVALID_RESTORE:
- PyErr_SetString(CairoError, "Context.restore without matching "
- "Context.save");
- break;
- case CAIRO_STATUS_INVALID_POP_GROUP:
- PyErr_SetString(CairoError, "Context.pop_group without matching "
- "Context.push_group");
- break;
- default:
- PyErr_SetString(CairoError, cairo_status_to_string (status));
- }
- return 1;
+ case CAIRO_STATUS_NO_MEMORY:
+ PyErr_NoMemory();
+ break;
+ case CAIRO_STATUS_READ_ERROR:
+ case CAIRO_STATUS_WRITE_ERROR:
+ PyErr_SetString(PyExc_IOError, cairo_status_to_string (status));
+ break;
+ case CAIRO_STATUS_INVALID_RESTORE:
+ PyErr_SetString(CairoError, "Context.restore without matching "
+ "Context.save");
+ break;
+ case CAIRO_STATUS_INVALID_POP_GROUP:
+ PyErr_SetString(CairoError, "Context.pop_group without matching "
+ "Context.push_group");
+ break;
+ default:
+ PyErr_SetString(CairoError, cairo_status_to_string (status));
+ }
+ return 1;
}
/* C API. Clients get at this via Pycairo_IMPORT, defined in pycairo.h.
*/
static Pycairo_CAPI_t CAPI = {
- &PycairoContext_Type, PycairoContext_FromContext,
+ &PycairoContext_Type,
+ PycairoContext_FromContext,
+
+ &PycairoFontFace_Type,
+ &PycairoToyFontFace_Type,
+ PycairoFontFace_FromFontFace,
- &PycairoFontFace_Type,
- &PycairoToyFontFace_Type, PycairoFontFace_FromFontFace,
+ &PycairoFontOptions_Type,
+ PycairoFontOptions_FromFontOptions,
- &PycairoFontOptions_Type, PycairoFontOptions_FromFontOptions,
- &PycairoMatrix_Type, PycairoMatrix_FromMatrix,
- &PycairoPath_Type, PycairoPath_FromPath,
+ &PycairoMatrix_Type,
+ PycairoMatrix_FromMatrix,
- &PycairoPattern_Type,
- &PycairoSolidPattern_Type,
- &PycairoSurfacePattern_Type,
- &PycairoGradient_Type,
- &PycairoLinearGradient_Type,
- &PycairoRadialGradient_Type,
- PycairoPattern_FromPattern,
+ &PycairoPath_Type,
+ PycairoPath_FromPath,
- &PycairoScaledFont_Type, PycairoScaledFont_FromScaledFont,
+ &PycairoPattern_Type,
+ &PycairoSolidPattern_Type,
+ &PycairoSurfacePattern_Type,
+ &PycairoGradient_Type,
+ &PycairoLinearGradient_Type,
+ &PycairoRadialGradient_Type,
+ PycairoPattern_FromPattern,
- &PycairoSurface_Type,
+ &PycairoScaledFont_Type,
+ PycairoScaledFont_FromScaledFont,
+
+ &PycairoSurface_Type,
#ifdef CAIRO_HAS_IMAGE_SURFACE
- &PycairoImageSurface_Type,
+ &PycairoImageSurface_Type,
#else
- 0,
+ 0,
#endif
#ifdef CAIRO_HAS_PDF_SURFACE
- &PycairoPDFSurface_Type,
+ &PycairoPDFSurface_Type,
#else
- 0,
+ 0,
#endif
#ifdef CAIRO_HAS_PS_SURFACE
- &PycairoPSSurface_Type,
+ &PycairoPSSurface_Type,
#else
- 0,
+ 0,
#endif
#ifdef CAIRO_HAS_SVG_SURFACE
- &PycairoSVGSurface_Type,
+ &PycairoSVGSurface_Type,
#else
- 0,
+ 0,
#endif
#ifdef CAIRO_HAS_WIN32_SURFACE
- &PycairoWin32Surface_Type,
+ &PycairoWin32Surface_Type,
#else
- 0,
+ 0,
#endif
#ifdef CAIRO_HAS_XLIB_SURFACE
- &PycairoXlibSurface_Type,
+ &PycairoXlibSurface_Type,
#else
- 0,
+ 0,
#endif
- PycairoSurface_FromSurface,
+ PycairoSurface_FromSurface,
- Pycairo_Check_Status,
+ Pycairo_Check_Status,
};
static PyObject *
-pycairo_cairo_version (PyObject *self)
-{
- return PyInt_FromLong (cairo_version());
+pycairo_cairo_version (PyObject *self) {
+ return PyInt_FromLong (cairo_version());
}
static PyObject *
-pycairo_cairo_version_string (PyObject *self)
-{
- return PyString_FromString (cairo_version_string());
+pycairo_cairo_version_string (PyObject *self) {
+ return PyString_FromString (cairo_version_string());
}
static PyMethodDef cairo_functions[] = {
- {"cairo_version", (PyCFunction)pycairo_cairo_version, METH_NOARGS},
- {"cairo_version_string", (PyCFunction)pycairo_cairo_version_string,
- METH_NOARGS},
- {NULL, NULL, 0, NULL},
+ {"cairo_version", (PyCFunction)pycairo_cairo_version, METH_NOARGS},
+ {"cairo_version_string", (PyCFunction)pycairo_cairo_version_string,
+ METH_NOARGS},
+ {NULL, NULL, 0, NULL},
};
DL_EXPORT(void)
init_cairo(void)
{
- PyObject *m;
-
- /* initialise 'tp_base' here to work round problem with MinGW compiler */
- PycairoContext_Type.tp_base = &PyBaseObject_Type;
- if (PyType_Ready(&PycairoContext_Type) < 0)
- return;
- PycairoFontFace_Type.tp_base = &PyBaseObject_Type;
- if (PyType_Ready(&PycairoFontFace_Type) < 0)
- return;
- PycairoToyFontFace_Type.tp_base = &PycairoFontFace_Type;
- if (PyType_Ready(&PycairoToyFontFace_Type) < 0)
- return;
- PycairoFontOptions_Type.tp_base = &PyBaseObject_Type;
- if (PyType_Ready(&PycairoFontOptions_Type) < 0)
- return;
- PycairoMatrix_Type.tp_base = &PyBaseObject_Type;
- if (PyType_Ready(&PycairoMatrix_Type) < 0)
- return;
- PycairoPath_Type.tp_base = &PyBaseObject_Type;
- if (PyType_Ready(&PycairoPath_Type) < 0)
- return;
- PycairoPathiter_Type.tp_iter=&PyObject_SelfIter;
-
- PycairoPattern_Type.tp_base = &PyBaseObject_Type;
- if (PyType_Ready(&PycairoPattern_Type) < 0)
- return;
- PycairoSolidPattern_Type.tp_base = &PycairoPattern_Type;
- if (PyType_Ready(&PycairoSolidPattern_Type) < 0)
- return;
- PycairoSurfacePattern_Type.tp_base = &PycairoPattern_Type;
- if (PyType_Ready(&PycairoSurfacePattern_Type) < 0)
- return;
- PycairoGradient_Type.tp_base = &PycairoPattern_Type;
- if (PyType_Ready(&PycairoGradient_Type) < 0)
- return;
- PycairoLinearGradient_Type.tp_base = &PycairoGradient_Type;
- if (PyType_Ready(&PycairoLinearGradient_Type) < 0)
- return;
- PycairoRadialGradient_Type.tp_base = &PycairoGradient_Type;
- if (PyType_Ready(&PycairoRadialGradient_Type) < 0)
- return;
-
- PycairoScaledFont_Type.tp_base = &PyBaseObject_Type;
- if (PyType_Ready(&PycairoScaledFont_Type) < 0)
- return;
-
- PycairoSurface_Type.tp_base = &PyBaseObject_Type;
- if (PyType_Ready(&PycairoSurface_Type) < 0)
- return;
+ PyObject *m;
+
+ /* initialise 'tp_base' here to work round problem with MinGW compiler */
+ PycairoContext_Type.tp_base = &PyBaseObject_Type;
+ if (PyType_Ready(&PycairoContext_Type) < 0)
+ return;
+ PycairoFontFace_Type.tp_base = &PyBaseObject_Type;
+ if (PyType_Ready(&PycairoFontFace_Type) < 0)
+ return;
+ PycairoToyFontFace_Type.tp_base = &PycairoFontFace_Type;
+ if (PyType_Ready(&PycairoToyFontFace_Type) < 0)
+ return;
+ PycairoFontOptions_Type.tp_base = &PyBaseObject_Type;
+ if (PyType_Ready(&PycairoFontOptions_Type) < 0)
+ return;
+ PycairoMatrix_Type.tp_base = &PyBaseObject_Type;
+ if (PyType_Ready(&PycairoMatrix_Type) < 0)
+ return;
+ PycairoPath_Type.tp_base = &PyBaseObject_Type;
+ if (PyType_Ready(&PycairoPath_Type) < 0)
+ return;
+ PycairoPathiter_Type.tp_iter=&PyObject_SelfIter;
+
+ PycairoPattern_Type.tp_base = &PyBaseObject_Type;
+ if (PyType_Ready(&PycairoPattern_Type) < 0)
+ return;
+ PycairoSolidPattern_Type.tp_base = &PycairoPattern_Type;
+ if (PyType_Ready(&PycairoSolidPattern_Type) < 0)
+ return;
+ PycairoSurfacePattern_Type.tp_base = &PycairoPattern_Type;
+ if (PyType_Ready(&PycairoSurfacePattern_Type) < 0)
+ return;
+ PycairoGradient_Type.tp_base = &PycairoPattern_Type;
+ if (PyType_Ready(&PycairoGradient_Type) < 0)
+ return;
+ PycairoLinearGradient_Type.tp_base = &PycairoGradient_Type;
+ if (PyType_Ready(&PycairoLinearGradient_Type) < 0)
+ return;
+ PycairoRadialGradient_Type.tp_base = &PycairoGradient_Type;
+ if (PyType_Ready(&PycairoRadialGradient_Type) < 0)
+ return;
+
+ PycairoScaledFont_Type.tp_base = &PyBaseObject_Type;
+ if (PyType_Ready(&PycairoScaledFont_Type) < 0)
+ return;
+
+ PycairoSurface_Type.tp_base = &PyBaseObject_Type;
+ if (PyType_Ready(&PycairoSurface_Type) < 0)
+ return;
#ifdef CAIRO_HAS_IMAGE_SURFACE
- PycairoImageSurface_Type.tp_base = &PycairoSurface_Type;
- if (PyType_Ready(&PycairoImageSurface_Type) < 0)
- return;
+ PycairoImageSurface_Type.tp_base = &PycairoSurface_Type;
+ if (PyType_Ready(&PycairoImageSurface_Type) < 0)
+ return;
#endif
#ifdef CAIRO_HAS_PDF_SURFACE
- PycairoPDFSurface_Type.tp_base = &PycairoSurface_Type;
- if (PyType_Ready(&PycairoPDFSurface_Type) < 0)
- return;
+ PycairoPDFSurface_Type.tp_base = &PycairoSurface_Type;
+ if (PyType_Ready(&PycairoPDFSurface_Type) < 0)
+ return;
#endif
#ifdef CAIRO_HAS_PS_SURFACE
- PycairoPSSurface_Type.tp_base = &PycairoSurface_Type;
- if (PyType_Ready(&PycairoPSSurface_Type) < 0)
- return;
+ PycairoPSSurface_Type.tp_base = &PycairoSurface_Type;
+ if (PyType_Ready(&PycairoPSSurface_Type) < 0)
+ return;
#endif
#ifdef CAIRO_HAS_SVG_SURFACE
- PycairoSVGSurface_Type.tp_base = &PycairoSurface_Type;
- if (PyType_Ready(&PycairoSVGSurface_Type) < 0)
- return;
+ PycairoSVGSurface_Type.tp_base = &PycairoSurface_Type;
+ if (PyType_Ready(&PycairoSVGSurface_Type) < 0)
+ return;
#endif
#ifdef CAIRO_HAS_WIN32_SURFACE
- PycairoWin32Surface_Type.tp_base = &PycairoSurface_Type;
- if (PyType_Ready(&PycairoWin32Surface_Type) < 0)
- return;
+ PycairoWin32Surface_Type.tp_base = &PycairoSurface_Type;
+ if (PyType_Ready(&PycairoWin32Surface_Type) < 0)
+ return;
#endif
#ifdef CAIRO_HAS_XLIB_SURFACE
- PycairoXlibSurface_Type.tp_base = &PycairoSurface_Type;
- if (PyType_Ready(&PycairoXlibSurface_Type) < 0)
- return;
-#endif
-
- m = Py_InitModule("cairo._cairo", cairo_functions);
-
- PyModule_AddStringConstant(m, "version", pycairo_version_string);
- PyModule_AddObject(m, "version_info",
- Py_BuildValue("(iii)", VERSION_MAJOR, VERSION_MINOR,
- VERSION_MICRO));
-
- Py_INCREF(&PycairoContext_Type);
- PyModule_AddObject(m, "Context", (PyObject *)&PycairoContext_Type);
- Py_INCREF(&PycairoFontFace_Type);
- PyModule_AddObject(m, "FontFace",(PyObject *)&PycairoFontFace_Type);
- Py_INCREF(&PycairoToyFontFace_Type);
- PyModule_AddObject(m, "ToyFontFace",(PyObject *)&PycairoToyFontFace_Type);
- Py_INCREF(&PycairoFontOptions_Type);
- PyModule_AddObject(m, "FontOptions",(PyObject *)&PycairoFontOptions_Type);
- Py_INCREF(&PycairoMatrix_Type);
- PyModule_AddObject(m, "Matrix", (PyObject *)&PycairoMatrix_Type);
- Py_INCREF(&PycairoPath_Type);
- /* Don't add Path object since it is not accessed directly as 'cairo.Path'
- * PyModule_AddObject(m, "Path", (PyObject *)&PycairoPath_Type);
- */
- Py_INCREF(&PycairoPattern_Type);
- PyModule_AddObject(m, "Pattern", (PyObject *)&PycairoPattern_Type);
- Py_INCREF(&PycairoSolidPattern_Type);
- PyModule_AddObject(m, "SolidPattern",
- (PyObject *)&PycairoSolidPattern_Type);
- Py_INCREF(&PycairoSurfacePattern_Type);
- PyModule_AddObject(m, "SurfacePattern",
- (PyObject *)&PycairoSurfacePattern_Type);
- Py_INCREF(&PycairoGradient_Type);
- PyModule_AddObject(m, "Gradient", (PyObject *)&PycairoGradient_Type);
- Py_INCREF(&PycairoLinearGradient_Type);
- PyModule_AddObject(m, "LinearGradient",
- (PyObject *)&PycairoLinearGradient_Type);
- Py_INCREF(&PycairoRadialGradient_Type);
- PyModule_AddObject(m, "RadialGradient",
- (PyObject *)&PycairoRadialGradient_Type);
-
- Py_INCREF(&PycairoScaledFont_Type);
- PyModule_AddObject(m, "ScaledFont", (PyObject *)&PycairoScaledFont_Type);
-
- Py_INCREF(&PycairoSurface_Type);
- PyModule_AddObject(m, "Surface", (PyObject *)&PycairoSurface_Type);
+ PycairoXlibSurface_Type.tp_base = &PycairoSurface_Type;
+ if (PyType_Ready(&PycairoXlibSurface_Type) < 0)
+ return;
+#endif
+
+ m = Py_InitModule("cairo._cairo", cairo_functions);
+
+ PyModule_AddStringConstant(m, "version", pycairo_version_string);
+ PyModule_AddObject(m, "version_info",
+ Py_BuildValue("(iii)", VERSION_MAJOR, VERSION_MINOR,
+ VERSION_MICRO));
+
+ Py_INCREF(&PycairoContext_Type);
+ PyModule_AddObject(m, "Context", (PyObject *)&PycairoContext_Type);
+ Py_INCREF(&PycairoFontFace_Type);
+ PyModule_AddObject(m, "FontFace",(PyObject *)&PycairoFontFace_Type);
+ Py_INCREF(&PycairoToyFontFace_Type);
+ PyModule_AddObject(m, "ToyFontFace",(PyObject *)&PycairoToyFontFace_Type);
+ Py_INCREF(&PycairoFontOptions_Type);
+ PyModule_AddObject(m, "FontOptions",(PyObject *)&PycairoFontOptions_Type);
+ Py_INCREF(&PycairoMatrix_Type);
+ PyModule_AddObject(m, "Matrix", (PyObject *)&PycairoMatrix_Type);
+ Py_INCREF(&PycairoPath_Type);
+ /* Don't add Path object since it is not accessed directly as 'cairo.Path'
+ * PyModule_AddObject(m, "Path", (PyObject *)&PycairoPath_Type);
+ */
+ Py_INCREF(&PycairoPattern_Type);
+ PyModule_AddObject(m, "Pattern", (PyObject *)&PycairoPattern_Type);
+ Py_INCREF(&PycairoSolidPattern_Type);
+ PyModule_AddObject(m, "SolidPattern",
+ (PyObject *)&PycairoSolidPattern_Type);
+ Py_INCREF(&PycairoSurfacePattern_Type);
+ PyModule_AddObject(m, "SurfacePattern",
+ (PyObject *)&PycairoSurfacePattern_Type);
+ Py_INCREF(&PycairoGradient_Type);
+ PyModule_AddObject(m, "Gradient", (PyObject *)&PycairoGradient_Type);
+ Py_INCREF(&PycairoLinearGradient_Type);
+ PyModule_AddObject(m, "LinearGradient",
+ (PyObject *)&PycairoLinearGradient_Type);
+ Py_INCREF(&PycairoRadialGradient_Type);
+ PyModule_AddObject(m, "RadialGradient",
+ (PyObject *)&PycairoRadialGradient_Type);
+
+ Py_INCREF(&PycairoScaledFont_Type);
+ PyModule_AddObject(m, "ScaledFont", (PyObject *)&PycairoScaledFont_Type);
+
+ Py_INCREF(&PycairoSurface_Type);
+ PyModule_AddObject(m, "Surface", (PyObject *)&PycairoSurface_Type);
#ifdef CAIRO_HAS_IMAGE_SURFACE
- Py_INCREF(&PycairoImageSurface_Type);
- PyModule_AddObject(m, "ImageSurface",
- (PyObject *)&PycairoImageSurface_Type);
+ Py_INCREF(&PycairoImageSurface_Type);
+ PyModule_AddObject(m, "ImageSurface",
+ (PyObject *)&PycairoImageSurface_Type);
#endif
#ifdef CAIRO_HAS_PDF_SURFACE
- Py_INCREF(&PycairoPDFSurface_Type);
- PyModule_AddObject(m, "PDFSurface", (PyObject *)&PycairoPDFSurface_Type);
+ Py_INCREF(&PycairoPDFSurface_Type);
+ PyModule_AddObject(m, "PDFSurface", (PyObject *)&PycairoPDFSurface_Type);
#endif
#ifdef CAIRO_HAS_PS_SURFACE
- Py_INCREF(&PycairoPSSurface_Type);
- PyModule_AddObject(m, "PSSurface", (PyObject *)&PycairoPSSurface_Type);
+ Py_INCREF(&PycairoPSSurface_Type);
+ PyModule_AddObject(m, "PSSurface", (PyObject *)&PycairoPSSurface_Type);
#endif
#ifdef CAIRO_HAS_SVG_SURFACE
- Py_INCREF(&PycairoSVGSurface_Type);
- PyModule_AddObject(m, "SVGSurface", (PyObject *)&PycairoSVGSurface_Type);
+ Py_INCREF(&PycairoSVGSurface_Type);
+ PyModule_AddObject(m, "SVGSurface", (PyObject *)&PycairoSVGSurface_Type);
#endif
#ifdef CAIRO_HAS_WIN32_SURFACE
- Py_INCREF(&PycairoWin32Surface_Type);
- PyModule_AddObject(m, "Win32Surface",
- (PyObject *)&PycairoWin32Surface_Type);
+ Py_INCREF(&PycairoWin32Surface_Type);
+ PyModule_AddObject(m, "Win32Surface",
+ (PyObject *)&PycairoWin32Surface_Type);
#endif
#ifdef CAIRO_HAS_XLIB_SURFACE
- Py_INCREF(&PycairoXlibSurface_Type);
- PyModule_AddObject(m, "XlibSurface",
- (PyObject *)&PycairoXlibSurface_Type);
+ Py_INCREF(&PycairoXlibSurface_Type);
+ PyModule_AddObject(m, "XlibSurface",
+ (PyObject *)&PycairoXlibSurface_Type);
#endif
- PyModule_AddObject(m, "CAPI", PyCObject_FromVoidPtr(&CAPI, NULL));
+ PyModule_AddObject(m, "CAPI", PyCObject_FromVoidPtr(&CAPI, NULL));
- /* Add 'cairo.Error' to the module */
- if (CairoError == NULL) {
- CairoError = PyErr_NewException("cairo.Error", NULL, NULL);
- if (CairoError == NULL)
- return;
- }
- Py_INCREF(CairoError);
- if (PyModule_AddObject(m, "Error", CairoError) < 0)
- return;
+ /* Add 'cairo.Error' to the module */
+ if (CairoError == NULL) {
+ CairoError = PyErr_NewException("cairo.Error", NULL, NULL);
+ if (CairoError == NULL)
+ return;
+ }
+ Py_INCREF(CairoError);
+ if (PyModule_AddObject(m, "Error", CairoError) < 0)
+ return;
/* constants */
#if CAIRO_HAS_ATSUI_FONT
- PyModule_AddIntConstant(m, "HAS_ATSUI_FONT", 1);
+ PyModule_AddIntConstant(m, "HAS_ATSUI_FONT", 1);
#else
- PyModule_AddIntConstant(m, "HAS_ATSUI_FONT", 0);
+ PyModule_AddIntConstant(m, "HAS_ATSUI_FONT", 0);
#endif
#if CAIRO_HAS_FT_FONT
- PyModule_AddIntConstant(m, "HAS_FT_FONT", 1);
+ PyModule_AddIntConstant(m, "HAS_FT_FONT", 1);
#else
- PyModule_AddIntConstant(m, "HAS_FT_FONT", 0);
+ PyModule_AddIntConstant(m, "HAS_FT_FONT", 0);
#endif
#if CAIRO_HAS_GLITZ_SURFACE
- PyModule_AddIntConstant(m, "HAS_GLITZ_SURFACE", 1);
+ PyModule_AddIntConstant(m, "HAS_GLITZ_SURFACE", 1);
#else
- PyModule_AddIntConstant(m, "HAS_GLITZ_SURFACE", 0);
+ PyModule_AddIntConstant(m, "HAS_GLITZ_SURFACE", 0);
#endif
#if CAIRO_HAS_IMAGE_SURFACE
- PyModule_AddIntConstant(m, "HAS_IMAGE_SURFACE", 1);
+ PyModule_AddIntConstant(m, "HAS_IMAGE_SURFACE", 1);
#else
- PyModule_AddIntConstant(m, "HAS_IMAGE_SURFACE", 0);
+ PyModule_AddIntConstant(m, "HAS_IMAGE_SURFACE", 0);
#endif
#if CAIRO_HAS_PDF_SURFACE
- PyModule_AddIntConstant(m, "HAS_PDF_SURFACE", 1);
+ PyModule_AddIntConstant(m, "HAS_PDF_SURFACE", 1);
#else
- PyModule_AddIntConstant(m, "HAS_PDF_SURFACE", 0);
+ PyModule_AddIntConstant(m, "HAS_PDF_SURFACE", 0);
#endif
#if CAIRO_HAS_PNG_FUNCTIONS
- PyModule_AddIntConstant(m, "HAS_PNG_FUNCTIONS", 1);
+ PyModule_AddIntConstant(m, "HAS_PNG_FUNCTIONS", 1);
#else
- PyModule_AddIntConstant(m, "HAS_PNG_FUNCTIONS", 0);
+ PyModule_AddIntConstant(m, "HAS_PNG_FUNCTIONS", 0);
#endif
#if CAIRO_HAS_PS_SURFACE
- PyModule_AddIntConstant(m, "HAS_PS_SURFACE", 1);
+ PyModule_AddIntConstant(m, "HAS_PS_SURFACE", 1);
#else
- PyModule_AddIntConstant(m, "HAS_PS_SURFACE", 0);
+ PyModule_AddIntConstant(m, "HAS_PS_SURFACE", 0);
#endif
#if CAIRO_HAS_SVG_SURFACE
- PyModule_AddIntConstant(m, "HAS_SVG_SURFACE", 1);
+ PyModule_AddIntConstant(m, "HAS_SVG_SURFACE", 1);
#else
- PyModule_AddIntConstant(m, "HAS_SVG_SURFACE", 0);
+ PyModule_AddIntConstant(m, "HAS_SVG_SURFACE", 0);
#endif
#if CAIRO_HAS_USER_FONT
- PyModule_AddIntConstant(m, "HAS_USER_FONT", 1);
+ PyModule_AddIntConstant(m, "HAS_USER_FONT", 1);
#else
- PyModule_AddIntConstant(m, "HAS_USER_FONT", 0);
+ PyModule_AddIntConstant(m, "HAS_USER_FONT", 0);
#endif
#if CAIRO_HAS_QUARTZ_SURFACE
- PyModule_AddIntConstant(m, "HAS_QUARTZ_SURFACE", 1);
+ PyModule_AddIntConstant(m, "HAS_QUARTZ_SURFACE", 1);
#else
- PyModule_AddIntConstant(m, "HAS_QUARTZ_SURFACE", 0);
+ PyModule_AddIntConstant(m, "HAS_QUARTZ_SURFACE", 0);
#endif
#if CAIRO_HAS_WIN32_FONT
- PyModule_AddIntConstant(m, "HAS_WIN32_FONT", 1);
+ PyModule_AddIntConstant(m, "HAS_WIN32_FONT", 1);
#else
- PyModule_AddIntConstant(m, "HAS_WIN32_FONT", 0);
+ PyModule_AddIntConstant(m, "HAS_WIN32_FONT", 0);
#endif
#if CAIRO_HAS_WIN32_SURFACE
- PyModule_AddIntConstant(m, "HAS_WIN32_SURFACE", 1);
+ PyModule_AddIntConstant(m, "HAS_WIN32_SURFACE", 1);
#else
- PyModule_AddIntConstant(m, "HAS_WIN32_SURFACE", 0);
+ PyModule_AddIntConstant(m, "HAS_WIN32_SURFACE", 0);
#endif
#if CAIRO_HAS_XCB_SURFACE
- PyModule_AddIntConstant(m, "HAS_XCB_SURFACE", 1);
+ PyModule_AddIntConstant(m, "HAS_XCB_SURFACE", 1);
#else
- PyModule_AddIntConstant(m, "HAS_XCB_SURFACE", 0);
+ PyModule_AddIntConstant(m, "HAS_XCB_SURFACE", 0);
#endif
#if CAIRO_HAS_XLIB_SURFACE
- PyModule_AddIntConstant(m, "HAS_XLIB_SURFACE", 1);
+ PyModule_AddIntConstant(m, "HAS_XLIB_SURFACE", 1);
#else
- PyModule_AddIntConstant(m, "HAS_XLIB_SURFACE", 0);
+ PyModule_AddIntConstant(m, "HAS_XLIB_SURFACE", 0);
#endif
#define CONSTANT(x) PyModule_AddIntConstant(m, #x, CAIRO_##x)
- CONSTANT(ANTIALIAS_DEFAULT);
- CONSTANT(ANTIALIAS_NONE);
- CONSTANT(ANTIALIAS_GRAY);
- CONSTANT(ANTIALIAS_SUBPIXEL);
-
- CONSTANT(CONTENT_COLOR);
- CONSTANT(CONTENT_ALPHA);
- CONSTANT(CONTENT_COLOR_ALPHA);
-
- CONSTANT(EXTEND_NONE);
- CONSTANT(EXTEND_REPEAT);
- CONSTANT(EXTEND_REFLECT);
- CONSTANT(EXTEND_PAD);
-
- CONSTANT(FILL_RULE_WINDING);
- CONSTANT(FILL_RULE_EVEN_ODD);
-
- CONSTANT(FILTER_FAST);
- CONSTANT(FILTER_GOOD);
- CONSTANT(FILTER_BEST);
- CONSTANT(FILTER_NEAREST);
- CONSTANT(FILTER_BILINEAR);
- CONSTANT(FILTER_GAUSSIAN);
-
- CONSTANT(FONT_WEIGHT_NORMAL);
- CONSTANT(FONT_WEIGHT_BOLD);
-
- CONSTANT(FONT_SLANT_NORMAL);
- CONSTANT(FONT_SLANT_ITALIC);
- CONSTANT(FONT_SLANT_OBLIQUE);
-
- CONSTANT(FORMAT_ARGB32);
- CONSTANT(FORMAT_RGB24);
- CONSTANT(FORMAT_A8);
- CONSTANT(FORMAT_A1);
-
- CONSTANT(HINT_METRICS_DEFAULT);
- CONSTANT(HINT_METRICS_OFF);
- CONSTANT(HINT_METRICS_ON);
-
- CONSTANT(HINT_STYLE_DEFAULT);
- CONSTANT(HINT_STYLE_NONE);
- CONSTANT(HINT_STYLE_SLIGHT);
- CONSTANT(HINT_STYLE_MEDIUM);
- CONSTANT(HINT_STYLE_FULL);
-
- CONSTANT(LINE_CAP_BUTT);
- CONSTANT(LINE_CAP_ROUND);
- CONSTANT(LINE_CAP_SQUARE);
-
- CONSTANT(LINE_JOIN_MITER);
- CONSTANT(LINE_JOIN_ROUND);
- CONSTANT(LINE_JOIN_BEVEL);
-
- CONSTANT(OPERATOR_CLEAR);
-
- CONSTANT(OPERATOR_SOURCE);
- CONSTANT(OPERATOR_OVER);
- CONSTANT(OPERATOR_IN);
- CONSTANT(OPERATOR_OUT);
- CONSTANT(OPERATOR_ATOP);
-
- CONSTANT(OPERATOR_DEST);
- CONSTANT(OPERATOR_DEST_OVER);
- CONSTANT(OPERATOR_DEST_IN);
- CONSTANT(OPERATOR_DEST_OUT);
- CONSTANT(OPERATOR_DEST_ATOP);
-
- CONSTANT(OPERATOR_XOR);
- CONSTANT(OPERATOR_ADD);
- CONSTANT(OPERATOR_SATURATE);
-
- CONSTANT(PATH_MOVE_TO);
- CONSTANT(PATH_LINE_TO);
- CONSTANT(PATH_CURVE_TO);
- CONSTANT(PATH_CLOSE_PATH);
+ CONSTANT(ANTIALIAS_DEFAULT);
+ CONSTANT(ANTIALIAS_NONE);
+ CONSTANT(ANTIALIAS_GRAY);
+ CONSTANT(ANTIALIAS_SUBPIXEL);
+
+ CONSTANT(CONTENT_COLOR);
+ CONSTANT(CONTENT_ALPHA);
+ CONSTANT(CONTENT_COLOR_ALPHA);
+
+ CONSTANT(EXTEND_NONE);
+ CONSTANT(EXTEND_REPEAT);
+ CONSTANT(EXTEND_REFLECT);
+ CONSTANT(EXTEND_PAD);
+
+ CONSTANT(FILL_RULE_WINDING);
+ CONSTANT(FILL_RULE_EVEN_ODD);
+
+ CONSTANT(FILTER_FAST);
+ CONSTANT(FILTER_GOOD);
+ CONSTANT(FILTER_BEST);
+ CONSTANT(FILTER_NEAREST);
+ CONSTANT(FILTER_BILINEAR);
+ CONSTANT(FILTER_GAUSSIAN);
+
+ CONSTANT(FONT_WEIGHT_NORMAL);
+ CONSTANT(FONT_WEIGHT_BOLD);
+
+ CONSTANT(FONT_SLANT_NORMAL);
+ CONSTANT(FONT_SLANT_ITALIC);
+ CONSTANT(FONT_SLANT_OBLIQUE);
+
+ CONSTANT(FORMAT_ARGB32);
+ CONSTANT(FORMAT_RGB24);
+ CONSTANT(FORMAT_A8);
+ CONSTANT(FORMAT_A1);
+
+ CONSTANT(HINT_METRICS_DEFAULT);
+ CONSTANT(HINT_METRICS_OFF);
+ CONSTANT(HINT_METRICS_ON);
+
+ CONSTANT(HINT_STYLE_DEFAULT);
+ CONSTANT(HINT_STYLE_NONE);
+ CONSTANT(HINT_STYLE_SLIGHT);
+ CONSTANT(HINT_STYLE_MEDIUM);
+ CONSTANT(HINT_STYLE_FULL);
+
+ CONSTANT(LINE_CAP_BUTT);
+ CONSTANT(LINE_CAP_ROUND);
+ CONSTANT(LINE_CAP_SQUARE);
+
+ CONSTANT(LINE_JOIN_MITER);
+ CONSTANT(LINE_JOIN_ROUND);
+ CONSTANT(LINE_JOIN_BEVEL);
+
+ CONSTANT(OPERATOR_CLEAR);
+
+ CONSTANT(OPERATOR_SOURCE);
+ CONSTANT(OPERATOR_OVER);
+ CONSTANT(OPERATOR_IN);
+ CONSTANT(OPERATOR_OUT);
+ CONSTANT(OPERATOR_ATOP);
+
+ CONSTANT(OPERATOR_DEST);
+ CONSTANT(OPERATOR_DEST_OVER);
+ CONSTANT(OPERATOR_DEST_IN);
+ CONSTANT(OPERATOR_DEST_OUT);
+ CONSTANT(OPERATOR_DEST_ATOP);
+
+ CONSTANT(OPERATOR_XOR);
+ CONSTANT(OPERATOR_ADD);
+ CONSTANT(OPERATOR_SATURATE);
+
+ CONSTANT(PATH_MOVE_TO);
+ CONSTANT(PATH_LINE_TO);
+ CONSTANT(PATH_CURVE_TO);
+ CONSTANT(PATH_CLOSE_PATH);
#ifdef CAIRO_HAS_PS_SURFACE
- CONSTANT(PS_LEVEL_2);
- CONSTANT(PS_LEVEL_3);
+ CONSTANT(PS_LEVEL_2);
+ CONSTANT(PS_LEVEL_3);
#endif
- CONSTANT(SUBPIXEL_ORDER_DEFAULT);
- CONSTANT(SUBPIXEL_ORDER_RGB);
- CONSTANT(SUBPIXEL_ORDER_BGR);
- CONSTANT(SUBPIXEL_ORDER_VRGB);
- CONSTANT(SUBPIXEL_ORDER_VBGR);
+ CONSTANT(SUBPIXEL_ORDER_DEFAULT);
+ CONSTANT(SUBPIXEL_ORDER_RGB);
+ CONSTANT(SUBPIXEL_ORDER_BGR);
+ CONSTANT(SUBPIXEL_ORDER_VRGB);
+ CONSTANT(SUBPIXEL_ORDER_VBGR);
#undef CONSTANT
}
diff --git a/src/pycairo-context.c b/src/pycairo-context.c
index 86f9a96..bbc887a 100644
--- a/src/pycairo-context.c
+++ b/src/pycairo-context.c
@@ -1,4 +1,4 @@
-/* -*- mode: C; c-basic-offset: 4 -*-
+/* -*- mode: C; c-basic-offset: 2 -*-
*
* Pycairo - Python bindings for cairo
*
@@ -50,429 +50,389 @@
* Return value: New reference or NULL on failure
*/
PyObject *
-PycairoContext_FromContext(cairo_t *ctx, PyTypeObject *type, PyObject *base)
-{
- PyObject *o;
+PycairoContext_FromContext(cairo_t *ctx, PyTypeObject *type, PyObject *base) {
+ PyObject *o;
- assert (ctx != NULL);
+ assert (ctx != NULL);
- if (Pycairo_Check_Status (cairo_status (ctx))) {
- cairo_destroy (ctx);
- return NULL;
- }
+ if (Pycairo_Check_Status (cairo_status (ctx))) {
+ cairo_destroy (ctx);
+ return NULL;
+ }
- o = PycairoContext_Type.tp_alloc (type, 0);
- if (o) {
- ((PycairoContext *)o)->ctx = ctx;
- Py_XINCREF(base);
- ((PycairoContext *)o)->base = base;
- } else {
- cairo_destroy (ctx);
- }
- return o;
+ o = PycairoContext_Type.tp_alloc (type, 0);
+ if (o) {
+ ((PycairoContext *)o)->ctx = ctx;
+ Py_XINCREF(base);
+ ((PycairoContext *)o)->base = base;
+ } else {
+ cairo_destroy (ctx);
+ }
+ return o;
}
static void
-pycairo_dealloc(PycairoContext *o)
-{
- if (o->ctx) {
- cairo_destroy(o->ctx);
- o->ctx = NULL;
- }
- Py_CLEAR(o->base);
+pycairo_dealloc(PycairoContext *o) {
+ if (o->ctx) {
+ cairo_destroy(o->ctx);
+ o->ctx = NULL;
+ }
+ Py_CLEAR(o->base);
- o->ob_type->tp_free((PyObject *)o);
+ o->ob_type->tp_free((PyObject *)o);
}
static PyObject *
-pycairo_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PycairoSurface *s;
- if (!PyArg_ParseTuple(args, "O!:Context.__new__",
- &PycairoSurface_Type, &s))
- return NULL;
- return PycairoContext_FromContext (cairo_create (s->surface), type, NULL);
+pycairo_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
+ PycairoSurface *s;
+ if (!PyArg_ParseTuple(args, "O!:Context.__new__",
+ &PycairoSurface_Type, &s))
+ return NULL;
+ return PycairoContext_FromContext (cairo_create (s->surface), type, NULL);
}
static PyObject *
-pycairo_append_path (PycairoContext *o, PyObject *args)
-{
- PycairoPath *p;
+pycairo_append_path (PycairoContext *o, PyObject *args) {
+ PycairoPath *p;
- if (!PyArg_ParseTuple(args, "O!:Context.append_path",
- &PycairoPath_Type, &p))
- return NULL;
+ if (!PyArg_ParseTuple(args, "O!:Context.append_path",
+ &PycairoPath_Type, &p))
+ return NULL;
- Py_BEGIN_ALLOW_THREADS
- cairo_append_path (o->ctx, p->path);
- Py_END_ALLOW_THREADS
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ Py_BEGIN_ALLOW_THREADS;
+ cairo_append_path (o->ctx, p->path);
+ Py_END_ALLOW_THREADS;
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_arc (PycairoContext *o, PyObject *args)
-{
- double xc, yc, radius, angle1, angle2;
+pycairo_arc (PycairoContext *o, PyObject *args) {
+ double xc, yc, radius, angle1, angle2;
- if (!PyArg_ParseTuple (args, "ddddd:Context.arc",
- &xc, &yc, &radius, &angle1, &angle2))
- return NULL;
+ if (!PyArg_ParseTuple (args, "ddddd:Context.arc",
+ &xc, &yc, &radius, &angle1, &angle2))
+ return NULL;
- cairo_arc (o->ctx, xc, yc, radius, angle1, angle2);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_arc (o->ctx, xc, yc, radius, angle1, angle2);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_arc_negative (PycairoContext *o, PyObject *args)
-{
- double xc, yc, radius, angle1, angle2;
+pycairo_arc_negative (PycairoContext *o, PyObject *args) {
+ double xc, yc, radius, angle1, angle2;
- if (!PyArg_ParseTuple (args, "ddddd:Context.arc_negative",
- &xc, &yc, &radius, &angle1, &angle2))
- return NULL;
+ if (!PyArg_ParseTuple (args, "ddddd:Context.arc_negative",
+ &xc, &yc, &radius, &angle1, &angle2))
+ return NULL;
- cairo_arc_negative (o->ctx, xc, yc, radius, angle1, angle2);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_arc_negative (o->ctx, xc, yc, radius, angle1, angle2);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_clip (PycairoContext *o)
-{
- Py_BEGIN_ALLOW_THREADS
- cairo_clip (o->ctx);
- Py_END_ALLOW_THREADS
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+pycairo_clip (PycairoContext *o) {
+ Py_BEGIN_ALLOW_THREADS;
+ cairo_clip (o->ctx);
+ Py_END_ALLOW_THREADS;
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_clip_extents (PycairoContext *o)
-{
- double x1, y1, x2, y2;
- cairo_clip_extents (o->ctx, &x1, &y1, &x2, &y2);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- return Py_BuildValue("(dddd)", x1, y1, x2, y2);
+pycairo_clip_extents (PycairoContext *o) {
+ double x1, y1, x2, y2;
+ cairo_clip_extents (o->ctx, &x1, &y1, &x2, &y2);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ return Py_BuildValue("(dddd)", x1, y1, x2, y2);
}
static PyObject *
-pycairo_clip_preserve (PycairoContext *o)
-{
- Py_BEGIN_ALLOW_THREADS
- cairo_clip_preserve (o->ctx);
- Py_END_ALLOW_THREADS
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+pycairo_clip_preserve (PycairoContext *o) {
+ Py_BEGIN_ALLOW_THREADS;
+ cairo_clip_preserve (o->ctx);
+ Py_END_ALLOW_THREADS;
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_close_path (PycairoContext *o)
-{
- Py_BEGIN_ALLOW_THREADS
- cairo_close_path (o->ctx);
- Py_END_ALLOW_THREADS
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+pycairo_close_path (PycairoContext *o) {
+ Py_BEGIN_ALLOW_THREADS;
+ cairo_close_path (o->ctx);
+ Py_END_ALLOW_THREADS;
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_copy_clip_rectangle_list (PycairoContext *o)
-{
- int i;
- PyObject *rv = NULL;
- cairo_rectangle_t *r;
- cairo_rectangle_list_t *rlist = cairo_copy_clip_rectangle_list (o->ctx);
- if (rlist->status != CAIRO_STATUS_SUCCESS) {
- Pycairo_Check_Status (rlist->status);
- goto exit;
- }
+pycairo_copy_clip_rectangle_list (PycairoContext *o) {
+ int i;
+ PyObject *rv = NULL;
+ cairo_rectangle_t *r;
+ cairo_rectangle_list_t *rlist = cairo_copy_clip_rectangle_list (o->ctx);
+ if (rlist->status != CAIRO_STATUS_SUCCESS) {
+ Pycairo_Check_Status (rlist->status);
+ goto exit;
+ }
+
+ rv = PyTuple_New(rlist->num_rectangles);
+ if (rv == NULL)
+ goto exit;
- rv = PyTuple_New(rlist->num_rectangles);
- if (rv == NULL)
- goto exit;
-
- for (i = 0, r = rlist->rectangles; i < rlist->num_rectangles; i++, r++) {
- PyObject *py_rect = Py_BuildValue("(dddd)", r->x, r->y,
- r->width, r->height);
- if (py_rect == NULL) {
- Py_CLEAR(rv);
- goto exit;
- }
- PyTuple_SET_ITEM (rv, i, py_rect);
+ for (i = 0, r = rlist->rectangles; i < rlist->num_rectangles; i++, r++) {
+ PyObject *py_rect = Py_BuildValue("(dddd)", r->x, r->y,
+ r->width, r->height);
+ if (py_rect == NULL) {
+ Py_CLEAR(rv);
+ goto exit;
}
+ PyTuple_SET_ITEM (rv, i, py_rect);
+ }
exit:
- cairo_rectangle_list_destroy(rlist);
- return rv;
+ cairo_rectangle_list_destroy(rlist);
+ return rv;
}
static PyObject *
-pycairo_copy_page (PycairoContext *o)
-{
- Py_BEGIN_ALLOW_THREADS
- cairo_copy_page (o->ctx);
- Py_END_ALLOW_THREADS
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+pycairo_copy_page (PycairoContext *o) {
+ Py_BEGIN_ALLOW_THREADS;
+ cairo_copy_page (o->ctx);
+ Py_END_ALLOW_THREADS;
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_copy_path (PycairoContext *o)
-{
- cairo_path_t *cp;
- Py_BEGIN_ALLOW_THREADS
- cp = cairo_copy_path (o->ctx);
- Py_END_ALLOW_THREADS
- return PycairoPath_FromPath (cp);
+pycairo_copy_path (PycairoContext *o) {
+ cairo_path_t *cp;
+ Py_BEGIN_ALLOW_THREADS;
+ cp = cairo_copy_path (o->ctx);
+ Py_END_ALLOW_THREADS;
+ return PycairoPath_FromPath (cp);
}
static PyObject *
-pycairo_copy_path_flat (PycairoContext *o)
-{
- cairo_path_t *cp;
- Py_BEGIN_ALLOW_THREADS
- cp = cairo_copy_path_flat (o->ctx);
- Py_END_ALLOW_THREADS
- return PycairoPath_FromPath (cp);
+pycairo_copy_path_flat (PycairoContext *o) {
+ cairo_path_t *cp;
+ Py_BEGIN_ALLOW_THREADS;
+ cp = cairo_copy_path_flat (o->ctx);
+ Py_END_ALLOW_THREADS;
+ return PycairoPath_FromPath (cp);
}
static PyObject *
-pycairo_curve_to (PycairoContext *o, PyObject *args)
-{
- double x1, y1, x2, y2, x3, y3;
+pycairo_curve_to (PycairoContext *o, PyObject *args) {
+ double x1, y1, x2, y2, x3, y3;
- if (!PyArg_ParseTuple (args, "dddddd:Context.curve_to",
- &x1, &y1, &x2, &y2, &x3, &y3))
- return NULL;
+ if (!PyArg_ParseTuple (args, "dddddd:Context.curve_to",
+ &x1, &y1, &x2, &y2, &x3, &y3))
+ return NULL;
- cairo_curve_to (o->ctx, x1, y1, x2, y2, x3, y3);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_curve_to (o->ctx, x1, y1, x2, y2, x3, y3);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_device_to_user(PycairoContext *o, PyObject *args)
-{
- double x, y;
+pycairo_device_to_user(PycairoContext *o, PyObject *args) {
+ double x, y;
- if (!PyArg_ParseTuple(args, "dd:Context.device_to_user", &x, &y))
- return NULL;
+ if (!PyArg_ParseTuple(args, "dd:Context.device_to_user", &x, &y))
+ return NULL;
- cairo_device_to_user(o->ctx, &x, &y);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- return Py_BuildValue("(dd)", x, y);
+ cairo_device_to_user(o->ctx, &x, &y);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ return Py_BuildValue("(dd)", x, y);
}
static PyObject *
-pycairo_device_to_user_distance (PycairoContext *o, PyObject *args)
-{
- double dx, dy;
+pycairo_device_to_user_distance (PycairoContext *o, PyObject *args) {
+ double dx, dy;
- if (!PyArg_ParseTuple (args, "dd:Context.device_to_user_distance",
- &dx, &dy))
- return NULL;
+ if (!PyArg_ParseTuple (args, "dd:Context.device_to_user_distance",
+ &dx, &dy))
+ return NULL;
- cairo_device_to_user_distance (o->ctx, &dx, &dy);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- return Py_BuildValue("(dd)", dx, dy);
+ cairo_device_to_user_distance (o->ctx, &dx, &dy);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ return Py_BuildValue("(dd)", dx, dy);
}
static PyObject *
-pycairo_fill (PycairoContext *o)
-{
- Py_BEGIN_ALLOW_THREADS
- cairo_fill (o->ctx);
- Py_END_ALLOW_THREADS
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+pycairo_fill (PycairoContext *o) {
+ Py_BEGIN_ALLOW_THREADS;
+ cairo_fill (o->ctx);
+ Py_END_ALLOW_THREADS;
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_fill_extents (PycairoContext *o)
-{
- double x1, y1, x2, y2;
- cairo_fill_extents (o->ctx, &x1, &y1, &x2, &y2);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- return Py_BuildValue("(dddd)", x1, y1, x2, y2);
+pycairo_fill_extents (PycairoContext *o) {
+ double x1, y1, x2, y2;
+ cairo_fill_extents (o->ctx, &x1, &y1, &x2, &y2);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ return Py_BuildValue("(dddd)", x1, y1, x2, y2);
}
static PyObject *
-pycairo_fill_preserve (PycairoContext *o)
-{
- Py_BEGIN_ALLOW_THREADS
- cairo_fill_preserve (o->ctx);
- Py_END_ALLOW_THREADS
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+pycairo_fill_preserve (PycairoContext *o) {
+ Py_BEGIN_ALLOW_THREADS;
+ cairo_fill_preserve (o->ctx);
+ Py_END_ALLOW_THREADS;
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_font_extents (PycairoContext *o)
-{
- cairo_font_extents_t e;
+pycairo_font_extents (PycairoContext *o) {
+ cairo_font_extents_t e;
- cairo_font_extents (o->ctx, &e);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- return Py_BuildValue("(ddddd)", e.ascent, e.descent, e.height,
- e.max_x_advance, e.max_y_advance);
+ cairo_font_extents (o->ctx, &e);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ return Py_BuildValue("(ddddd)", e.ascent, e.descent, e.height,
+ e.max_x_advance, e.max_y_advance);
}
static PyObject *
-pycairo_get_antialias (PycairoContext *o)
-{
- return PyInt_FromLong (cairo_get_antialias (o->ctx));
+pycairo_get_antialias (PycairoContext *o) {
+ return PyInt_FromLong (cairo_get_antialias (o->ctx));
}
static PyObject *
-pycairo_get_current_point (PycairoContext *o)
-{
- double x, y;
- cairo_get_current_point (o->ctx, &x, &y);
- return Py_BuildValue("(dd)", x, y);
+pycairo_get_current_point (PycairoContext *o) {
+ double x, y;
+ cairo_get_current_point (o->ctx, &x, &y);
+ return Py_BuildValue("(dd)", x, y);
}
static PyObject *
-pycairo_get_dash (PycairoContext *o)
-{
- double *dashes = NULL, offset;
- int count, i;
- PyObject *py_dashes = NULL, *rv = NULL;
-
- count = cairo_get_dash_count (o->ctx);
- dashes = PyMem_Malloc (count * sizeof(double));
- if (dashes == NULL)
- return PyErr_NoMemory();
-
- cairo_get_dash (o->ctx, dashes, &offset);
- py_dashes = PyTuple_New(count);
- if (py_dashes == NULL)
- goto exit;
-
- for (i = 0; i < count; i++) {
- PyObject *dash = PyFloat_FromDouble(dashes[i]);
- if (dash == NULL)
- goto exit;
- PyTuple_SET_ITEM (py_dashes, i, dash);
- }
- rv = Py_BuildValue("(Od)", py_dashes, offset);
+pycairo_get_dash (PycairoContext *o) {
+ double *dashes = NULL, offset;
+ int count, i;
+ PyObject *py_dashes = NULL, *rv = NULL;
+
+ count = cairo_get_dash_count (o->ctx);
+ dashes = PyMem_Malloc (count * sizeof(double));
+ if (dashes == NULL)
+ return PyErr_NoMemory();
+
+ cairo_get_dash (o->ctx, dashes, &offset);
+ py_dashes = PyTuple_New(count);
+ if (py_dashes == NULL)
+ goto exit;
+
+ for (i = 0; i < count; i++) {
+ PyObject *dash = PyFloat_FromDouble(dashes[i]);
+ if (dash == NULL)
+ goto exit;
+ PyTuple_SET_ITEM (py_dashes, i, dash);
+ }
+ rv = Py_BuildValue("(Od)", py_dashes, offset);
exit:
- PyMem_Free (dashes);
- Py_XDECREF(py_dashes);
- return rv;
+ PyMem_Free (dashes);
+ Py_XDECREF(py_dashes);
+ return rv;
}
static PyObject *
-pycairo_get_dash_count (PycairoContext *o)
-{
- return PyInt_FromLong (cairo_get_dash_count (o->ctx));
+pycairo_get_dash_count (PycairoContext *o) {
+ return PyInt_FromLong (cairo_get_dash_count (o->ctx));
}
static PyObject *
-pycairo_get_fill_rule (PycairoContext *o)
-{
- return PyInt_FromLong(cairo_get_fill_rule (o->ctx));
+pycairo_get_fill_rule (PycairoContext *o) {
+ return PyInt_FromLong(cairo_get_fill_rule (o->ctx));
}
static PyObject *
-pycairo_get_font_face (PycairoContext *o)
-{
- return PycairoFontFace_FromFontFace (
- cairo_font_face_reference (cairo_get_font_face (o->ctx)));
+pycairo_get_font_face (PycairoContext *o) {
+ return PycairoFontFace_FromFontFace (
+ cairo_font_face_reference (cairo_get_font_face (o->ctx)));
}
static PyObject *
-pycairo_get_font_matrix (PycairoContext *o)
-{
- cairo_matrix_t matrix;
- cairo_get_font_matrix (o->ctx, &matrix);
- return PycairoMatrix_FromMatrix (&matrix);
+pycairo_get_font_matrix (PycairoContext *o) {
+ cairo_matrix_t matrix;
+ cairo_get_font_matrix (o->ctx, &matrix);
+ return PycairoMatrix_FromMatrix (&matrix);
}
static PyObject *
-pycairo_get_font_options (PycairoContext *o)
-{
- cairo_font_options_t *options = cairo_font_options_create();
- cairo_get_font_options (o->ctx, options);
- /* there is no reference fn */
- return PycairoFontOptions_FromFontOptions (options);
+pycairo_get_font_options (PycairoContext *o) {
+ cairo_font_options_t *options = cairo_font_options_create();
+ cairo_get_font_options (o->ctx, options);
+ /* there is no reference fn */
+ return PycairoFontOptions_FromFontOptions (options);
}
static PyObject *
-pycairo_get_group_target (PycairoContext *o)
-{
- cairo_surface_t *surface = cairo_get_group_target (o->ctx);
- if (surface != NULL)
- return PycairoSurface_FromSurface (cairo_surface_reference (surface),
- NULL);
- Py_RETURN_NONE;
+pycairo_get_group_target (PycairoContext *o) {
+ cairo_surface_t *surface = cairo_get_group_target (o->ctx);
+ if (surface != NULL)
+ return PycairoSurface_FromSurface (cairo_surface_reference (surface),
+ NULL);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_get_line_cap (PycairoContext *o)
-{
- return PyInt_FromLong(cairo_get_line_cap (o->ctx));
+pycairo_get_line_cap (PycairoContext *o) {
+ return PyInt_FromLong(cairo_get_line_cap (o->ctx));
}
static PyObject *
-pycairo_get_line_join (PycairoContext *o)
-{
- return PyInt_FromLong(cairo_get_line_join (o->ctx));
+pycairo_get_line_join (PycairoContext *o) {
+ return PyInt_FromLong(cairo_get_line_join (o->ctx));
}
static PyObject *
-pycairo_get_line_width (PycairoContext *o)
-{
- return PyFloat_FromDouble(cairo_get_line_width (o->ctx));
+pycairo_get_line_width (PycairoContext *o) {
+ return PyFloat_FromDouble(cairo_get_line_width (o->ctx));
}
static PyObject *
-pycairo_get_matrix (PycairoContext *o)
-{
- cairo_matrix_t matrix;
- cairo_get_matrix (o->ctx, &matrix);
- return PycairoMatrix_FromMatrix (&matrix);
+pycairo_get_matrix (PycairoContext *o) {
+ cairo_matrix_t matrix;
+ cairo_get_matrix (o->ctx, &matrix);
+ return PycairoMatrix_FromMatrix (&matrix);
}
static PyObject *
-pycairo_get_miter_limit (PycairoContext *o)
-{
- return PyFloat_FromDouble (cairo_get_miter_limit (o->ctx));
+pycairo_get_miter_limit (PycairoContext *o) {
+ return PyFloat_FromDouble (cairo_get_miter_limit (o->ctx));
}
static PyObject *
-pycairo_get_operator (PycairoContext *o)
-{
- return PyInt_FromLong (cairo_get_operator (o->ctx));
+pycairo_get_operator (PycairoContext *o) {
+ return PyInt_FromLong (cairo_get_operator (o->ctx));
}
static PyObject *
-pycairo_get_scaled_font (PycairoContext *o)
-{
- return PycairoScaledFont_FromScaledFont (
- cairo_scaled_font_reference (cairo_get_scaled_font (o->ctx)));
+pycairo_get_scaled_font (PycairoContext *o) {
+ return PycairoScaledFont_FromScaledFont (
+ cairo_scaled_font_reference (cairo_get_scaled_font (o->ctx)));
}
static PyObject *
-pycairo_get_source (PycairoContext *o)
-{
- return PycairoPattern_FromPattern (
+pycairo_get_source (PycairoContext *o) {
+ return PycairoPattern_FromPattern (
cairo_pattern_reference (cairo_get_source (o->ctx)), NULL);
}
static PyObject *
-pycairo_get_target (PycairoContext *o)
-{
- return PycairoSurface_FromSurface (
+pycairo_get_target (PycairoContext *o) {
+ return PycairoSurface_FromSurface (
cairo_surface_reference (cairo_get_target (o->ctx)),
NULL);
}
static PyObject *
-pycairo_get_tolerance (PycairoContext *o)
-{
- return PyFloat_FromDouble (cairo_get_tolerance (o->ctx));
+pycairo_get_tolerance (PycairoContext *o) {
+ return PyFloat_FromDouble (cairo_get_tolerance (o->ctx));
}
/* read a Python sequence of (i,x,y) sequences
@@ -483,1065 +443,1004 @@ pycairo_get_tolerance (PycairoContext *o)
static cairo_glyph_t *
_PyGlyphs_AsGlyphs (PyObject *py_object, int *num_glyphs)
{
- int length, i;
- cairo_glyph_t *glyphs = NULL, *glyph;
- PyObject *py_glyphs, *py_seq = NULL;
-
- py_glyphs = PySequence_Fast (py_object, "glyphs must be a sequence");
- if (py_glyphs == NULL)
- return NULL;
-
- length = PySequence_Fast_GET_SIZE(py_glyphs);
- if (*num_glyphs < 0 || *num_glyphs > length)
- *num_glyphs = length;
-
- glyphs = PyMem_Malloc (*num_glyphs * sizeof(cairo_glyph_t));
- if (glyphs == NULL) {
- PyErr_NoMemory();
- goto error;
- }
- for (i = 0, glyph = glyphs; i < *num_glyphs; i++, glyph++) {
- PyObject *py_item = PySequence_Fast_GET_ITEM(py_glyphs, i);
- py_seq = PySequence_Fast (py_item, "glyph items must be a sequence");
- if (py_seq == NULL)
- goto error;
- if (PySequence_Fast_GET_SIZE(py_seq) != 3) {
- PyErr_SetString(PyExc_ValueError,
- "each glyph item must be an (i,x,y) sequence");
- goto error;
- }
- glyph->index = PyInt_AsLong(PySequence_Fast_GET_ITEM(py_seq, 0));
- glyph->x = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(py_seq, 1));
- glyph->y = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(py_seq, 2));
- if (PyErr_Occurred())
- goto error;
- Py_DECREF(py_seq);
+ int length, i;
+ cairo_glyph_t *glyphs = NULL, *glyph;
+ PyObject *py_glyphs, *py_seq = NULL;
+
+ py_glyphs = PySequence_Fast (py_object, "glyphs must be a sequence");
+ if (py_glyphs == NULL)
+ return NULL;
+
+ length = PySequence_Fast_GET_SIZE(py_glyphs);
+ if (*num_glyphs < 0 || *num_glyphs > length)
+ *num_glyphs = length;
+
+ glyphs = PyMem_Malloc (*num_glyphs * sizeof(cairo_glyph_t));
+ if (glyphs == NULL) {
+ PyErr_NoMemory();
+ goto error;
+ }
+ for (i = 0, glyph = glyphs; i < *num_glyphs; i++, glyph++) {
+ PyObject *py_item = PySequence_Fast_GET_ITEM(py_glyphs, i);
+ py_seq = PySequence_Fast (py_item, "glyph items must be a sequence");
+ if (py_seq == NULL)
+ goto error;
+ if (PySequence_Fast_GET_SIZE(py_seq) != 3) {
+ PyErr_SetString(PyExc_ValueError,
+ "each glyph item must be an (i,x,y) sequence");
+ goto error;
}
- Py_DECREF(py_glyphs);
- return glyphs;
+ glyph->index = PyInt_AsLong(PySequence_Fast_GET_ITEM(py_seq, 0));
+ glyph->x = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(py_seq, 1));
+ glyph->y = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(py_seq, 2));
+ if (PyErr_Occurred())
+ goto error;
+ Py_DECREF(py_seq);
+ }
+ Py_DECREF(py_glyphs);
+ return glyphs;
error:
- Py_DECREF(py_glyphs);
- Py_XDECREF(py_seq);
- PyMem_Free(glyphs);
- return NULL;
+ Py_DECREF(py_glyphs);
+ Py_XDECREF(py_seq);
+ PyMem_Free(glyphs);
+ return NULL;
}
static PyObject *
-pycairo_glyph_extents (PycairoContext *o, PyObject *args)
-{
- int num_glyphs = -1;
- cairo_glyph_t *glyphs;
- cairo_text_extents_t extents;
- PyObject *py_object;
+pycairo_glyph_extents (PycairoContext *o, PyObject *args) {
+ int num_glyphs = -1;
+ cairo_glyph_t *glyphs;
+ cairo_text_extents_t extents;
+ PyObject *py_object;
- if (!PyArg_ParseTuple (args, "O|i:Context.glyph_extents",
- &py_object, &num_glyphs))
- return NULL;
+ if (!PyArg_ParseTuple (args, "O|i:Context.glyph_extents",
+ &py_object, &num_glyphs))
+ return NULL;
- glyphs = _PyGlyphs_AsGlyphs (py_object, &num_glyphs);
- if (glyphs == NULL)
- return NULL;
- cairo_glyph_extents (o->ctx, glyphs, num_glyphs, &extents);
- PyMem_Free (glyphs);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- return Py_BuildValue("(dddddd)", extents.x_bearing, extents.y_bearing,
- extents.width, extents.height, extents.x_advance,
- extents.y_advance);
+ glyphs = _PyGlyphs_AsGlyphs (py_object, &num_glyphs);
+ if (glyphs == NULL)
+ return NULL;
+ cairo_glyph_extents (o->ctx, glyphs, num_glyphs, &extents);
+ PyMem_Free (glyphs);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ return Py_BuildValue("(dddddd)", extents.x_bearing, extents.y_bearing,
+ extents.width, extents.height, extents.x_advance,
+ extents.y_advance);
}
static PyObject *
-pycairo_glyph_path (PycairoContext *o, PyObject *args)
-{
- int num_glyphs = -1;
- cairo_glyph_t *glyphs;
- PyObject *py_object;
+pycairo_glyph_path (PycairoContext *o, PyObject *args) {
+ int num_glyphs = -1;
+ cairo_glyph_t *glyphs;
+ PyObject *py_object;
- if (!PyArg_ParseTuple (args, "O|i:Context.glyph_path",
- &py_object, &num_glyphs))
- return NULL;
+ if (!PyArg_ParseTuple (args, "O|i:Context.glyph_path",
+ &py_object, &num_glyphs))
+ return NULL;
- glyphs = _PyGlyphs_AsGlyphs (py_object, &num_glyphs);
- if (glyphs == NULL)
- return NULL;
- cairo_glyph_path (o->ctx, glyphs, num_glyphs);
- PyMem_Free (glyphs);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ glyphs = _PyGlyphs_AsGlyphs (py_object, &num_glyphs);
+ if (glyphs == NULL)
+ return NULL;
+ cairo_glyph_path (o->ctx, glyphs, num_glyphs);
+ PyMem_Free (glyphs);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_has_current_point (PycairoContext *o)
-{
- PyObject *b = cairo_has_current_point (o->ctx) ? Py_True : Py_False;
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_INCREF(b);
- return b;
+pycairo_has_current_point (PycairoContext *o) {
+ PyObject *b = cairo_has_current_point (o->ctx) ? Py_True : Py_False;
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_INCREF(b);
+ return b;
}
static PyObject *
-pycairo_identity_matrix (PycairoContext *o)
-{
- cairo_identity_matrix (o->ctx);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+pycairo_identity_matrix (PycairoContext *o) {
+ cairo_identity_matrix (o->ctx);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_in_fill (PycairoContext *o, PyObject *args)
-{
- double x, y;
- PyObject *result;
+pycairo_in_fill (PycairoContext *o, PyObject *args) {
+ double x, y;
+ PyObject *result;
- if (!PyArg_ParseTuple (args, "dd:Context.in_fill", &x, &y))
- return NULL;
+ if (!PyArg_ParseTuple (args, "dd:Context.in_fill", &x, &y))
+ return NULL;
- result = cairo_in_fill (o->ctx, x, y) ? Py_True : Py_False;
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_INCREF(result);
- return result;
+ result = cairo_in_fill (o->ctx, x, y) ? Py_True : Py_False;
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_INCREF(result);
+ return result;
}
static PyObject *
-pycairo_in_stroke (PycairoContext *o, PyObject *args)
-{
- double x, y;
- PyObject *result;
+pycairo_in_stroke (PycairoContext *o, PyObject *args) {
+ double x, y;
+ PyObject *result;
- if (!PyArg_ParseTuple (args, "dd:Context.in_stroke", &x, &y))
- return NULL;
+ if (!PyArg_ParseTuple (args, "dd:Context.in_stroke", &x, &y))
+ return NULL;
- result = cairo_in_stroke (o->ctx, x, y) ? Py_True : Py_False;
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_INCREF(result);
- return result;
+ result = cairo_in_stroke (o->ctx, x, y) ? Py_True : Py_False;
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_INCREF(result);
+ return result;
}
static PyObject *
-pycairo_line_to (PycairoContext *o, PyObject *args)
-{
- double x, y;
+pycairo_line_to (PycairoContext *o, PyObject *args) {
+ double x, y;
- if (!PyArg_ParseTuple (args, "dd:Context.line_to", &x, &y))
- return NULL;
+ if (!PyArg_ParseTuple (args, "dd:Context.line_to", &x, &y))
+ return NULL;
- cairo_line_to (o->ctx, x, y);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_line_to (o->ctx, x, y);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_mask (PycairoContext *o, PyObject *args)
-{
- PycairoPattern *p;
+pycairo_mask (PycairoContext *o, PyObject *args) {
+ PycairoPattern *p;
- if (!PyArg_ParseTuple(args, "O!:Context.mask", &PycairoPattern_Type, &p))
- return NULL;
+ if (!PyArg_ParseTuple(args, "O!:Context.mask", &PycairoPattern_Type, &p))
+ return NULL;
- Py_BEGIN_ALLOW_THREADS
- cairo_mask (o->ctx, p->pattern);
- Py_END_ALLOW_THREADS
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ Py_BEGIN_ALLOW_THREADS;
+ cairo_mask (o->ctx, p->pattern);
+ Py_END_ALLOW_THREADS;
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_mask_surface (PycairoContext *o, PyObject *args)
-{
- PycairoSurface *s;
- double surface_x = 0.0, surface_y = 0.0;
+pycairo_mask_surface (PycairoContext *o, PyObject *args) {
+ PycairoSurface *s;
+ double surface_x = 0.0, surface_y = 0.0;
- if (!PyArg_ParseTuple (args, "O!|dd:Context.mask_surface",
- &PycairoSurface_Type, &s, &surface_x, &surface_y))
- return NULL;
+ if (!PyArg_ParseTuple (args, "O!|dd:Context.mask_surface",
+ &PycairoSurface_Type, &s, &surface_x, &surface_y))
+ return NULL;
- Py_BEGIN_ALLOW_THREADS
- cairo_mask_surface (o->ctx, s->surface, surface_x, surface_y);
- Py_END_ALLOW_THREADS
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ Py_BEGIN_ALLOW_THREADS;
+ cairo_mask_surface (o->ctx, s->surface, surface_x, surface_y);
+ Py_END_ALLOW_THREADS;
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_move_to (PycairoContext *o, PyObject *args)
-{
- double x, y;
+pycairo_move_to (PycairoContext *o, PyObject *args) {
+ double x, y;
- if (!PyArg_ParseTuple (args, "dd:Context.move_to", &x, &y))
- return NULL;
+ if (!PyArg_ParseTuple (args, "dd:Context.move_to", &x, &y))
+ return NULL;
- cairo_move_to (o->ctx, x, y);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_move_to (o->ctx, x, y);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_new_path (PycairoContext *o)
-{
- cairo_new_path (o->ctx);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+pycairo_new_path (PycairoContext *o) {
+ cairo_new_path (o->ctx);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_new_sub_path (PycairoContext *o)
-{
- cairo_new_sub_path (o->ctx);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+pycairo_new_sub_path (PycairoContext *o) {
+ cairo_new_sub_path (o->ctx);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_paint (PycairoContext *o)
-{
- Py_BEGIN_ALLOW_THREADS
- cairo_paint (o->ctx);
- Py_END_ALLOW_THREADS
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+pycairo_paint (PycairoContext *o) {
+ Py_BEGIN_ALLOW_THREADS;
+ cairo_paint (o->ctx);
+ Py_END_ALLOW_THREADS;
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_paint_with_alpha (PycairoContext *o, PyObject *args)
-{
- double alpha;
+pycairo_paint_with_alpha (PycairoContext *o, PyObject *args) {
+ double alpha;
- if (!PyArg_ParseTuple (args, "d:Context.paint_with_alpha", &alpha))
- return NULL;
+ if (!PyArg_ParseTuple (args, "d:Context.paint_with_alpha", &alpha))
+ return NULL;
- Py_BEGIN_ALLOW_THREADS
- cairo_paint_with_alpha (o->ctx, alpha);
- Py_END_ALLOW_THREADS
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ Py_BEGIN_ALLOW_THREADS;
+ cairo_paint_with_alpha (o->ctx, alpha);
+ Py_END_ALLOW_THREADS;
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_path_extents (PycairoContext *o)
-{
- double x1, y1, x2, y2;
- cairo_path_extents (o->ctx, &x1, &y1, &x2, &y2);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- return Py_BuildValue("(dddd)", x1, y1, x2, y2);
+pycairo_path_extents (PycairoContext *o) {
+ double x1, y1, x2, y2;
+ cairo_path_extents (o->ctx, &x1, &y1, &x2, &y2);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ return Py_BuildValue("(dddd)", x1, y1, x2, y2);
}
static PyObject *
-pycairo_pop_group (PycairoContext *o)
-{
- return PycairoPattern_FromPattern (cairo_pop_group (o->ctx), NULL);
+pycairo_pop_group (PycairoContext *o) {
+ return PycairoPattern_FromPattern (cairo_pop_group (o->ctx), NULL);
}
static PyObject *
-pycairo_pop_group_to_source (PycairoContext *o)
-{
- cairo_pop_group_to_source (o->ctx);
- Py_RETURN_NONE;
+pycairo_pop_group_to_source (PycairoContext *o) {
+ cairo_pop_group_to_source (o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_push_group (PycairoContext *o)
-{
- cairo_push_group (o->ctx);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+pycairo_push_group (PycairoContext *o) {
+ cairo_push_group (o->ctx);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_push_group_with_content (PycairoContext *o, PyObject *args)
-{
- cairo_content_t content;
+pycairo_push_group_with_content (PycairoContext *o, PyObject *args) {
+ cairo_content_t content;
- if (!PyArg_ParseTuple(args, "i:Context.push_group_with_content",
- &content))
- return NULL;
- cairo_push_group_with_content (o->ctx, content);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ if (!PyArg_ParseTuple(args, "i:Context.push_group_with_content",
+ &content))
+ return NULL;
+ cairo_push_group_with_content (o->ctx, content);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_rectangle (PycairoContext *o, PyObject *args)
-{
- double x, y, width, height;
+pycairo_rectangle (PycairoContext *o, PyObject *args) {
+ double x, y, width, height;
- if (!PyArg_ParseTuple (args, "dddd:Context.rectangle",
- &x, &y, &width, &height))
- return NULL;
+ if (!PyArg_ParseTuple (args, "dddd:Context.rectangle",
+ &x, &y, &width, &height))
+ return NULL;
- cairo_rectangle (o->ctx, x, y, width, height);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_rectangle (o->ctx, x, y, width, height);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_rel_curve_to (PycairoContext *o, PyObject *args)
-{
- double dx1, dy1, dx2, dy2, dx3, dy3;
+pycairo_rel_curve_to (PycairoContext *o, PyObject *args) {
+ double dx1, dy1, dx2, dy2, dx3, dy3;
- if (!PyArg_ParseTuple (args, "dddddd:Context.rel_curve_to",
- &dx1, &dy1, &dx2, &dy2, &dx3, &dy3))
- return NULL;
+ if (!PyArg_ParseTuple (args, "dddddd:Context.rel_curve_to",
+ &dx1, &dy1, &dx2, &dy2, &dx3, &dy3))
+ return NULL;
- cairo_rel_curve_to (o->ctx, dx1, dy1, dx2, dy2, dx3, dy3);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_rel_curve_to (o->ctx, dx1, dy1, dx2, dy2, dx3, dy3);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_rel_line_to (PycairoContext *o, PyObject *args)
-{
- double dx, dy;
+pycairo_rel_line_to (PycairoContext *o, PyObject *args) {
+ double dx, dy;
- if (!PyArg_ParseTuple (args, "dd:Context.rel_line_to", &dx, &dy))
- return NULL;
+ if (!PyArg_ParseTuple (args, "dd:Context.rel_line_to", &dx, &dy))
+ return NULL;
- cairo_rel_line_to (o->ctx, dx, dy);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_rel_line_to (o->ctx, dx, dy);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_rel_move_to (PycairoContext *o, PyObject *args)
-{
- double dx, dy;
+pycairo_rel_move_to (PycairoContext *o, PyObject *args) {
+ double dx, dy;
- if (!PyArg_ParseTuple (args, "dd:Context.rel_move_to", &dx, &dy))
- return NULL;
+ if (!PyArg_ParseTuple (args, "dd:Context.rel_move_to", &dx, &dy))
+ return NULL;
- cairo_rel_move_to (o->ctx, dx, dy);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_rel_move_to (o->ctx, dx, dy);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_reset_clip (PycairoContext *o)
-{
- cairo_reset_clip (o->ctx);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+pycairo_reset_clip (PycairoContext *o) {
+ cairo_reset_clip (o->ctx);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_restore (PycairoContext *o)
-{
- cairo_restore (o->ctx);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+pycairo_restore (PycairoContext *o) {
+ cairo_restore (o->ctx);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_rotate (PycairoContext *o, PyObject *args)
-{
- double angle;
+pycairo_rotate (PycairoContext *o, PyObject *args) {
+ double angle;
- if (!PyArg_ParseTuple(args, "d:Context.rotate", &angle))
- return NULL;
+ if (!PyArg_ParseTuple(args, "d:Context.rotate", &angle))
+ return NULL;
- cairo_rotate (o->ctx, angle);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_rotate (o->ctx, angle);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_save (PycairoContext *o)
-{
- cairo_save (o->ctx);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+pycairo_save (PycairoContext *o) {
+ cairo_save (o->ctx);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_scale (PycairoContext *o, PyObject *args)
-{
- double sx, sy;
+pycairo_scale (PycairoContext *o, PyObject *args) {
+ double sx, sy;
- if (!PyArg_ParseTuple (args, "dd:Context.scale", &sx, &sy))
- return NULL;
+ if (!PyArg_ParseTuple (args, "dd:Context.scale", &sx, &sy))
+ return NULL;
- cairo_scale (o->ctx, sx, sy);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_scale (o->ctx, sx, sy);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_select_font_face (PycairoContext *o, PyObject *args)
-{
- PyObject *obj;
- PyObject *pyUTF8 = NULL;
- const char *utf8family = NULL;
- cairo_font_slant_t slant = CAIRO_FONT_SLANT_NORMAL;
- cairo_font_weight_t weight = CAIRO_FONT_WEIGHT_NORMAL;
-
- if (!PyArg_ParseTuple(args, "O!|ii:Context.select_font_face",
- &PyBaseString_Type, &obj, &slant, &weight))
- return NULL;
-
- /* accept str and unicode family, auto convert to utf8 as required */
- if (PyString_Check(obj)) {
- /* A plain ASCII string is also a valid UTF-8 string */
- utf8family = PyString_AS_STRING(obj);
- } else if (PyUnicode_Check(obj)) {
- pyUTF8 = PyUnicode_AsUTF8String(obj);
- if (pyUTF8 != NULL) {
- utf8family = PyString_AS_STRING(pyUTF8);
- }
- } else {
- PyErr_SetString(PyExc_TypeError,
- "Context.select_font_face: family must be str or unicode");
+pycairo_select_font_face (PycairoContext *o, PyObject *args) {
+ PyObject *obj;
+ PyObject *pyUTF8 = NULL;
+ const char *utf8family = NULL;
+ cairo_font_slant_t slant = CAIRO_FONT_SLANT_NORMAL;
+ cairo_font_weight_t weight = CAIRO_FONT_WEIGHT_NORMAL;
+
+ if (!PyArg_ParseTuple(args, "O!|ii:Context.select_font_face",
+ &PyBaseString_Type, &obj, &slant, &weight))
+ return NULL;
+
+ /* accept str and unicode family, auto convert to utf8 as required */
+ if (PyString_Check(obj)) {
+ /* A plain ASCII string is also a valid UTF-8 string */
+ utf8family = PyString_AS_STRING(obj);
+ } else if (PyUnicode_Check(obj)) {
+ pyUTF8 = PyUnicode_AsUTF8String(obj);
+ if (pyUTF8 != NULL) {
+ utf8family = PyString_AS_STRING(pyUTF8);
}
- if (utf8family == NULL)
- return NULL;
+ } else {
+ PyErr_SetString(PyExc_TypeError,
+ "Context.select_font_face: family must be str or unicode");
+ }
+ if (utf8family == NULL)
+ return NULL;
- cairo_select_font_face (o->ctx, utf8family, slant, weight);
- Py_XDECREF(pyUTF8);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_select_font_face (o->ctx, utf8family, slant, weight);
+ Py_XDECREF(pyUTF8);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_set_antialias (PycairoContext *o, PyObject *args)
-{
- cairo_antialias_t antialias = CAIRO_ANTIALIAS_DEFAULT;
+pycairo_set_antialias (PycairoContext *o, PyObject *args) {
+ cairo_antialias_t antialias = CAIRO_ANTIALIAS_DEFAULT;
- if (!PyArg_ParseTuple(args, "|i:Context.set_antialias", &antialias))
- return NULL;
+ if (!PyArg_ParseTuple(args, "|i:Context.set_antialias", &antialias))
+ return NULL;
- cairo_set_antialias (o->ctx, antialias);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_set_antialias (o->ctx, antialias);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_set_dash (PycairoContext *o, PyObject *args)
-{
- double *dashes, offset = 0;
- int num_dashes, i;
- PyObject *py_dashes;
-
- if (!PyArg_ParseTuple (args, "O|d:Context.set_dash", &py_dashes, &offset))
- return NULL;
-
- py_dashes = PySequence_Fast (py_dashes,
- "first argument must be a sequence");
- if (py_dashes == NULL)
- return NULL;
-
- num_dashes = PySequence_Fast_GET_SIZE(py_dashes);
- dashes = PyMem_Malloc (num_dashes * sizeof(double));
- if (dashes == NULL) {
- Py_DECREF(py_dashes);
- return PyErr_NoMemory();
- }
+pycairo_set_dash (PycairoContext *o, PyObject *args) {
+ double *dashes, offset = 0;
+ int num_dashes, i;
+ PyObject *py_dashes;
- for (i = 0; i < num_dashes; i++) {
- dashes[i] = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(py_dashes, i));
- if (PyErr_Occurred()) {
- PyMem_Free (dashes);
- Py_DECREF(py_dashes);
- return NULL;
- }
- }
- cairo_set_dash (o->ctx, dashes, num_dashes, offset);
- PyMem_Free (dashes);
+ if (!PyArg_ParseTuple (args, "O|d:Context.set_dash", &py_dashes, &offset))
+ return NULL;
+
+ py_dashes = PySequence_Fast (py_dashes,
+ "first argument must be a sequence");
+ if (py_dashes == NULL)
+ return NULL;
+
+ num_dashes = PySequence_Fast_GET_SIZE(py_dashes);
+ dashes = PyMem_Malloc (num_dashes * sizeof(double));
+ if (dashes == NULL) {
Py_DECREF(py_dashes);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ return PyErr_NoMemory();
+ }
+
+ for (i = 0; i < num_dashes; i++) {
+ dashes[i] = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(py_dashes, i));
+ if (PyErr_Occurred()) {
+ PyMem_Free (dashes);
+ Py_DECREF(py_dashes);
+ return NULL;
+ }
+ }
+ cairo_set_dash (o->ctx, dashes, num_dashes, offset);
+ PyMem_Free (dashes);
+ Py_DECREF(py_dashes);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_set_fill_rule (PycairoContext *o, PyObject *args)
-{
- cairo_fill_rule_t fill_rule;
+pycairo_set_fill_rule (PycairoContext *o, PyObject *args) {
+ cairo_fill_rule_t fill_rule;
- if (!PyArg_ParseTuple (args, "i:Context.set_fill_rule", &fill_rule))
- return NULL;
+ if (!PyArg_ParseTuple (args, "i:Context.set_fill_rule", &fill_rule))
+ return NULL;
- cairo_set_fill_rule (o->ctx, fill_rule);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_set_fill_rule (o->ctx, fill_rule);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_set_font_face (PycairoContext *o, PyObject *obj)
-{
- if (PyObject_TypeCheck(obj, &PycairoFontFace_Type))
- cairo_set_font_face (o->ctx, ((PycairoFontFace *)obj)->font_face);
- else if (obj == Py_None)
- cairo_set_font_face (o->ctx, NULL);
- else {
- PyErr_SetString(PyExc_TypeError,
- "Context.set_font_face() argument must be "
- "cairo.FontFace or None");
- return NULL;
- }
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+pycairo_set_font_face (PycairoContext *o, PyObject *obj) {
+ if (PyObject_TypeCheck(obj, &PycairoFontFace_Type))
+ cairo_set_font_face (o->ctx, ((PycairoFontFace *)obj)->font_face);
+ else if (obj == Py_None)
+ cairo_set_font_face (o->ctx, NULL);
+ else {
+ PyErr_SetString(PyExc_TypeError,
+ "Context.set_font_face() argument must be "
+ "cairo.FontFace or None");
+ return NULL;
+ }
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_set_font_matrix (PycairoContext *o, PyObject *args)
-{
- PycairoMatrix *matrix;
+pycairo_set_font_matrix (PycairoContext *o, PyObject *args) {
+ PycairoMatrix *matrix;
- if (!PyArg_ParseTuple (args, "O!:Context.set_font_matrix",
- &PycairoMatrix_Type, &matrix))
- return NULL;
+ if (!PyArg_ParseTuple (args, "O!:Context.set_font_matrix",
+ &PycairoMatrix_Type, &matrix))
+ return NULL;
- cairo_set_font_matrix (o->ctx, &matrix->matrix);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_set_font_matrix (o->ctx, &matrix->matrix);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_set_font_options (PycairoContext *o, PyObject *args)
-{
- PycairoFontOptions *options;
+pycairo_set_font_options (PycairoContext *o, PyObject *args) {
+ PycairoFontOptions *options;
- if (!PyArg_ParseTuple (args, "O!:Context.set_font_options",
- &PycairoFontOptions_Type, &options))
- return NULL;
+ if (!PyArg_ParseTuple (args, "O!:Context.set_font_options",
+ &PycairoFontOptions_Type, &options))
+ return NULL;
- cairo_set_font_options (o->ctx, options->font_options);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_set_font_options (o->ctx, options->font_options);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_set_font_size (PycairoContext *o, PyObject *args)
-{
- double size;
+pycairo_set_font_size (PycairoContext *o, PyObject *args) {
+ double size;
- if (!PyArg_ParseTuple (args, "d:Context.set_font_size", &size))
- return NULL;
+ if (!PyArg_ParseTuple (args, "d:Context.set_font_size", &size))
+ return NULL;
- cairo_set_font_size (o->ctx, size);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_set_font_size (o->ctx, size);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_set_line_cap (PycairoContext *o, PyObject *args)
-{
- cairo_line_cap_t line_cap;
+pycairo_set_line_cap (PycairoContext *o, PyObject *args) {
+ cairo_line_cap_t line_cap;
- if (!PyArg_ParseTuple (args, "i:Context.set_line_cap", &line_cap))
- return NULL;
+ if (!PyArg_ParseTuple (args, "i:Context.set_line_cap", &line_cap))
+ return NULL;
- cairo_set_line_cap (o->ctx, line_cap);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_set_line_cap (o->ctx, line_cap);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_set_line_join (PycairoContext *o, PyObject *args)
-{
- cairo_line_join_t line_join;
+pycairo_set_line_join (PycairoContext *o, PyObject *args) {
+ cairo_line_join_t line_join;
- if (!PyArg_ParseTuple (args, "i:Context.set_line_join", &line_join))
- return NULL;
+ if (!PyArg_ParseTuple (args, "i:Context.set_line_join", &line_join))
+ return NULL;
- cairo_set_line_join (o->ctx, line_join);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_set_line_join (o->ctx, line_join);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_set_line_width (PycairoContext *o, PyObject *args)
-{
- double width;
+pycairo_set_line_width (PycairoContext *o, PyObject *args) {
+ double width;
- if (!PyArg_ParseTuple (args, "d:Context.set_line_width", &width))
- return NULL;
+ if (!PyArg_ParseTuple (args, "d:Context.set_line_width", &width))
+ return NULL;
- cairo_set_line_width (o->ctx, width);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_set_line_width (o->ctx, width);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_set_matrix (PycairoContext *o, PyObject *args)
-{
- PycairoMatrix *matrix;
+pycairo_set_matrix (PycairoContext *o, PyObject *args) {
+ PycairoMatrix *matrix;
- if (!PyArg_ParseTuple (args, "O!:Context.set_matrix",
- &PycairoMatrix_Type, &matrix))
- return NULL;
+ if (!PyArg_ParseTuple (args, "O!:Context.set_matrix",
+ &PycairoMatrix_Type, &matrix))
+ return NULL;
- cairo_set_matrix (o->ctx, &matrix->matrix);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_set_matrix (o->ctx, &matrix->matrix);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_set_miter_limit (PycairoContext *o, PyObject *args)
-{
- double limit;
+pycairo_set_miter_limit (PycairoContext *o, PyObject *args) {
+ double limit;
- if (!PyArg_ParseTuple (args, "d:Context.set_miter_limit", &limit))
- return NULL;
+ if (!PyArg_ParseTuple (args, "d:Context.set_miter_limit", &limit))
+ return NULL;
- cairo_set_miter_limit (o->ctx, limit);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_set_miter_limit (o->ctx, limit);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_set_operator(PycairoContext *o, PyObject *args)
-{
- cairo_operator_t op;
+pycairo_set_operator(PycairoContext *o, PyObject *args) {
+ cairo_operator_t op;
- if (!PyArg_ParseTuple(args, "i:Context.set_operator", &op))
- return NULL;
+ if (!PyArg_ParseTuple(args, "i:Context.set_operator", &op))
+ return NULL;
- cairo_set_operator(o->ctx, op);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_set_operator(o->ctx, op);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_set_scaled_font(PycairoContext *o, PyObject *args)
-{
- PycairoScaledFont *f;
- if (!PyArg_ParseTuple( args, "O!:Context.set_scaled_font",
- &PycairoScaledFont_Type, &f))
- return NULL;
+pycairo_set_scaled_font(PycairoContext *o, PyObject *args) {
+ PycairoScaledFont *f;
+ if (!PyArg_ParseTuple( args, "O!:Context.set_scaled_font",
+ &PycairoScaledFont_Type, &f))
+ return NULL;
- cairo_set_scaled_font(o->ctx, f->scaled_font);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_set_scaled_font(o->ctx, f->scaled_font);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_set_source (PycairoContext *o, PyObject *args)
-{
- PycairoPattern *p;
+pycairo_set_source (PycairoContext *o, PyObject *args) {
+ PycairoPattern *p;
- if (!PyArg_ParseTuple( args, "O!:Context.set_source",
- &PycairoPattern_Type, &p))
- return NULL;
+ if (!PyArg_ParseTuple( args, "O!:Context.set_source",
+ &PycairoPattern_Type, &p))
+ return NULL;
- cairo_set_source (o->ctx, p->pattern);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_set_source (o->ctx, p->pattern);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_set_source_rgb (PycairoContext *o, PyObject *args)
-{
- double red, green, blue;
+pycairo_set_source_rgb (PycairoContext *o, PyObject *args) {
+ double red, green, blue;
- if (!PyArg_ParseTuple (args, "ddd:Context.set_source_rgb",
- &red, &green, &blue))
- return NULL;
+ if (!PyArg_ParseTuple (args, "ddd:Context.set_source_rgb",
+ &red, &green, &blue))
+ return NULL;
- cairo_set_source_rgb (o->ctx, red, green, blue);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_set_source_rgb (o->ctx, red, green, blue);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_set_source_rgba (PycairoContext *o, PyObject *args)
-{
- double red, green, blue;
- double alpha = 1.0;
+pycairo_set_source_rgba (PycairoContext *o, PyObject *args) {
+ double red, green, blue;
+ double alpha = 1.0;
- if (!PyArg_ParseTuple (args, "ddd|d:Context.set_source_rgba",
- &red, &green, &blue, &alpha))
- return NULL;
+ if (!PyArg_ParseTuple (args, "ddd|d:Context.set_source_rgba",
+ &red, &green, &blue, &alpha))
+ return NULL;
- cairo_set_source_rgba (o->ctx, red, green, blue, alpha);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_set_source_rgba (o->ctx, red, green, blue, alpha);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_set_source_surface (PycairoContext *o, PyObject *args)
-{
- PycairoSurface *surface;
- double x = 0.0, y = 0.0;
+pycairo_set_source_surface (PycairoContext *o, PyObject *args) {
+ PycairoSurface *surface;
+ double x = 0.0, y = 0.0;
- if (!PyArg_ParseTuple (args, "O!|dd:Context.set_source_surface",
- &PycairoSurface_Type, &surface, &x, &y))
- return NULL;
+ if (!PyArg_ParseTuple (args, "O!|dd:Context.set_source_surface",
+ &PycairoSurface_Type, &surface, &x, &y))
+ return NULL;
- cairo_set_source_surface (o->ctx, surface->surface, x, y);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_set_source_surface (o->ctx, surface->surface, x, y);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_set_tolerance (PycairoContext *o, PyObject *args)
-{
- double tolerance;
- if (!PyArg_ParseTuple (args, "d:Context.set_tolerance", &tolerance))
- return NULL;
- cairo_set_tolerance (o->ctx, tolerance);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+pycairo_set_tolerance (PycairoContext *o, PyObject *args) {
+ double tolerance;
+ if (!PyArg_ParseTuple (args, "d:Context.set_tolerance", &tolerance))
+ return NULL;
+ cairo_set_tolerance (o->ctx, tolerance);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_show_glyphs (PycairoContext *o, PyObject *args)
-{
- int num_glyphs = -1;
- cairo_glyph_t *glyphs;
- PyObject *py_object;
+pycairo_show_glyphs (PycairoContext *o, PyObject *args) {
+ int num_glyphs = -1;
+ cairo_glyph_t *glyphs;
+ PyObject *py_object;
- if (!PyArg_ParseTuple (args, "O|i:Context.show_glyphs",
- &py_object, &num_glyphs))
- return NULL;
+ if (!PyArg_ParseTuple (args, "O|i:Context.show_glyphs",
+ &py_object, &num_glyphs))
+ return NULL;
- glyphs = _PyGlyphs_AsGlyphs (py_object, &num_glyphs);
- if (glyphs == NULL)
- return NULL;
- Py_BEGIN_ALLOW_THREADS
- cairo_show_glyphs (o->ctx, glyphs, num_glyphs);
- Py_END_ALLOW_THREADS
- PyMem_Free (glyphs);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ glyphs = _PyGlyphs_AsGlyphs (py_object, &num_glyphs);
+ if (glyphs == NULL)
+ return NULL;
+ Py_BEGIN_ALLOW_THREADS;
+ cairo_show_glyphs (o->ctx, glyphs, num_glyphs);
+ Py_END_ALLOW_THREADS;
+ PyMem_Free (glyphs);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_show_page (PycairoContext *o)
-{
- Py_BEGIN_ALLOW_THREADS
- cairo_show_page (o->ctx);
- Py_END_ALLOW_THREADS
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+pycairo_show_page (PycairoContext *o) {
+ Py_BEGIN_ALLOW_THREADS;
+ cairo_show_page (o->ctx);
+ Py_END_ALLOW_THREADS;
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_show_text (PycairoContext *o, PyObject *obj)
-{
- PyObject *pyUTF8 = NULL;
- const char *utf8 = NULL;
-
- /* accept str and unicode text, auto convert to utf8 as required */
- if (PyString_Check(obj)) {
- /* A plain ASCII string is also a valid UTF-8 string */
- utf8 = PyString_AS_STRING(obj);
- } else if (PyUnicode_Check(obj)) {
- pyUTF8 = PyUnicode_AsUTF8String(obj);
- if (pyUTF8 != NULL) {
- utf8 = PyString_AS_STRING(pyUTF8);
- }
- } else {
- PyErr_SetString(PyExc_TypeError,
- "Context.show_text: text must be str or unicode");
+pycairo_show_text (PycairoContext *o, PyObject *obj) {
+ PyObject *pyUTF8 = NULL;
+ const char *utf8 = NULL;
+
+ /* accept str and unicode text, auto convert to utf8 as required */
+ if (PyString_Check(obj)) {
+ /* A plain ASCII string is also a valid UTF-8 string */
+ utf8 = PyString_AS_STRING(obj);
+ } else if (PyUnicode_Check(obj)) {
+ pyUTF8 = PyUnicode_AsUTF8String(obj);
+ if (pyUTF8 != NULL) {
+ utf8 = PyString_AS_STRING(pyUTF8);
}
- if (utf8 == NULL)
- return NULL;
+ } else {
+ PyErr_SetString(PyExc_TypeError,
+ "Context.show_text: text must be str or unicode");
+ }
+ if (utf8 == NULL)
+ return NULL;
- Py_BEGIN_ALLOW_THREADS
- cairo_show_text (o->ctx, utf8);
- Py_END_ALLOW_THREADS
- Py_XDECREF(pyUTF8);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ Py_BEGIN_ALLOW_THREADS;
+ cairo_show_text (o->ctx, utf8);
+ Py_END_ALLOW_THREADS;
+ Py_XDECREF(pyUTF8);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_stroke (PycairoContext *o)
-{
- Py_BEGIN_ALLOW_THREADS
- cairo_stroke (o->ctx);
- Py_END_ALLOW_THREADS
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+pycairo_stroke (PycairoContext *o) {
+ Py_BEGIN_ALLOW_THREADS;
+ cairo_stroke (o->ctx);
+ Py_END_ALLOW_THREADS;
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_stroke_extents (PycairoContext *o)
-{
- double x1, y1, x2, y2;
- cairo_stroke_extents (o->ctx, &x1, &y1, &x2, &y2);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- return Py_BuildValue("(dddd)", x1, y1, x2, y2);
+pycairo_stroke_extents (PycairoContext *o) {
+ double x1, y1, x2, y2;
+ cairo_stroke_extents (o->ctx, &x1, &y1, &x2, &y2);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ return Py_BuildValue("(dddd)", x1, y1, x2, y2);
}
static PyObject *
-pycairo_stroke_preserve (PycairoContext *o)
-{
- Py_BEGIN_ALLOW_THREADS
- cairo_stroke_preserve (o->ctx);
- Py_END_ALLOW_THREADS
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+pycairo_stroke_preserve (PycairoContext *o) {
+ Py_BEGIN_ALLOW_THREADS;
+ cairo_stroke_preserve (o->ctx);
+ Py_END_ALLOW_THREADS;
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_text_extents (PycairoContext *o, PyObject *obj)
-{
- cairo_text_extents_t extents;
- PyObject *pyUTF8 = NULL;
- const char *utf8 = NULL;
-
- /* accept str and unicode text, auto convert to utf8 as required */
- if (PyString_Check(obj)) {
- /* A plain ASCII string is also a valid UTF-8 string */
- utf8 = PyString_AS_STRING(obj);
- } else if (PyUnicode_Check(obj)) {
- pyUTF8 = PyUnicode_AsUTF8String(obj);
- if (pyUTF8 != NULL) {
- utf8 = PyString_AS_STRING(pyUTF8);
- }
- } else {
- PyErr_SetString(PyExc_TypeError,
- "Context.text_extents: text must be str or unicode");
+pycairo_text_extents (PycairoContext *o, PyObject *obj) {
+ cairo_text_extents_t extents;
+ PyObject *pyUTF8 = NULL;
+ const char *utf8 = NULL;
+
+ /* accept str and unicode text, auto convert to utf8 as required */
+ if (PyString_Check(obj)) {
+ /* A plain ASCII string is also a valid UTF-8 string */
+ utf8 = PyString_AS_STRING(obj);
+ } else if (PyUnicode_Check(obj)) {
+ pyUTF8 = PyUnicode_AsUTF8String(obj);
+ if (pyUTF8 != NULL) {
+ utf8 = PyString_AS_STRING(pyUTF8);
}
- if (utf8 == NULL)
- return NULL;
+ } else {
+ PyErr_SetString(PyExc_TypeError,
+ "Context.text_extents: text must be str or unicode");
+ }
+ if (utf8 == NULL)
+ return NULL;
- cairo_text_extents (o->ctx, utf8, &extents);
- Py_XDECREF(pyUTF8);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- return Py_BuildValue("(dddddd)", extents.x_bearing, extents.y_bearing,
- extents.width, extents.height, extents.x_advance,
- extents.y_advance);
+ cairo_text_extents (o->ctx, utf8, &extents);
+ Py_XDECREF(pyUTF8);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ return Py_BuildValue("(dddddd)", extents.x_bearing, extents.y_bearing,
+ extents.width, extents.height, extents.x_advance,
+ extents.y_advance);
}
static PyObject *
-pycairo_text_path (PycairoContext *o, PyObject *obj)
-{
- PyObject *pyUTF8 = NULL;
- const char *utf8 = NULL;
-
- /* accept str and unicode text, auto convert to utf8 as required */
- if (PyString_Check(obj)) {
- /* A plain ASCII string is also a valid UTF-8 string */
- utf8 = PyString_AS_STRING(obj);
- } else if (PyUnicode_Check(obj)) {
- pyUTF8 = PyUnicode_AsUTF8String(obj);
- if (pyUTF8 != NULL) {
- utf8 = PyString_AS_STRING(pyUTF8);
- }
- } else {
- PyErr_SetString(PyExc_TypeError,
- "Context.text_path: text must be str or unicode");
+pycairo_text_path (PycairoContext *o, PyObject *obj) {
+ PyObject *pyUTF8 = NULL;
+ const char *utf8 = NULL;
+
+ /* accept str and unicode text, auto convert to utf8 as required */
+ if (PyString_Check(obj)) {
+ /* A plain ASCII string is also a valid UTF-8 string */
+ utf8 = PyString_AS_STRING(obj);
+ } else if (PyUnicode_Check(obj)) {
+ pyUTF8 = PyUnicode_AsUTF8String(obj);
+ if (pyUTF8 != NULL) {
+ utf8 = PyString_AS_STRING(pyUTF8);
}
- if (utf8 == NULL)
- return NULL;
+ } else {
+ PyErr_SetString(PyExc_TypeError,
+ "Context.text_path: text must be str or unicode");
+ }
+ if (utf8 == NULL)
+ return NULL;
- cairo_text_path (o->ctx, utf8);
- Py_XDECREF(pyUTF8);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_text_path (o->ctx, utf8);
+ Py_XDECREF(pyUTF8);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_transform (PycairoContext *o, PyObject *args)
-{
- PycairoMatrix *matrix;
+pycairo_transform (PycairoContext *o, PyObject *args) {
+ PycairoMatrix *matrix;
- if (!PyArg_ParseTuple (args, "O!:Context.transform",
- &PycairoMatrix_Type, &matrix))
- return NULL;
+ if (!PyArg_ParseTuple (args, "O!:Context.transform",
+ &PycairoMatrix_Type, &matrix))
+ return NULL;
- cairo_transform (o->ctx, &matrix->matrix);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_transform (o->ctx, &matrix->matrix);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_translate (PycairoContext *o, PyObject *args)
-{
- double tx, ty;
+pycairo_translate (PycairoContext *o, PyObject *args) {
+ double tx, ty;
- if (!PyArg_ParseTuple (args, "dd:Context.translate", &tx, &ty))
- return NULL;
+ if (!PyArg_ParseTuple (args, "dd:Context.translate", &tx, &ty))
+ return NULL;
- cairo_translate (o->ctx, tx, ty);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- Py_RETURN_NONE;
+ cairo_translate (o->ctx, tx, ty);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
}
static PyObject *
-pycairo_user_to_device (PycairoContext *o, PyObject *args)
-{
- double x, y;
+pycairo_user_to_device (PycairoContext *o, PyObject *args) {
+ double x, y;
- if (!PyArg_ParseTuple (args, "dd:Context.user_to_device", &x, &y))
- return NULL;
+ if (!PyArg_ParseTuple (args, "dd:Context.user_to_device", &x, &y))
+ return NULL;
- cairo_user_to_device (o->ctx, &x, &y);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- return Py_BuildValue("(dd)", x, y);
+ cairo_user_to_device (o->ctx, &x, &y);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ return Py_BuildValue("(dd)", x, y);
}
static PyObject *
-pycairo_user_to_device_distance (PycairoContext *o, PyObject *args)
-{
- double dx, dy;
+pycairo_user_to_device_distance (PycairoContext *o, PyObject *args) {
+ double dx, dy;
- if (!PyArg_ParseTuple (args, "dd:Context.user_to_device_distance",
- &dx, &dy))
- return NULL;
+ if (!PyArg_ParseTuple (args, "dd:Context.user_to_device_distance",
+ &dx, &dy))
+ return NULL;
- cairo_user_to_device_distance (o->ctx, &dx, &dy);
- RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
- return Py_BuildValue("(dd)", dx, dy);
+ cairo_user_to_device_distance (o->ctx, &dx, &dy);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ return Py_BuildValue("(dd)", dx, dy);
}
static PyMethodDef pycairo_methods[] = {
- /* methods never exposed in a language binding:
- * cairo_destroy()
- * cairo_reference()
- * cairo_rectangle_list_destroy()
- *
- * cairo_status()
- * cairo_status_string()
- * - not needed since Pycairo calls Pycairo_Check_Status() to check
- * for errors and raise exceptions
- */
- {"append_path", (PyCFunction)pycairo_append_path, METH_VARARGS},
- {"arc", (PyCFunction)pycairo_arc, METH_VARARGS},
- {"arc_negative", (PyCFunction)pycairo_arc_negative, METH_VARARGS},
- {"clip", (PyCFunction)pycairo_clip, METH_NOARGS},
- {"clip_extents", (PyCFunction)pycairo_clip_extents, METH_NOARGS},
- {"clip_preserve", (PyCFunction)pycairo_clip_preserve, METH_NOARGS},
- {"close_path", (PyCFunction)pycairo_close_path, METH_NOARGS},
- {"copy_clip_rectangle_list", (PyCFunction)pycairo_copy_clip_rectangle_list,
- METH_NOARGS},
- {"copy_page", (PyCFunction)pycairo_copy_page, METH_NOARGS},
- {"copy_path", (PyCFunction)pycairo_copy_path, METH_NOARGS},
- {"copy_path_flat", (PyCFunction)pycairo_copy_path_flat, METH_NOARGS},
- {"curve_to", (PyCFunction)pycairo_curve_to, METH_VARARGS},
- {"device_to_user", (PyCFunction)pycairo_device_to_user, METH_VARARGS},
- {"device_to_user_distance",
- (PyCFunction)pycairo_device_to_user_distance, METH_VARARGS},
- {"fill", (PyCFunction)pycairo_fill, METH_NOARGS},
- {"fill_extents", (PyCFunction)pycairo_fill_extents, METH_NOARGS},
- {"fill_preserve", (PyCFunction)pycairo_fill_preserve, METH_NOARGS},
- {"font_extents", (PyCFunction)pycairo_font_extents, METH_NOARGS},
- {"get_antialias", (PyCFunction)pycairo_get_antialias, METH_NOARGS},
- {"get_current_point",(PyCFunction)pycairo_get_current_point,METH_NOARGS},
- {"get_dash", (PyCFunction)pycairo_get_dash, METH_NOARGS},
- {"get_dash_count", (PyCFunction)pycairo_get_dash_count, METH_NOARGS},
- {"get_fill_rule", (PyCFunction)pycairo_get_fill_rule, METH_NOARGS},
- {"get_font_face", (PyCFunction)pycairo_get_font_face, METH_NOARGS},
- {"get_font_matrix", (PyCFunction)pycairo_get_font_matrix, METH_NOARGS},
- {"get_font_options",(PyCFunction)pycairo_get_font_options, METH_NOARGS},
- {"get_group_target",(PyCFunction)pycairo_get_group_target, METH_NOARGS},
- {"get_line_cap", (PyCFunction)pycairo_get_line_cap, METH_NOARGS},
- {"get_line_join", (PyCFunction)pycairo_get_line_join, METH_NOARGS},
- {"get_line_width", (PyCFunction)pycairo_get_line_width, METH_NOARGS},
- {"get_matrix", (PyCFunction)pycairo_get_matrix, METH_NOARGS},
- {"get_miter_limit", (PyCFunction)pycairo_get_miter_limit, METH_NOARGS},
- {"get_operator", (PyCFunction)pycairo_get_operator, METH_NOARGS},
- {"get_scaled_font", (PyCFunction)pycairo_get_scaled_font, METH_NOARGS},
- {"get_source", (PyCFunction)pycairo_get_source, METH_NOARGS},
- {"get_target", (PyCFunction)pycairo_get_target, METH_NOARGS},
- {"get_tolerance", (PyCFunction)pycairo_get_tolerance, METH_NOARGS},
- {"glyph_extents", (PyCFunction)pycairo_glyph_extents, METH_VARARGS},
- {"glyph_path", (PyCFunction)pycairo_glyph_path, METH_VARARGS},
- {"has_current_point",(PyCFunction)pycairo_has_current_point, METH_NOARGS},
- {"identity_matrix", (PyCFunction)pycairo_identity_matrix, METH_NOARGS},
- {"in_fill", (PyCFunction)pycairo_in_fill, METH_VARARGS},
- {"in_stroke", (PyCFunction)pycairo_in_stroke, METH_VARARGS},
- {"line_to", (PyCFunction)pycairo_line_to, METH_VARARGS},
- {"mask", (PyCFunction)pycairo_mask, METH_VARARGS},
- {"mask_surface", (PyCFunction)pycairo_mask_surface, METH_VARARGS},
- {"move_to", (PyCFunction)pycairo_move_to, METH_VARARGS},
- {"new_path", (PyCFunction)pycairo_new_path, METH_NOARGS},
- {"new_sub_path", (PyCFunction)pycairo_new_sub_path, METH_NOARGS},
- {"paint", (PyCFunction)pycairo_paint, METH_NOARGS},
- {"paint_with_alpha",(PyCFunction)pycairo_paint_with_alpha, METH_VARARGS},
- {"path_extents", (PyCFunction)pycairo_path_extents, METH_NOARGS},
- {"pop_group", (PyCFunction)pycairo_pop_group, METH_NOARGS},
- {"pop_group_to_source",
- (PyCFunction)pycairo_pop_group_to_source, METH_NOARGS},
- {"push_group", (PyCFunction)pycairo_push_group, METH_NOARGS},
- {"push_group_with_content",
- (PyCFunction)pycairo_push_group_with_content, METH_VARARGS},
- {"rectangle", (PyCFunction)pycairo_rectangle, METH_VARARGS},
- {"rel_curve_to", (PyCFunction)pycairo_rel_curve_to, METH_VARARGS},
- {"rel_line_to", (PyCFunction)pycairo_rel_line_to, METH_VARARGS},
- {"rel_move_to", (PyCFunction)pycairo_rel_move_to, METH_VARARGS},
- {"reset_clip", (PyCFunction)pycairo_reset_clip, METH_NOARGS},
- {"restore", (PyCFunction)pycairo_restore, METH_NOARGS},
- {"rotate", (PyCFunction)pycairo_rotate, METH_VARARGS},
- {"save", (PyCFunction)pycairo_save, METH_NOARGS},
- {"scale", (PyCFunction)pycairo_scale, METH_VARARGS},
- {"select_font_face",(PyCFunction)pycairo_select_font_face, METH_VARARGS},
- {"set_antialias", (PyCFunction)pycairo_set_antialias, METH_VARARGS},
- {"set_dash", (PyCFunction)pycairo_set_dash, METH_VARARGS},
- {"set_fill_rule", (PyCFunction)pycairo_set_fill_rule, METH_VARARGS},
- {"set_font_face", (PyCFunction)pycairo_set_font_face, METH_O},
- {"set_font_matrix", (PyCFunction)pycairo_set_font_matrix, METH_VARARGS},
- {"set_font_options",(PyCFunction)pycairo_set_font_options, METH_VARARGS},
- {"set_font_size", (PyCFunction)pycairo_set_font_size, METH_VARARGS},
- {"set_line_cap", (PyCFunction)pycairo_set_line_cap, METH_VARARGS},
- {"set_line_join", (PyCFunction)pycairo_set_line_join, METH_VARARGS},
- {"set_line_width", (PyCFunction)pycairo_set_line_width, METH_VARARGS},
- {"set_matrix", (PyCFunction)pycairo_set_matrix, METH_VARARGS},
- {"set_miter_limit", (PyCFunction)pycairo_set_miter_limit, METH_VARARGS},
- {"set_operator", (PyCFunction)pycairo_set_operator, METH_VARARGS},
- {"set_scaled_font", (PyCFunction)pycairo_set_scaled_font, METH_VARARGS},
- {"set_source", (PyCFunction)pycairo_set_source, METH_VARARGS},
- {"set_source_rgb", (PyCFunction)pycairo_set_source_rgb, METH_VARARGS},
- {"set_source_rgba", (PyCFunction)pycairo_set_source_rgba, METH_VARARGS},
- {"set_source_surface",(PyCFunction)pycairo_set_source_surface,
- METH_VARARGS},
- {"set_tolerance", (PyCFunction)pycairo_set_tolerance, METH_VARARGS},
- {"show_glyphs", (PyCFunction)pycairo_show_glyphs, METH_VARARGS},
- {"show_page", (PyCFunction)pycairo_show_page, METH_NOARGS},
- {"show_text", (PyCFunction)pycairo_show_text, METH_O},
- {"stroke", (PyCFunction)pycairo_stroke, METH_NOARGS},
- {"stroke_extents", (PyCFunction)pycairo_stroke_extents, METH_NOARGS},
- {"stroke_preserve", (PyCFunction)pycairo_stroke_preserve, METH_NOARGS},
- {"text_extents", (PyCFunction)pycairo_text_extents, METH_O},
- {"text_path", (PyCFunction)pycairo_text_path, METH_O},
- {"transform", (PyCFunction)pycairo_transform, METH_VARARGS},
- {"translate", (PyCFunction)pycairo_translate, METH_VARARGS},
- {"user_to_device", (PyCFunction)pycairo_user_to_device, METH_VARARGS},
- {"user_to_device_distance",(PyCFunction)pycairo_user_to_device_distance,
- METH_VARARGS},
- {NULL, NULL, 0, NULL},
+ /* methods never exposed in a language binding:
+ * cairo_destroy()
+ * cairo_reference()
+ * cairo_rectangle_list_destroy()
+ *
+ * cairo_status()
+ * cairo_status_string()
+ * - not needed since Pycairo calls Pycairo_Check_Status() to check
+ * for errors and raise exceptions
+ */
+ {"append_path", (PyCFunction)pycairo_append_path, METH_VARARGS},
+ {"arc", (PyCFunction)pycairo_arc, METH_VARARGS},
+ {"arc_negative", (PyCFunction)pycairo_arc_negative, METH_VARARGS},
+ {"clip", (PyCFunction)pycairo_clip, METH_NOARGS},
+ {"clip_extents", (PyCFunction)pycairo_clip_extents, METH_NOARGS},
+ {"clip_preserve", (PyCFunction)pycairo_clip_preserve, METH_NOARGS},
+ {"close_path", (PyCFunction)pycairo_close_path, METH_NOARGS},
+ {"copy_clip_rectangle_list", (PyCFunction)pycairo_copy_clip_rectangle_list,
+ METH_NOARGS},
+ {"copy_page", (PyCFunction)pycairo_copy_page, METH_NOARGS},
+ {"copy_path", (PyCFunction)pycairo_copy_path, METH_NOARGS},
+ {"copy_path_flat", (PyCFunction)pycairo_copy_path_flat, METH_NOARGS},
+ {"curve_to", (PyCFunction)pycairo_curve_to, METH_VARARGS},
+ {"device_to_user", (PyCFunction)pycairo_device_to_user, METH_VARARGS},
+ {"device_to_user_distance", (PyCFunction)pycairo_device_to_user_distance,
+ METH_VARARGS},
+ {"fill", (PyCFunction)pycairo_fill, METH_NOARGS},
+ {"fill_extents", (PyCFunction)pycairo_fill_extents, METH_NOARGS},
+ {"fill_preserve", (PyCFunction)pycairo_fill_preserve, METH_NOARGS},
+ {"font_extents", (PyCFunction)pycairo_font_extents, METH_NOARGS},
+ {"get_antialias", (PyCFunction)pycairo_get_antialias, METH_NOARGS},
+ {"get_current_point",(PyCFunction)pycairo_get_current_point,METH_NOARGS},
+ {"get_dash", (PyCFunction)pycairo_get_dash, METH_NOARGS},
+ {"get_dash_count", (PyCFunction)pycairo_get_dash_count, METH_NOARGS},
+ {"get_fill_rule", (PyCFunction)pycairo_get_fill_rule, METH_NOARGS},
+ {"get_font_face", (PyCFunction)pycairo_get_font_face, METH_NOARGS},
+ {"get_font_matrix", (PyCFunction)pycairo_get_font_matrix, METH_NOARGS},
+ {"get_font_options",(PyCFunction)pycairo_get_font_options, METH_NOARGS},
+ {"get_group_target",(PyCFunction)pycairo_get_group_target, METH_NOARGS},
+ {"get_line_cap", (PyCFunction)pycairo_get_line_cap, METH_NOARGS},
+ {"get_line_join", (PyCFunction)pycairo_get_line_join, METH_NOARGS},
+ {"get_line_width", (PyCFunction)pycairo_get_line_width, METH_NOARGS},
+ {"get_matrix", (PyCFunction)pycairo_get_matrix, METH_NOARGS},
+ {"get_miter_limit", (PyCFunction)pycairo_get_miter_limit, METH_NOARGS},
+ {"get_operator", (PyCFunction)pycairo_get_operator, METH_NOARGS},
+ {"get_scaled_font", (PyCFunction)pycairo_get_scaled_font, METH_NOARGS},
+ {"get_source", (PyCFunction)pycairo_get_source, METH_NOARGS},
+ {"get_target", (PyCFunction)pycairo_get_target, METH_NOARGS},
+ {"get_tolerance", (PyCFunction)pycairo_get_tolerance, METH_NOARGS},
+ {"glyph_extents", (PyCFunction)pycairo_glyph_extents, METH_VARARGS},
+ {"glyph_path", (PyCFunction)pycairo_glyph_path, METH_VARARGS},
+ {"has_current_point",(PyCFunction)pycairo_has_current_point, METH_NOARGS},
+ {"identity_matrix", (PyCFunction)pycairo_identity_matrix, METH_NOARGS},
+ {"in_fill", (PyCFunction)pycairo_in_fill, METH_VARARGS},
+ {"in_stroke", (PyCFunction)pycairo_in_stroke, METH_VARARGS},
+ {"line_to", (PyCFunction)pycairo_line_to, METH_VARARGS},
+ {"mask", (PyCFunction)pycairo_mask, METH_VARARGS},
+ {"mask_surface", (PyCFunction)pycairo_mask_surface, METH_VARARGS},
+ {"move_to", (PyCFunction)pycairo_move_to, METH_VARARGS},
+ {"new_path", (PyCFunction)pycairo_new_path, METH_NOARGS},
+ {"new_sub_path", (PyCFunction)pycairo_new_sub_path, METH_NOARGS},
+ {"paint", (PyCFunction)pycairo_paint, METH_NOARGS},
+ {"paint_with_alpha",(PyCFunction)pycairo_paint_with_alpha, METH_VARARGS},
+ {"path_extents", (PyCFunction)pycairo_path_extents, METH_NOARGS},
+ {"pop_group", (PyCFunction)pycairo_pop_group, METH_NOARGS},
+ {"pop_group_to_source", (PyCFunction)pycairo_pop_group_to_source,
+ METH_NOARGS},
+ {"push_group", (PyCFunction)pycairo_push_group, METH_NOARGS},
+ {"push_group_with_content", (PyCFunction)pycairo_push_group_with_content,
+ METH_VARARGS},
+ {"rectangle", (PyCFunction)pycairo_rectangle, METH_VARARGS},
+ {"rel_curve_to", (PyCFunction)pycairo_rel_curve_to, METH_VARARGS},
+ {"rel_line_to", (PyCFunction)pycairo_rel_line_to, METH_VARARGS},
+ {"rel_move_to", (PyCFunction)pycairo_rel_move_to, METH_VARARGS},
+ {"reset_clip", (PyCFunction)pycairo_reset_clip, METH_NOARGS},
+ {"restore", (PyCFunction)pycairo_restore, METH_NOARGS},
+ {"rotate", (PyCFunction)pycairo_rotate, METH_VARARGS},
+ {"save", (PyCFunction)pycairo_save, METH_NOARGS},
+ {"scale", (PyCFunction)pycairo_scale, METH_VARARGS},
+ {"select_font_face",(PyCFunction)pycairo_select_font_face, METH_VARARGS},
+ {"set_antialias", (PyCFunction)pycairo_set_antialias, METH_VARARGS},
+ {"set_dash", (PyCFunction)pycairo_set_dash, METH_VARARGS},
+ {"set_fill_rule", (PyCFunction)pycairo_set_fill_rule, METH_VARARGS},
+ {"set_font_face", (PyCFunction)pycairo_set_font_face, METH_O},
+ {"set_font_matrix", (PyCFunction)pycairo_set_font_matrix, METH_VARARGS},
+ {"set_font_options",(PyCFunction)pycairo_set_font_options, METH_VARARGS},
+ {"set_font_size", (PyCFunction)pycairo_set_font_size, METH_VARARGS},
+ {"set_line_cap", (PyCFunction)pycairo_set_line_cap, METH_VARARGS},
+ {"set_line_join", (PyCFunction)pycairo_set_line_join, METH_VARARGS},
+ {"set_line_width", (PyCFunction)pycairo_set_line_width, METH_VARARGS},
+ {"set_matrix", (PyCFunction)pycairo_set_matrix, METH_VARARGS},
+ {"set_miter_limit", (PyCFunction)pycairo_set_miter_limit, METH_VARARGS},
+ {"set_operator", (PyCFunction)pycairo_set_operator, METH_VARARGS},
+ {"set_scaled_font", (PyCFunction)pycairo_set_scaled_font, METH_VARARGS},
+ {"set_source", (PyCFunction)pycairo_set_source, METH_VARARGS},
+ {"set_source_rgb", (PyCFunction)pycairo_set_source_rgb, METH_VARARGS},
+ {"set_source_rgba", (PyCFunction)pycairo_set_source_rgba, METH_VARARGS},
+ {"set_source_surface",(PyCFunction)pycairo_set_source_surface, METH_VARARGS},
+ {"set_tolerance", (PyCFunction)pycairo_set_tolerance, METH_VARARGS},
+ {"show_glyphs", (PyCFunction)pycairo_show_glyphs, METH_VARARGS},
+ {"show_page", (PyCFunction)pycairo_show_page, METH_NOARGS},
+ {"show_text", (PyCFunction)pycairo_show_text, METH_O},
+ {"stroke", (PyCFunction)pycairo_stroke, METH_NOARGS},
+ {"stroke_extents", (PyCFunction)pycairo_stroke_extents, METH_NOARGS},
+ {"stroke_preserve", (PyCFunction)pycairo_stroke_preserve, METH_NOARGS},
+ {"text_extents", (PyCFunction)pycairo_text_extents, METH_O},
+ {"text_path", (PyCFunction)pycairo_text_path, METH_O},
+ {"transform", (PyCFunction)pycairo_transform, METH_VARARGS},
+ {"translate", (PyCFunction)pycairo_translate, METH_VARARGS},
+ {"user_to_device", (PyCFunction)pycairo_user_to_device, METH_VARARGS},
+ {"user_to_device_distance",(PyCFunction)pycairo_user_to_device_distance,
+ METH_VARARGS},
+ {NULL, NULL, 0, NULL},
};
PyTypeObject PycairoContext_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "cairo.Context", /* tp_name */
- sizeof(PycairoContext), /* tp_basicsize */
- 0, /* tp_itemsize */
- (destructor)pycairo_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,/* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- pycairo_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* &PyBaseObject_Type, */ /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)pycairo_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.Context", /* tp_name */
+ sizeof(PycairoContext), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ (destructor)pycairo_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,/* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ pycairo_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PyBaseObject_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)pycairo_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
};
diff --git a/src/pycairo-font.c b/src/pycairo-font.c
index 8b1215c..d240b46 100644
--- a/src/pycairo-font.c
+++ b/src/pycairo-font.c
@@ -1,4 +1,4 @@
-/* -*- mode: C; c-basic-offset: 4 -*-
+/* -*- mode: C; c-basic-offset: 2 -*-
*
* Pycairo - Python bindings for cairo
*
@@ -46,50 +46,47 @@
* Return value: New reference or NULL on failure
*/
PyObject *
-PycairoFontFace_FromFontFace (cairo_font_face_t *font_face)
-{
- PyTypeObject *type = NULL;
- PyObject *o;
+PycairoFontFace_FromFontFace (cairo_font_face_t *font_face) {
+ PyTypeObject *type = NULL;
+ PyObject *o;
- assert (font_face != NULL);
+ assert (font_face != NULL);
- if (Pycairo_Check_Status (cairo_font_face_status (font_face))) {
- cairo_font_face_destroy (font_face);
- return NULL;
- }
-
- switch (cairo_font_face_get_type (font_face)) {
- case CAIRO_FONT_TYPE_TOY:
- type = &PycairoToyFontFace_Type;
- break;
- default:
- type = &PycairoFontFace_Type;
- break;
- }
- o = type->tp_alloc (type, 0);
- if (o == NULL)
- cairo_font_face_destroy (font_face);
- else
- ((PycairoFontFace *)o)->font_face = font_face;
- return o;
+ if (Pycairo_Check_Status (cairo_font_face_status (font_face))) {
+ cairo_font_face_destroy (font_face);
+ return NULL;
+ }
+
+ switch (cairo_font_face_get_type (font_face)) {
+ case CAIRO_FONT_TYPE_TOY:
+ type = &PycairoToyFontFace_Type;
+ break;
+ default:
+ type = &PycairoFontFace_Type;
+ break;
+ }
+ o = type->tp_alloc (type, 0);
+ if (o == NULL)
+ cairo_font_face_destroy (font_face);
+ else
+ ((PycairoFontFace *)o)->font_face = font_face;
+ return o;
}
static void
-font_face_dealloc (PycairoFontFace *o)
-{
- if (o->font_face) {
- cairo_font_face_destroy (o->font_face);
- o->font_face = NULL;
- }
- o->ob_type->tp_free((PyObject *) o);
+font_face_dealloc (PycairoFontFace *o) {
+ if (o->font_face) {
+ cairo_font_face_destroy (o->font_face);
+ o->font_face = NULL;
+ }
+ o->ob_type->tp_free((PyObject *) o);
}
static PyObject *
-font_face_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PyErr_SetString (PyExc_TypeError, "The FontFace type cannot be "
- "instantiated directly, use Context.get_font_face()");
- return NULL;
+font_face_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
+ PyErr_SetString (PyExc_TypeError, "The FontFace type cannot be "
+ "instantiated directly, use Context.get_font_face()");
+ return NULL;
}
/*
@@ -105,157 +102,153 @@ static PyMethodDef font_face_methods[] = {
*/
PyTypeObject PycairoFontFace_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "cairo.FontFace", /* tp_name */
- sizeof(PycairoFontFace), /* tp_basicsize */
- 0, /* tp_itemsize */
- (destructor)font_face_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- 0, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* &PyBaseObject_Type, */ /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)font_face_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.FontFace", /* tp_name */
+ sizeof(PycairoFontFace), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ (destructor)font_face_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ 0, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PyBaseObject_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)font_face_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
};
/* class cairo.ToyFontFace ------------------------------------------------- */
static PyObject *
-toy_font_face_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PyObject *obj;
- PyObject *pyUTF8 = NULL;
- const char *utf8family = NULL;
- cairo_font_slant_t slant = CAIRO_FONT_SLANT_NORMAL;
- cairo_font_weight_t weight = CAIRO_FONT_WEIGHT_NORMAL;
-
- if (!PyArg_ParseTuple(args, "O!|ii:ToyFontFace.__new__",
- &PyBaseString_Type, &obj, &slant, &weight))
- return NULL;
-
- /* accept str and unicode family, auto convert to utf8 as required */
- if (PyString_Check(obj)) {
- /* A plain ASCII string is also a valid UTF-8 string */
- utf8family = PyString_AS_STRING(obj);
- } else if (PyUnicode_Check(obj)) {
- pyUTF8 = PyUnicode_AsUTF8String(obj);
- if (pyUTF8 != NULL) {
- utf8family = PyString_AS_STRING(pyUTF8);
- }
- } else {
- PyErr_SetString(PyExc_TypeError,
- "ToyFontFace.__new__: family must be str or unicode");
+toy_font_face_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
+ PyObject *obj;
+ PyObject *pyUTF8 = NULL;
+ const char *utf8family = NULL;
+ cairo_font_slant_t slant = CAIRO_FONT_SLANT_NORMAL;
+ cairo_font_weight_t weight = CAIRO_FONT_WEIGHT_NORMAL;
+
+ if (!PyArg_ParseTuple(args, "O!|ii:ToyFontFace.__new__",
+ &PyBaseString_Type, &obj, &slant, &weight))
+ return NULL;
+
+ /* accept str and unicode family, auto convert to utf8 as required */
+ if (PyString_Check(obj)) {
+ /* A plain ASCII string is also a valid UTF-8 string */
+ utf8family = PyString_AS_STRING(obj);
+ } else if (PyUnicode_Check(obj)) {
+ pyUTF8 = PyUnicode_AsUTF8String(obj);
+ if (pyUTF8 != NULL) {
+ utf8family = PyString_AS_STRING(pyUTF8);
}
- if (utf8family == NULL)
- return NULL;
+ } else {
+ PyErr_SetString(PyExc_TypeError,
+ "ToyFontFace.__new__: family must be str or unicode");
+ }
+ if (utf8family == NULL)
+ return NULL;
- PyObject *o = PycairoFontFace_FromFontFace (
- cairo_toy_font_face_create (utf8family, slant, weight));
- Py_XDECREF(pyUTF8);
- return o;
+ PyObject *o = PycairoFontFace_FromFontFace (
+ cairo_toy_font_face_create (utf8family, slant, weight));
+ Py_XDECREF(pyUTF8);
+ return o;
}
static PyObject *
-toy_font_get_family (PycairoToyFontFace *o)
-{
- return PyString_FromString (cairo_toy_font_face_get_family (o->font_face));
+toy_font_get_family (PycairoToyFontFace *o) {
+ return PyString_FromString (cairo_toy_font_face_get_family (o->font_face));
}
static PyObject *
-toy_font_get_slant (PycairoToyFontFace *o)
-{
- return PyInt_FromLong (cairo_toy_font_face_get_slant (o->font_face));
+toy_font_get_slant (PycairoToyFontFace *o) {
+ return PyInt_FromLong (cairo_toy_font_face_get_slant (o->font_face));
}
static PyObject *
-toy_font_get_weight (PycairoToyFontFace *o)
-{
- return PyInt_FromLong (cairo_toy_font_face_get_weight (o->font_face));
+toy_font_get_weight (PycairoToyFontFace *o) {
+ return PyInt_FromLong (cairo_toy_font_face_get_weight (o->font_face));
}
static PyMethodDef toy_font_face_methods[] = {
- {"get_family", (PyCFunction)toy_font_get_family, METH_NOARGS},
- {"get_slant", (PyCFunction)toy_font_get_slant, METH_NOARGS},
- {"get_weight", (PyCFunction)toy_font_get_weight, METH_NOARGS},
- {NULL, NULL, 0, NULL},
+ {"get_family", (PyCFunction)toy_font_get_family, METH_NOARGS},
+ {"get_slant", (PyCFunction)toy_font_get_slant, METH_NOARGS},
+ {"get_weight", (PyCFunction)toy_font_get_weight, METH_NOARGS},
+ {NULL, NULL, 0, NULL},
};
PyTypeObject PycairoToyFontFace_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "cairo.ToyFontFace", /* tp_name */
- sizeof(PycairoToyFontFace), /* tp_basicsize */
- 0, /* tp_itemsize */
- 0, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- toy_font_face_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* &PycairoFontFace_Type, */ /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)toy_font_face_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.ToyFontFace", /* tp_name */
+ sizeof(PycairoToyFontFace), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ toy_font_face_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PycairoFontFace_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)toy_font_face_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
};
@@ -268,176 +261,168 @@ PyTypeObject PycairoToyFontFace_Type = {
* Return value: New reference or NULL on failure
*/
PyObject *
-PycairoScaledFont_FromScaledFont (cairo_scaled_font_t *scaled_font)
-{
- PyObject *o;
+PycairoScaledFont_FromScaledFont (cairo_scaled_font_t *scaled_font) {
+ PyObject *o;
- assert (scaled_font != NULL);
+ assert (scaled_font != NULL);
- if (Pycairo_Check_Status (cairo_scaled_font_status (scaled_font))) {
- cairo_scaled_font_destroy (scaled_font);
- return NULL;
- }
-
- o = PycairoScaledFont_Type.tp_alloc (&PycairoScaledFont_Type, 0);
- if (o == NULL)
- cairo_scaled_font_destroy (scaled_font);
- else
- ((PycairoScaledFont *)o)->scaled_font = scaled_font;
- return o;
+ if (Pycairo_Check_Status (cairo_scaled_font_status (scaled_font))) {
+ cairo_scaled_font_destroy (scaled_font);
+ return NULL;
+ }
+
+ o = PycairoScaledFont_Type.tp_alloc (&PycairoScaledFont_Type, 0);
+ if (o == NULL)
+ cairo_scaled_font_destroy (scaled_font);
+ else
+ ((PycairoScaledFont *)o)->scaled_font = scaled_font;
+ return o;
}
static void
-scaled_font_dealloc(PycairoScaledFont *o)
-{
- if (o->scaled_font) {
- cairo_scaled_font_destroy (o->scaled_font);
- o->scaled_font = NULL;
- }
- o->ob_type->tp_free((PyObject *) o);
+scaled_font_dealloc(PycairoScaledFont *o) {
+ if (o->scaled_font) {
+ cairo_scaled_font_destroy (o->scaled_font);
+ o->scaled_font = NULL;
+ }
+ o->ob_type->tp_free((PyObject *) o);
}
static PyObject *
-scaled_font_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PycairoFontFace *ff;
- PycairoFontOptions *fo;
- PycairoMatrix *mx1, *mx2;
-
- if (!PyArg_ParseTuple(args, "O!O!O!O!:ScaledFont.__new__",
- &PycairoFontFace_Type, &ff,
- &PycairoMatrix_Type, &mx1,
- &PycairoMatrix_Type, &mx2,
- &PycairoFontOptions_Type, &fo))
- return NULL;
- return PycairoScaledFont_FromScaledFont (
+scaled_font_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
+ PycairoFontFace *ff;
+ PycairoFontOptions *fo;
+ PycairoMatrix *mx1, *mx2;
+
+ if (!PyArg_ParseTuple(args, "O!O!O!O!:ScaledFont.__new__",
+ &PycairoFontFace_Type, &ff,
+ &PycairoMatrix_Type, &mx1,
+ &PycairoMatrix_Type, &mx2,
+ &PycairoFontOptions_Type, &fo))
+ return NULL;
+ return PycairoScaledFont_FromScaledFont (
cairo_scaled_font_create (ff->font_face, &mx1->matrix,
&mx2->matrix, fo->font_options));
}
static PyObject *
-scaled_font_extents (PycairoScaledFont *o)
-{
- cairo_font_extents_t e;
-
- cairo_scaled_font_extents (o->scaled_font, &e);
- RETURN_NULL_IF_CAIRO_SCALED_FONT_ERROR(o->scaled_font);
- return Py_BuildValue ("(ddddd)", e.ascent, e.descent, e.height,
- e.max_x_advance, e.max_y_advance);
+scaled_font_extents (PycairoScaledFont *o) {
+ cairo_font_extents_t e;
+
+ cairo_scaled_font_extents (o->scaled_font, &e);
+ RETURN_NULL_IF_CAIRO_SCALED_FONT_ERROR(o->scaled_font);
+ return Py_BuildValue ("(ddddd)", e.ascent, e.descent, e.height,
+ e.max_x_advance, e.max_y_advance);
}
static PyObject *
-scaled_font_get_font_face (PycairoScaledFont *o)
-{
- return PycairoFontFace_FromFontFace (
+scaled_font_get_font_face (PycairoScaledFont *o) {
+ return PycairoFontFace_FromFontFace (
cairo_font_face_reference (
cairo_scaled_font_get_font_face (o->scaled_font)));
}
static PyObject *
-scaled_font_get_scale_matrix (PycairoScaledFont *o)
-{
- cairo_matrix_t matrix;
- cairo_scaled_font_get_scale_matrix (o->scaled_font, &matrix);
- return PycairoMatrix_FromMatrix (&matrix);
+scaled_font_get_scale_matrix (PycairoScaledFont *o) {
+ cairo_matrix_t matrix;
+ cairo_scaled_font_get_scale_matrix (o->scaled_font, &matrix);
+ return PycairoMatrix_FromMatrix (&matrix);
}
static PyObject *
-scaled_font_text_extents (PycairoScaledFont *o, PyObject *obj)
-{
- cairo_text_extents_t extents;
- PyObject *pyUTF8 = NULL;
- const char *utf8 = NULL;
-
- /* accept str and unicode text, auto convert to utf8 as required */
- if (PyString_Check(obj)) {
- /* A plain ASCII string is also a valid UTF-8 string */
- utf8 = PyString_AS_STRING(obj);
- } else if (PyUnicode_Check(obj)) {
- pyUTF8 = PyUnicode_AsUTF8String(obj);
- if (pyUTF8 != NULL) {
- utf8 = PyString_AS_STRING(pyUTF8);
- }
- } else {
- PyErr_SetString(PyExc_TypeError,
- "ScaledFont.text_extents: text must be str or unicode");
+scaled_font_text_extents (PycairoScaledFont *o, PyObject *obj) {
+ cairo_text_extents_t extents;
+ PyObject *pyUTF8 = NULL;
+ const char *utf8 = NULL;
+
+ /* accept str and unicode text, auto convert to utf8 as required */
+ if (PyString_Check(obj)) {
+ /* A plain ASCII string is also a valid UTF-8 string */
+ utf8 = PyString_AS_STRING(obj);
+ } else if (PyUnicode_Check(obj)) {
+ pyUTF8 = PyUnicode_AsUTF8String(obj);
+ if (pyUTF8 != NULL) {
+ utf8 = PyString_AS_STRING(pyUTF8);
}
- if (utf8 == NULL)
- return NULL;
-
- cairo_scaled_font_text_extents (o->scaled_font, utf8, &extents);
- Py_XDECREF(pyUTF8);
- RETURN_NULL_IF_CAIRO_SCALED_FONT_ERROR(o->scaled_font);
- return Py_BuildValue("(dddddd)", extents.x_bearing, extents.y_bearing,
- extents.width, extents.height, extents.x_advance,
- extents.y_advance);
+ } else {
+ PyErr_SetString(PyExc_TypeError,
+ "ScaledFont.text_extents: text must be str or unicode");
+ }
+ if (utf8 == NULL)
+ return NULL;
+
+ cairo_scaled_font_text_extents (o->scaled_font, utf8, &extents);
+ Py_XDECREF(pyUTF8);
+ RETURN_NULL_IF_CAIRO_SCALED_FONT_ERROR(o->scaled_font);
+ return Py_BuildValue("(dddddd)", extents.x_bearing, extents.y_bearing,
+ extents.width, extents.height, extents.x_advance,
+ extents.y_advance);
}
static PyMethodDef scaled_font_methods[] = {
- /* methods never exposed in a language binding:
- * cairo_scaled_font_destroy()
- * cairo_scaled_font_get_type()
- * cairo_scaled_font_reference()
- *
- * TODO if requested:
- * cairo_scaled_font_get_ctm
- * cairo_scaled_font_get_font_matrix
- * cairo_scaled_font_get_font_options
- * cairo_scaled_font_glyph_extents
- * cairo_scaled_font_text_to_glyphs
- */
- {"extents", (PyCFunction)scaled_font_extents, METH_NOARGS},
- {"get_font_face", (PyCFunction)scaled_font_get_font_face, METH_NOARGS},
- {"get_scale_matrix", (PyCFunction)scaled_font_get_scale_matrix,
- METH_VARARGS},
- {"text_extents", (PyCFunction)scaled_font_text_extents, METH_O},
- {NULL, NULL, 0, NULL},
+ /* methods never exposed in a language binding:
+ * cairo_scaled_font_destroy()
+ * cairo_scaled_font_get_type()
+ * cairo_scaled_font_reference()
+ *
+ * TODO if requested:
+ * cairo_scaled_font_get_ctm
+ * cairo_scaled_font_get_font_matrix
+ * cairo_scaled_font_get_font_options
+ * cairo_scaled_font_glyph_extents
+ * cairo_scaled_font_text_to_glyphs
+ */
+ {"extents", (PyCFunction)scaled_font_extents, METH_NOARGS},
+ {"get_font_face", (PyCFunction)scaled_font_get_font_face, METH_NOARGS},
+ {"get_scale_matrix", (PyCFunction)scaled_font_get_scale_matrix, METH_VARARGS},
+ {"text_extents", (PyCFunction)scaled_font_text_extents, METH_O},
+ {NULL, NULL, 0, NULL},
};
PyTypeObject PycairoScaledFont_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "cairo.ScaledFont", /* tp_name */
- sizeof(PycairoScaledFont), /* tp_basicsize */
- 0, /* tp_itemsize */
- (destructor)scaled_font_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- scaled_font_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* &PyBaseObject_Type, */ /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)scaled_font_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.ScaledFont", /* tp_name */
+ sizeof(PycairoScaledFont), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ (destructor)scaled_font_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ scaled_font_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PyBaseObject_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)scaled_font_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
};
@@ -450,192 +435,177 @@ PyTypeObject PycairoScaledFont_Type = {
* Return value: New reference or NULL on failure
*/
PyObject *
-PycairoFontOptions_FromFontOptions (cairo_font_options_t *font_options)
-{
- PyObject *o;
-
- assert (font_options != NULL);
+PycairoFontOptions_FromFontOptions (cairo_font_options_t *font_options) {
+ PyObject *o;
- if (Pycairo_Check_Status (cairo_font_options_status (font_options))) {
- cairo_font_options_destroy (font_options);
- return NULL;
- }
+ assert (font_options != NULL);
- o = PycairoFontOptions_Type.tp_alloc (&PycairoFontOptions_Type, 0);
- if (o == NULL)
- cairo_font_options_destroy (font_options);
- else
- ((PycairoFontOptions *)o)->font_options = font_options;
- return o;
+ if (Pycairo_Check_Status (cairo_font_options_status (font_options))) {
+ cairo_font_options_destroy (font_options);
+ return NULL;
+ }
+
+ o = PycairoFontOptions_Type.tp_alloc (&PycairoFontOptions_Type, 0);
+ if (o == NULL)
+ cairo_font_options_destroy (font_options);
+ else
+ ((PycairoFontOptions *)o)->font_options = font_options;
+ return o;
}
static void
-font_options_dealloc(PycairoFontOptions *o)
-{
- if (o->font_options) {
- cairo_font_options_destroy (o->font_options);
- o->font_options = NULL;
- }
- o->ob_type->tp_free((PyObject *) o);
+font_options_dealloc(PycairoFontOptions *o) {
+ if (o->font_options) {
+ cairo_font_options_destroy (o->font_options);
+ o->font_options = NULL;
+ }
+ o->ob_type->tp_free((PyObject *) o);
}
static PyObject *
-font_options_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- return PycairoFontOptions_FromFontOptions (cairo_font_options_create());
+font_options_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
+ return PycairoFontOptions_FromFontOptions (cairo_font_options_create());
}
static PyObject *
-font_options_get_antialias (PycairoFontOptions *o)
-{
- return PyInt_FromLong (cairo_font_options_get_antialias (o->font_options));
+font_options_get_antialias (PycairoFontOptions *o) {
+ return PyInt_FromLong (cairo_font_options_get_antialias (o->font_options));
}
static PyObject *
-font_options_get_hint_metrics (PycairoFontOptions *o)
-{
- return PyInt_FromLong (cairo_font_options_get_hint_metrics
- (o->font_options));
+font_options_get_hint_metrics (PycairoFontOptions *o) {
+ return PyInt_FromLong (cairo_font_options_get_hint_metrics
+ (o->font_options));
}
static PyObject *
-font_options_get_hint_style (PycairoFontOptions *o)
-{
- return PyInt_FromLong (cairo_font_options_get_hint_style
- (o->font_options));
+font_options_get_hint_style (PycairoFontOptions *o) {
+ return PyInt_FromLong (cairo_font_options_get_hint_style
+ (o->font_options));
}
static PyObject *
-font_options_get_subpixel_order (PycairoFontOptions *o)
-{
- return PyInt_FromLong (cairo_font_options_get_subpixel_order
- (o->font_options));
+font_options_get_subpixel_order (PycairoFontOptions *o) {
+ return PyInt_FromLong (cairo_font_options_get_subpixel_order
+ (o->font_options));
}
static PyObject *
-font_options_set_antialias (PycairoFontOptions *o, PyObject *args)
-{
- cairo_antialias_t aa = CAIRO_ANTIALIAS_DEFAULT;
+font_options_set_antialias (PycairoFontOptions *o, PyObject *args) {
+ cairo_antialias_t aa = CAIRO_ANTIALIAS_DEFAULT;
- if (!PyArg_ParseTuple(args, "|i:FontOptions.set_antialias", &aa))
- return NULL;
+ if (!PyArg_ParseTuple(args, "|i:FontOptions.set_antialias", &aa))
+ return NULL;
- cairo_font_options_set_antialias (o->font_options, aa);
- RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(o->font_options);
- Py_RETURN_NONE;
+ cairo_font_options_set_antialias (o->font_options, aa);
+ RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(o->font_options);
+ Py_RETURN_NONE;
}
static PyObject *
-font_options_set_hint_metrics (PycairoFontOptions *o, PyObject *args)
-{
- cairo_hint_metrics_t hm = CAIRO_HINT_METRICS_DEFAULT;
+font_options_set_hint_metrics (PycairoFontOptions *o, PyObject *args) {
+ cairo_hint_metrics_t hm = CAIRO_HINT_METRICS_DEFAULT;
- if (!PyArg_ParseTuple(args, "|i:FontOptions.set_hint_metrics", &hm))
- return NULL;
+ if (!PyArg_ParseTuple(args, "|i:FontOptions.set_hint_metrics", &hm))
+ return NULL;
- cairo_font_options_set_hint_metrics (o->font_options, hm);
- RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(o->font_options);
- Py_RETURN_NONE;
+ cairo_font_options_set_hint_metrics (o->font_options, hm);
+ RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(o->font_options);
+ Py_RETURN_NONE;
}
static PyObject *
-font_options_set_hint_style (PycairoFontOptions *o, PyObject *args)
-{
- cairo_hint_style_t hs = CAIRO_HINT_STYLE_DEFAULT;
+font_options_set_hint_style (PycairoFontOptions *o, PyObject *args) {
+ cairo_hint_style_t hs = CAIRO_HINT_STYLE_DEFAULT;
- if (!PyArg_ParseTuple(args, "|i:FontOptions.set_hint_style", &hs))
- return NULL;
+ if (!PyArg_ParseTuple(args, "|i:FontOptions.set_hint_style", &hs))
+ return NULL;
- cairo_font_options_set_hint_style (o->font_options, hs);
- RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(o->font_options);
- Py_RETURN_NONE;
+ cairo_font_options_set_hint_style (o->font_options, hs);
+ RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(o->font_options);
+ Py_RETURN_NONE;
}
static PyObject *
-font_options_set_subpixel_order (PycairoFontOptions *o, PyObject *args)
-{
- cairo_subpixel_order_t so = CAIRO_SUBPIXEL_ORDER_DEFAULT;
+font_options_set_subpixel_order (PycairoFontOptions *o, PyObject *args) {
+ cairo_subpixel_order_t so = CAIRO_SUBPIXEL_ORDER_DEFAULT;
- if (!PyArg_ParseTuple(args, "|i:FontOptions.set_subpixel_order", &so))
- return NULL;
+ if (!PyArg_ParseTuple(args, "|i:FontOptions.set_subpixel_order", &so))
+ return NULL;
- cairo_font_options_set_subpixel_order (o->font_options, so);
- RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(o->font_options);
- Py_RETURN_NONE;
+ cairo_font_options_set_subpixel_order (o->font_options, so);
+ RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(o->font_options);
+ Py_RETURN_NONE;
}
static PyMethodDef font_options_methods[] = {
- /* methods never exposed in a language binding:
- * cairo_font_options_destroy()
- * cairo_font_options_reference()
- */
- /* TODO: */
- /* copy */
- /* hash */
- /* merge */
- /* equal (richcmp?) */
- {"get_antialias", (PyCFunction)font_options_get_antialias,
- METH_NOARGS},
- {"get_hint_metrics", (PyCFunction)font_options_get_hint_metrics,
- METH_NOARGS},
- {"get_hint_style", (PyCFunction)font_options_get_hint_style,
- METH_NOARGS},
- {"get_subpixel_order",(PyCFunction)font_options_get_subpixel_order,
- METH_NOARGS},
- {"set_antialias", (PyCFunction)font_options_set_antialias,
- METH_VARARGS},
- {"set_hint_metrics", (PyCFunction)font_options_set_hint_metrics,
- METH_VARARGS},
- {"set_hint_style", (PyCFunction)font_options_set_hint_style,
- METH_VARARGS},
- {"set_subpixel_order",(PyCFunction)font_options_set_subpixel_order,
- METH_VARARGS},
- {NULL, NULL, 0, NULL},
+ /* methods never exposed in a language binding:
+ * cairo_font_options_destroy()
+ * cairo_font_options_reference()
+ */
+ /* TODO: */
+ /* copy */
+ /* hash */
+ /* merge */
+ /* equal (richcmp?) */
+ {"get_antialias", (PyCFunction)font_options_get_antialias, METH_NOARGS},
+ {"get_hint_metrics", (PyCFunction)font_options_get_hint_metrics,
+ METH_NOARGS},
+ {"get_hint_style", (PyCFunction)font_options_get_hint_style, METH_NOARGS},
+ {"get_subpixel_order",(PyCFunction)font_options_get_subpixel_order,
+ METH_NOARGS},
+ {"set_antialias", (PyCFunction)font_options_set_antialias, METH_VARARGS},
+ {"set_hint_metrics", (PyCFunction)font_options_set_hint_metrics,
+ METH_VARARGS},
+ {"set_hint_style", (PyCFunction)font_options_set_hint_style, METH_VARARGS},
+ {"set_subpixel_order",(PyCFunction)font_options_set_subpixel_order,
+ METH_VARARGS},
+ {NULL, NULL, 0, NULL},
};
PyTypeObject PycairoFontOptions_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "cairo.FontOptions", /* tp_name */
- sizeof(PycairoFontOptions), /* tp_basicsize */
- 0, /* tp_itemsize */
- (destructor)font_options_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- font_options_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* &PyBaseObject_Type, */ /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)font_options_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.FontOptions", /* tp_name */
+ sizeof(PycairoFontOptions), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ (destructor)font_options_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ font_options_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PyBaseObject_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)font_options_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
};
diff --git a/src/pycairo-matrix.c b/src/pycairo-matrix.c
index 73f1845..8daa6dc 100644
--- a/src/pycairo-matrix.c
+++ b/src/pycairo-matrix.c
@@ -1,4 +1,4 @@
-/* -*- mode: C; c-basic-offset: 4 -*-
+/* -*- mode: C; c-basic-offset: 2 -*-
*
* Pycairo - Python bindings for cairo
*
@@ -43,204 +43,189 @@
* Return value: New reference or NULL on failure
*/
PyObject *
-PycairoMatrix_FromMatrix (const cairo_matrix_t *matrix)
-{
- PyObject *o;
- assert (matrix != NULL);
- o = PycairoMatrix_Type.tp_alloc (&PycairoMatrix_Type, 0);
- if (o != NULL)
- ((PycairoMatrix *)o)->matrix = *matrix;
- return o;
+PycairoMatrix_FromMatrix (const cairo_matrix_t *matrix) {
+ PyObject *o;
+ assert (matrix != NULL);
+ o = PycairoMatrix_Type.tp_alloc (&PycairoMatrix_Type, 0);
+ if (o != NULL)
+ ((PycairoMatrix *)o)->matrix = *matrix;
+ return o;
}
static void
-matrix_dealloc (PycairoMatrix *o)
-{
- o->ob_type->tp_free((PyObject *)o);
+matrix_dealloc (PycairoMatrix *o) {
+ o->ob_type->tp_free((PyObject *)o);
}
static PyObject *
-matrix_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PyObject *o;
- static char *kwlist[] = { "xx", "yx", "xy", "yy", "x0", "y0", NULL };
- double xx = 1.0, yx = 0.0, xy = 0.0, yy = 1.0, x0 = 0.0, y0 = 0.0;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwds,
- "|dddddd:Matrix.__init__", kwlist,
- &xx, &yx, &xy, &yy, &x0, &y0))
- return NULL;
-
- o = type->tp_alloc(type, 0);
- if (o)
- cairo_matrix_init (&((PycairoMatrix *)o)->matrix,
- xx, yx, xy, yy, x0, y0);
- return o;
+matrix_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
+ PyObject *o;
+ static char *kwlist[] = { "xx", "yx", "xy", "yy", "x0", "y0", NULL };
+ double xx = 1.0, yx = 0.0, xy = 0.0, yy = 1.0, x0 = 0.0, y0 = 0.0;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds,
+ "|dddddd:Matrix.__init__", kwlist,
+ &xx, &yx, &xy, &yy, &x0, &y0))
+ return NULL;
+
+ o = type->tp_alloc(type, 0);
+ if (o)
+ cairo_matrix_init (&((PycairoMatrix *)o)->matrix,
+ xx, yx, xy, yy, x0, y0);
+ return o;
}
static PyObject *
-matrix_init_rotate (PyTypeObject *type, PyObject *args)
-{
- cairo_matrix_t matrix;
- double radians;
+matrix_init_rotate (PyTypeObject *type, PyObject *args) {
+ cairo_matrix_t matrix;
+ double radians;
- if (!PyArg_ParseTuple(args, "d:Matrix.init_rotate", &radians))
- return NULL;
+ if (!PyArg_ParseTuple(args, "d:Matrix.init_rotate", &radians))
+ return NULL;
- cairo_matrix_init_rotate (&matrix, radians);
- return PycairoMatrix_FromMatrix (&matrix);
+ cairo_matrix_init_rotate (&matrix, radians);
+ return PycairoMatrix_FromMatrix (&matrix);
}
static PyObject *
-matrix_invert (PycairoMatrix *o)
-{
- if (Pycairo_Check_Status (cairo_matrix_invert (&o->matrix)))
- return NULL;
- Py_RETURN_NONE;
+matrix_invert (PycairoMatrix *o) {
+ if (Pycairo_Check_Status (cairo_matrix_invert (&o->matrix)))
+ return NULL;
+ Py_RETURN_NONE;
}
/* cairo_matrix_multiply */
static PyObject *
-matrix_multiply (PycairoMatrix *o, PyObject *args)
-{
- PycairoMatrix *mx2;
+matrix_multiply (PycairoMatrix *o, PyObject *args) {
+ PycairoMatrix *mx2;
- if (!PyArg_ParseTuple(args, "O!:Matrix.multiply",
- &PycairoMatrix_Type, &mx2))
- return NULL;
+ if (!PyArg_ParseTuple(args, "O!:Matrix.multiply",
+ &PycairoMatrix_Type, &mx2))
+ return NULL;
- cairo_matrix_t result;
- cairo_matrix_multiply (&result, &o->matrix, &mx2->matrix);
- return PycairoMatrix_FromMatrix (&result);
+ cairo_matrix_t result;
+ cairo_matrix_multiply (&result, &o->matrix, &mx2->matrix);
+ return PycairoMatrix_FromMatrix (&result);
}
/* standard matrix multiply, for use by '*' operator */
static PyObject *
-matrix_operator_multiply (PycairoMatrix *o, PycairoMatrix *o2)
-{
- cairo_matrix_t result;
- cairo_matrix_multiply (&result, &o->matrix, &o2->matrix);
- return PycairoMatrix_FromMatrix (&result);
+matrix_operator_multiply (PycairoMatrix *o, PycairoMatrix *o2) {
+ cairo_matrix_t result;
+ cairo_matrix_multiply (&result, &o->matrix, &o2->matrix);
+ return PycairoMatrix_FromMatrix (&result);
}
static PyObject *
-matrix_repr (PycairoMatrix *o)
-{
- char buf[256];
-
- PyOS_snprintf(buf, sizeof(buf), "cairo.Matrix(%g, %g, %g, %g, %g, %g)",
- o->matrix.xx, o->matrix.yx,
- o->matrix.xy, o->matrix.yy,
- o->matrix.x0, o->matrix.y0);
- return PyString_FromString(buf);
+matrix_repr (PycairoMatrix *o) {
+ char buf[256];
+
+ PyOS_snprintf(buf, sizeof(buf), "cairo.Matrix(%g, %g, %g, %g, %g, %g)",
+ o->matrix.xx, o->matrix.yx,
+ o->matrix.xy, o->matrix.yy,
+ o->matrix.x0, o->matrix.y0);
+ return PyString_FromString(buf);
}
static PyObject *
-matrix_richcmp (PycairoMatrix *m1, PycairoMatrix *m2, int op)
-{
- int equal;
- PyObject *ret;
- cairo_matrix_t *mx1 = &m1->matrix;
- cairo_matrix_t *mx2 = &m2->matrix;
-
- if (!PyObject_TypeCheck(m2, &PycairoMatrix_Type) ||
- !(op == Py_EQ || op == Py_NE)) {
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
- }
-
- equal = mx1->xx == mx2->xx && mx1->yx == mx2->yx &&
- mx1->xy == mx2->xy && mx1->yy == mx2->yy &&
- mx1->x0 == mx2->x0 && mx1->y0 == mx2->y0;
-
- if (op == Py_EQ)
- ret = equal ? Py_True : Py_False;
- else
- ret = equal ? Py_False : Py_True;
- Py_INCREF(ret);
- return ret;
+matrix_richcmp (PycairoMatrix *m1, PycairoMatrix *m2, int op) {
+ int equal;
+ PyObject *ret;
+ cairo_matrix_t *mx1 = &m1->matrix;
+ cairo_matrix_t *mx2 = &m2->matrix;
+
+ if (!PyObject_TypeCheck(m2, &PycairoMatrix_Type) ||
+ !(op == Py_EQ || op == Py_NE)) {
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+ }
+
+ equal = mx1->xx == mx2->xx && mx1->yx == mx2->yx &&
+ mx1->xy == mx2->xy && mx1->yy == mx2->yy &&
+ mx1->x0 == mx2->x0 && mx1->y0 == mx2->y0;
+
+ if (op == Py_EQ)
+ ret = equal ? Py_True : Py_False;
+ else
+ ret = equal ? Py_False : Py_True;
+ Py_INCREF(ret);
+ return ret;
}
static PyObject *
-matrix_rotate (PycairoMatrix *o, PyObject *args)
-{
- double radians;
+matrix_rotate (PycairoMatrix *o, PyObject *args) {
+ double radians;
- if (!PyArg_ParseTuple(args, "d:Matrix.rotate", &radians))
- return NULL;
+ if (!PyArg_ParseTuple(args, "d:Matrix.rotate", &radians))
+ return NULL;
- cairo_matrix_rotate (&o->matrix, radians);
- Py_RETURN_NONE;
+ cairo_matrix_rotate (&o->matrix, radians);
+ Py_RETURN_NONE;
}
static PyObject *
-matrix_scale (PycairoMatrix *o, PyObject *args)
-{
- double sx, sy;
+matrix_scale (PycairoMatrix *o, PyObject *args) {
+ double sx, sy;
- if (!PyArg_ParseTuple(args, "dd:Matrix.scale", &sx, &sy))
- return NULL;
+ if (!PyArg_ParseTuple(args, "dd:Matrix.scale", &sx, &sy))
+ return NULL;
- cairo_matrix_scale (&o->matrix, sx, sy);
- Py_RETURN_NONE;
+ cairo_matrix_scale (&o->matrix, sx, sy);
+ Py_RETURN_NONE;
}
static PyObject *
-matrix_transform_distance (PycairoMatrix *o, PyObject *args)
-{
- double dx, dy;
+matrix_transform_distance (PycairoMatrix *o, PyObject *args) {
+ double dx, dy;
- if (!PyArg_ParseTuple(args, "dd:Matrix.transform_distance", &dx, &dy))
- return NULL;
+ if (!PyArg_ParseTuple(args, "dd:Matrix.transform_distance", &dx, &dy))
+ return NULL;
- cairo_matrix_transform_distance (&o->matrix, &dx, &dy);
- return Py_BuildValue("(dd)", dx, dy);
+ cairo_matrix_transform_distance (&o->matrix, &dx, &dy);
+ return Py_BuildValue("(dd)", dx, dy);
}
static PyObject *
-matrix_transform_point (PycairoMatrix *o, PyObject *args)
-{
- double x, y;
+matrix_transform_point (PycairoMatrix *o, PyObject *args) {
+ double x, y;
- if (!PyArg_ParseTuple(args, "dd:Matrix.transform_point", &x, &y))
- return NULL;
+ if (!PyArg_ParseTuple(args, "dd:Matrix.transform_point", &x, &y))
+ return NULL;
- cairo_matrix_transform_point (&o->matrix, &x, &y);
- return Py_BuildValue("(dd)", x, y);
+ cairo_matrix_transform_point (&o->matrix, &x, &y);
+ return Py_BuildValue("(dd)", x, y);
}
static PyObject *
-matrix_translate (PycairoMatrix *o, PyObject *args)
-{
- double tx, ty;
+matrix_translate (PycairoMatrix *o, PyObject *args) {
+ double tx, ty;
- if (!PyArg_ParseTuple(args, "dd:Matrix.translate", &tx, &ty))
- return NULL;
+ if (!PyArg_ParseTuple(args, "dd:Matrix.translate", &tx, &ty))
+ return NULL;
- cairo_matrix_translate (&o->matrix, tx, ty);
- Py_RETURN_NONE;
+ cairo_matrix_translate (&o->matrix, tx, ty);
+ Py_RETURN_NONE;
}
static PyObject *
-matrix_item (PycairoMatrix *o, Py_ssize_t i)
-{
- switch (i) {
- case 0:
- return Py_BuildValue("d", o->matrix.xx);
- case 1:
- return Py_BuildValue("d", o->matrix.yx);
- case 2:
- return Py_BuildValue("d", o->matrix.xy);
- case 3:
- return Py_BuildValue("d", o->matrix.yy);
- case 4:
- return Py_BuildValue("d", o->matrix.x0);
- case 5:
- return Py_BuildValue("d", o->matrix.y0);
- default:
- PyErr_SetString(PyExc_IndexError, "Matrix index out of range");
- return NULL;
- }
+matrix_item (PycairoMatrix *o, Py_ssize_t i) {
+ switch (i) {
+ case 0:
+ return Py_BuildValue("d", o->matrix.xx);
+ case 1:
+ return Py_BuildValue("d", o->matrix.yx);
+ case 2:
+ return Py_BuildValue("d", o->matrix.xy);
+ case 3:
+ return Py_BuildValue("d", o->matrix.yy);
+ case 4:
+ return Py_BuildValue("d", o->matrix.x0);
+ case 5:
+ return Py_BuildValue("d", o->matrix.y0);
+ default:
+ PyErr_SetString(PyExc_IndexError, "Matrix index out of range");
+ return NULL;
+ }
}
static PyNumberMethods matrix_as_number = {
@@ -286,80 +271,78 @@ static PyNumberMethods matrix_as_number = {
};
static PySequenceMethods matrix_as_sequence = {
- 0, /* sq_length */
- 0, /* sq_concat */
- 0, /* sq_repeat */
- (ssizeargfunc)matrix_item, /* sq_item */
- 0, /* sq_slice */
- 0, /* sq_ass_item */
- 0, /* sq_ass_slice */
- 0, /* sq_contains */
+ 0, /* sq_length */
+ 0, /* sq_concat */
+ 0, /* sq_repeat */
+ (ssizeargfunc)matrix_item, /* sq_item */
+ 0, /* sq_slice */
+ 0, /* sq_ass_item */
+ 0, /* sq_ass_slice */
+ 0, /* sq_contains */
};
static PyMethodDef matrix_methods[] = {
- /* Do not need to wrap all cairo_matrix_init_*() functions
- * C API Matrix constructors Python equivalents
- * cairo_matrix_init() cairo.Matrix(xx,yx,xy,yy,x0,y0)
- * cairo_matrix_init_rotate() cairo.Matrix.init_rotate(radians)
-
- * cairo_matrix_init_identity() cairo.Matrix()
- * cairo_matrix_init_translate() cairo.Matrix(x0=x0,y0=y0)
- * cairo_matrix_init_scale() cairo.Matrix(xx=xx,yy=yy)
- */
- {"init_rotate", (PyCFunction)matrix_init_rotate,
- METH_VARARGS | METH_CLASS },
- {"invert", (PyCFunction)matrix_invert, METH_NOARGS },
- {"multiply", (PyCFunction)matrix_multiply, METH_VARARGS },
- {"rotate", (PyCFunction)matrix_rotate, METH_VARARGS },
- {"scale", (PyCFunction)matrix_scale, METH_VARARGS },
- {"transform_distance",(PyCFunction)matrix_transform_distance,
- METH_VARARGS },
- {"transform_point", (PyCFunction)matrix_transform_point, METH_VARARGS },
- {"translate", (PyCFunction)matrix_translate, METH_VARARGS },
- {NULL, NULL, 0, NULL},
+ /* Do not need to wrap all cairo_matrix_init_*() functions
+ * C API Matrix constructors Python equivalents
+ * cairo_matrix_init() cairo.Matrix(xx,yx,xy,yy,x0,y0)
+ * cairo_matrix_init_rotate() cairo.Matrix.init_rotate(radians)
+
+ * cairo_matrix_init_identity() cairo.Matrix()
+ * cairo_matrix_init_translate() cairo.Matrix(x0=x0,y0=y0)
+ * cairo_matrix_init_scale() cairo.Matrix(xx=xx,yy=yy)
+ */
+ {"init_rotate", (PyCFunction)matrix_init_rotate, METH_VARARGS | METH_CLASS },
+ {"invert", (PyCFunction)matrix_invert, METH_NOARGS },
+ {"multiply", (PyCFunction)matrix_multiply, METH_VARARGS },
+ {"rotate", (PyCFunction)matrix_rotate, METH_VARARGS },
+ {"scale", (PyCFunction)matrix_scale, METH_VARARGS },
+ {"transform_distance",(PyCFunction)matrix_transform_distance, METH_VARARGS },
+ {"transform_point", (PyCFunction)matrix_transform_point, METH_VARARGS },
+ {"translate", (PyCFunction)matrix_translate, METH_VARARGS },
+ {NULL, NULL, 0, NULL},
};
PyTypeObject PycairoMatrix_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "cairo.Matrix", /* tp_name */
- sizeof(PycairoMatrix), /* tp_basicsize */
- 0, /* tp_itemsize */
- (destructor)matrix_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- (reprfunc)matrix_repr, /* tp_repr */
- &matrix_as_number, /* tp_as_number */
- &matrix_as_sequence, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- NULL, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- (richcmpfunc)matrix_richcmp, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- matrix_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* &PyBaseObject_Type, */ /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)matrix_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.Matrix", /* tp_name */
+ sizeof(PycairoMatrix), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ (destructor)matrix_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ (reprfunc)matrix_repr, /* tp_repr */
+ &matrix_as_number, /* tp_as_number */
+ &matrix_as_sequence, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ NULL, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ (richcmpfunc)matrix_richcmp, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ matrix_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PyBaseObject_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)matrix_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
};
diff --git a/src/pycairo-path.c b/src/pycairo-path.c
index 7473f14..53e706f 100644
--- a/src/pycairo-path.c
+++ b/src/pycairo-path.c
@@ -1,4 +1,4 @@
-/* -*- mode: C; c-basic-offset: 4 -*-
+/* -*- mode: C; c-basic-offset: 2 -*-
*
* Pycairo - Python bindings for cairo
*
@@ -49,289 +49,281 @@
* Return value: New reference or NULL on failure
*/
PyObject *
-PycairoPath_FromPath (cairo_path_t *path)
-{
- PyObject *o;
+PycairoPath_FromPath (cairo_path_t *path) {
+ PyObject *o;
- assert (path != NULL);
+ assert (path != NULL);
- if (Pycairo_Check_Status (path->status)) {
- cairo_path_destroy (path);
- return NULL;
- }
-
- o = PycairoPath_Type.tp_alloc (&PycairoPath_Type, 0);
- if (o)
- ((PycairoPath *)o)->path = path;
- else
- cairo_path_destroy (path);
- return o;
+ if (Pycairo_Check_Status (path->status)) {
+ cairo_path_destroy (path);
+ return NULL;
+ }
+
+ o = PycairoPath_Type.tp_alloc (&PycairoPath_Type, 0);
+ if (o)
+ ((PycairoPath *)o)->path = path;
+ else
+ cairo_path_destroy (path);
+ return o;
}
static void
-path_dealloc(PycairoPath *p)
-{
+path_dealloc(PycairoPath *p) {
#ifdef DEBUG
- printf("path_dealloc start\n");
+ printf("path_dealloc start\n");
#endif
- if (p->path) {
- cairo_path_destroy(p->path);
- p->path = NULL;
- }
- p->ob_type->tp_free((PyObject *)p);
+ if (p->path) {
+ cairo_path_destroy(p->path);
+ p->path = NULL;
+ }
+ p->ob_type->tp_free((PyObject *)p);
#ifdef DEBUG
- printf("path_dealloc end\n");
+ printf("path_dealloc end\n");
#endif
}
static PyObject *
-path_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- return type->tp_alloc(type, 0);
- /* initializes memory to zeros */
+path_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
+ return type->tp_alloc(type, 0);
+ /* initializes memory to zeros */
}
static int
-path_init(PycairoPath *p, PyObject *args, PyObject *kwds)
-{
- PyErr_SetString(PyExc_TypeError, "The Path type cannot be instantiated, "
- "use Context.copy_path()");
- return -1;
+path_init(PycairoPath *p, PyObject *args, PyObject *kwds) {
+ PyErr_SetString(PyExc_TypeError, "The Path type cannot be instantiated, "
+ "use Context.copy_path()");
+ return -1;
}
static PyObject *
-path_str(PycairoPath *p)
-{
- PyObject *s, *pieces = NULL, *result = NULL;
- cairo_path_t *path = p->path;
- cairo_path_data_t *data;
- int i, ret;
- char buf[80];
-
- pieces = PyList_New(0);
- if (pieces == NULL)
+path_str(PycairoPath *p) {
+ PyObject *s, *pieces = NULL, *result = NULL;
+ cairo_path_t *path = p->path;
+ cairo_path_data_t *data;
+ int i, ret;
+ char buf[80];
+
+ pieces = PyList_New(0);
+ if (pieces == NULL)
+ goto Done;
+
+ /* loop reading elements */
+ for (i=0; i < path->num_data; i += path->data[i].header.length) {
+ data = &path->data[i];
+ switch (data->header.type) {
+
+ case CAIRO_PATH_MOVE_TO:
+ PyOS_snprintf(buf, sizeof(buf), "move_to %f %f",
+ data[1].point.x, data[1].point.y);
+ s = PyString_FromString(buf);
+ if (!s)
+ goto Done;
+ ret = PyList_Append(pieces, s);
+ Py_DECREF(s);
+ if (ret < 0)
goto Done;
+ break;
- /* loop reading elements */
- for (i=0; i < path->num_data; i += path->data[i].header.length) {
- data = &path->data[i];
- switch (data->header.type) {
-
- case CAIRO_PATH_MOVE_TO:
- PyOS_snprintf(buf, sizeof(buf), "move_to %f %f",
- data[1].point.x, data[1].point.y);
- s = PyString_FromString(buf);
- if (!s)
- goto Done;
- ret = PyList_Append(pieces, s);
- Py_DECREF(s);
- if (ret < 0)
- goto Done;
- break;
-
- case CAIRO_PATH_LINE_TO:
- PyOS_snprintf(buf, sizeof(buf), "line_to %f %f",
- data[1].point.x, data[1].point.y);
- s = PyString_FromString(buf);
- if (!s)
- goto Done;
- ret = PyList_Append(pieces, s);
- Py_DECREF(s);
- if (ret < 0)
- goto Done;
- break;
-
- case CAIRO_PATH_CURVE_TO:
- PyOS_snprintf(buf, sizeof(buf), "curve_to %f %f %f %f %f %f",
- data[1].point.x, data[1].point.y,
- data[2].point.x, data[2].point.y,
- data[3].point.x, data[3].point.y);
- s = PyString_FromString(buf);
- if (!s)
- goto Done;
- ret = PyList_Append(pieces, s);
- Py_DECREF(s);
- if (ret < 0)
- goto Done;
- break;
-
- case CAIRO_PATH_CLOSE_PATH:
- s = PyString_FromString("close path");
- if (!s)
- goto Done;
- ret = PyList_Append(pieces, s);
- Py_DECREF(s);
- if (ret < 0)
- goto Done;
- break;
- }
- }
- /* result = "\n".join(pieces) */
- s = PyString_FromString("\n");
- if (s == NULL)
+ case CAIRO_PATH_LINE_TO:
+ PyOS_snprintf(buf, sizeof(buf), "line_to %f %f",
+ data[1].point.x, data[1].point.y);
+ s = PyString_FromString(buf);
+ if (!s)
+ goto Done;
+ ret = PyList_Append(pieces, s);
+ Py_DECREF(s);
+ if (ret < 0)
+ goto Done;
+ break;
+
+ case CAIRO_PATH_CURVE_TO:
+ PyOS_snprintf(buf, sizeof(buf), "curve_to %f %f %f %f %f %f",
+ data[1].point.x, data[1].point.y,
+ data[2].point.x, data[2].point.y,
+ data[3].point.x, data[3].point.y);
+ s = PyString_FromString(buf);
+ if (!s)
+ goto Done;
+ ret = PyList_Append(pieces, s);
+ Py_DECREF(s);
+ if (ret < 0)
+ goto Done;
+ break;
+
+ case CAIRO_PATH_CLOSE_PATH:
+ s = PyString_FromString("close path");
+ if (!s)
+ goto Done;
+ ret = PyList_Append(pieces, s);
+ Py_DECREF(s);
+ if (ret < 0)
goto Done;
- result = _PyString_Join(s, pieces);
- Py_DECREF(s);
+ break;
+ }
+ }
+ /* result = "\n".join(pieces) */
+ s = PyString_FromString("\n");
+ if (s == NULL)
+ goto Done;
+ result = _PyString_Join(s, pieces);
+ Py_DECREF(s);
Done:
- Py_XDECREF(pieces);
- return result;
+ Py_XDECREF(pieces);
+ return result;
}
static PyObject * path_iter(PyObject *seq); /* forward declaration */
PyTypeObject PycairoPath_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "cairo.Path", /* tp_name */
- sizeof(PycairoPath), /* tp_basicsize */
- 0, /* tp_itemsize */
- (destructor)path_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- (reprfunc)path_str, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- (getiterfunc)path_iter, /* tp_iter */
- 0, /* tp_iternext */
- 0, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* &PyBaseObject_Type, */ /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)path_init, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)path_new, /* tp_new */
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.Path", /* tp_name */
+ sizeof(PycairoPath), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ (destructor)path_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ (reprfunc)path_str, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ (getiterfunc)path_iter, /* tp_iter */
+ 0, /* tp_iternext */
+ 0, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PyBaseObject_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)path_init, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)path_new, /* tp_new */
};
/*********************** PycairoPath Iterator **************************/
typedef struct {
- PyObject_HEAD
- int index; /* position within PycairoPath */
- PycairoPath *pypath; /* Set to NULL when iterator is exhausted */
+ PyObject_HEAD
+ int index; /* position within PycairoPath */
+ PycairoPath *pypath; /* Set to NULL when iterator is exhausted */
} PycairoPathiter;
PyTypeObject PycairoPathiter_Type;
static void
-pathiter_dealloc(PycairoPathiter *it)
-{
- Py_XDECREF(it->pypath);
- PyObject_Del(it);
+pathiter_dealloc(PycairoPathiter *it) {
+ Py_XDECREF(it->pypath);
+ PyObject_Del(it);
}
static PyObject *
-path_iter(PyObject *pypath)
-{
- PycairoPathiter *it;
+path_iter(PyObject *pypath) {
+ PycairoPathiter *it;
- if (!PyObject_TypeCheck (pypath, &PycairoPath_Type)) {
- PyErr_BadInternalCall();
- return NULL;
- }
- it = PyObject_New(PycairoPathiter, &PycairoPathiter_Type);
- if (it == NULL)
- return NULL;
-
- it->index = 0;
- Py_INCREF(pypath);
- it->pypath = (PycairoPath *)pypath;
- return (PyObject *) it;
+ if (!PyObject_TypeCheck (pypath, &PycairoPath_Type)) {
+ PyErr_BadInternalCall();
+ return NULL;
+ }
+ it = PyObject_New(PycairoPathiter, &PycairoPathiter_Type);
+ if (it == NULL)
+ return NULL;
+
+ it->index = 0;
+ Py_INCREF(pypath);
+ it->pypath = (PycairoPath *)pypath;
+ return (PyObject *) it;
}
static PyObject *
-pathiter_next(PycairoPathiter *it)
-{
- PycairoPath *pypath;
- cairo_path_t *path;
-
- assert(it != NULL);
- pypath = it->pypath;
- if (pypath == NULL)
- return NULL;
- assert (PyObject_TypeCheck (pypath, &PycairoPath_Type));
- path = pypath->path;
-
- /* return the next path element, advance index */
- if (it->index < path->num_data) {
- cairo_path_data_t *data = &path->data[it->index];
- int type = data->header.type;
-
- it->index += data[0].header.length;
-
- switch (type) {
- case CAIRO_PATH_MOVE_TO:
- case CAIRO_PATH_LINE_TO:
- return Py_BuildValue("(i(dd))", type,
- data[1].point.x, data[1].point.y);
- case CAIRO_PATH_CURVE_TO:
- return Py_BuildValue("(i(dddddd))", type,
- data[1].point.x, data[1].point.y,
- data[2].point.x, data[2].point.y,
- data[3].point.x, data[3].point.y);
- case CAIRO_PATH_CLOSE_PATH:
- return Py_BuildValue("i()", type);
- default:
- PyErr_SetString(PyExc_RuntimeError, "unknown CAIRO_PATH type");
- return NULL;
- }
- }
+pathiter_next(PycairoPathiter *it) {
+ PycairoPath *pypath;
+ cairo_path_t *path;
- /* iterator has no remaining items */
- Py_DECREF(pypath);
- it->pypath = NULL;
+ assert(it != NULL);
+ pypath = it->pypath;
+ if (pypath == NULL)
return NULL;
+ assert (PyObject_TypeCheck (pypath, &PycairoPath_Type));
+ path = pypath->path;
+
+ /* return the next path element, advance index */
+ if (it->index < path->num_data) {
+ cairo_path_data_t *data = &path->data[it->index];
+ int type = data->header.type;
+
+ it->index += data[0].header.length;
+
+ switch (type) {
+ case CAIRO_PATH_MOVE_TO:
+ case CAIRO_PATH_LINE_TO:
+ return Py_BuildValue("(i(dd))", type,
+ data[1].point.x, data[1].point.y);
+ case CAIRO_PATH_CURVE_TO:
+ return Py_BuildValue("(i(dddddd))", type,
+ data[1].point.x, data[1].point.y,
+ data[2].point.x, data[2].point.y,
+ data[3].point.x, data[3].point.y);
+ case CAIRO_PATH_CLOSE_PATH:
+ return Py_BuildValue("i()", type);
+ default:
+ PyErr_SetString(PyExc_RuntimeError, "unknown CAIRO_PATH type");
+ return NULL;
+ }
+ }
+
+ /* iterator has no remaining items */
+ Py_DECREF(pypath);
+ it->pypath = NULL;
+ return NULL;
}
PyTypeObject PycairoPathiter_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "cairo.Pathiter", /* tp_name */
- sizeof(PycairoPathiter), /* tp_basicsize */
- 0, /* tp_itemsize */
- (destructor)pathiter_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* PyObject_SelfIter, */ /* tp_iter */
- (iternextfunc)pathiter_next, /* tp_iternext */
- 0, /* tp_methods */
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.Pathiter", /* tp_name */
+ sizeof(PycairoPathiter), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ (destructor)pathiter_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* PyObject_SelfIter, */ /* tp_iter */
+ (iternextfunc)pathiter_next, /* tp_iternext */
+ 0, /* tp_methods */
};
diff --git a/src/pycairo-pattern.c b/src/pycairo-pattern.c
index 3a793f7..c6f5050 100644
--- a/src/pycairo-pattern.c
+++ b/src/pycairo-pattern.c
@@ -1,4 +1,4 @@
-/* -*- mode: C; c-basic-offset: 4 -*-
+/* -*- mode: C; c-basic-offset: 2 -*-
*
* Pycairo - Python bindings for cairo
*
@@ -55,564 +55,544 @@
* Return value: New reference or NULL on failure
*/
PyObject *
-PycairoPattern_FromPattern (cairo_pattern_t *pattern, PyObject *base)
-{
- PyTypeObject *type = NULL;
- PyObject *o;
-
- assert (pattern != NULL);
-
- if (Pycairo_Check_Status (cairo_pattern_status (pattern))) {
- cairo_pattern_destroy (pattern);
- return NULL;
- }
-
- switch (cairo_pattern_get_type (pattern)) {
- case CAIRO_PATTERN_TYPE_SOLID:
- type = &PycairoSolidPattern_Type;
- break;
- case CAIRO_PATTERN_TYPE_SURFACE:
- type = &PycairoSurfacePattern_Type;
- break;
- case CAIRO_PATTERN_TYPE_LINEAR:
- type = &PycairoLinearGradient_Type;
- break;
- case CAIRO_PATTERN_TYPE_RADIAL:
- type = &PycairoRadialGradient_Type;
- break;
- default:
- type = &PycairoPattern_Type;
- break;
- }
-
- o = type->tp_alloc(type, 0);
- if (o == NULL) {
- cairo_pattern_destroy (pattern);
- } else {
- ((PycairoPattern *)o)->pattern = pattern;
- Py_XINCREF(base);
- ((PycairoPattern *)o)->base = base;
- }
- return o;
+PycairoPattern_FromPattern (cairo_pattern_t *pattern, PyObject *base) {
+ PyTypeObject *type = NULL;
+ PyObject *o;
+
+ assert (pattern != NULL);
+
+ if (Pycairo_Check_Status (cairo_pattern_status (pattern))) {
+ cairo_pattern_destroy (pattern);
+ return NULL;
+ }
+
+ switch (cairo_pattern_get_type (pattern)) {
+ case CAIRO_PATTERN_TYPE_SOLID:
+ type = &PycairoSolidPattern_Type;
+ break;
+ case CAIRO_PATTERN_TYPE_SURFACE:
+ type = &PycairoSurfacePattern_Type;
+ break;
+ case CAIRO_PATTERN_TYPE_LINEAR:
+ type = &PycairoLinearGradient_Type;
+ break;
+ case CAIRO_PATTERN_TYPE_RADIAL:
+ type = &PycairoRadialGradient_Type;
+ break;
+ default:
+ type = &PycairoPattern_Type;
+ break;
+ }
+
+ o = type->tp_alloc(type, 0);
+ if (o == NULL) {
+ cairo_pattern_destroy (pattern);
+ } else {
+ ((PycairoPattern *)o)->pattern = pattern;
+ Py_XINCREF(base);
+ ((PycairoPattern *)o)->base = base;
+ }
+ return o;
}
static void
-pattern_dealloc (PycairoPattern *o)
-{
- if (o->pattern) {
- cairo_pattern_destroy (o->pattern);
- o->pattern = NULL;
- }
- Py_CLEAR(o->base);
-
- o->ob_type->tp_free((PyObject *)o);
+pattern_dealloc (PycairoPattern *o) {
+ if (o->pattern) {
+ cairo_pattern_destroy (o->pattern);
+ o->pattern = NULL;
+ }
+ Py_CLEAR(o->base);
+
+ o->ob_type->tp_free((PyObject *)o);
}
static PyObject *
-pattern_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PyErr_SetString(PyExc_TypeError,
- "The Pattern type cannot be instantiated");
- return NULL;
+pattern_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
+ PyErr_SetString(PyExc_TypeError,
+ "The Pattern type cannot be instantiated");
+ return NULL;
}
static PyObject *
-pattern_get_extend (PycairoPattern *o)
-{
- return PyInt_FromLong (cairo_pattern_get_extend (o->pattern));
+pattern_get_extend (PycairoPattern *o) {
+ return PyInt_FromLong (cairo_pattern_get_extend (o->pattern));
}
static PyObject *
-pattern_get_matrix (PycairoPattern *o)
-{
- cairo_matrix_t matrix;
- cairo_pattern_get_matrix (o->pattern, &matrix);
- return PycairoMatrix_FromMatrix (&matrix);
+pattern_get_matrix (PycairoPattern *o) {
+ cairo_matrix_t matrix;
+ cairo_pattern_get_matrix (o->pattern, &matrix);
+ return PycairoMatrix_FromMatrix (&matrix);
}
static PyObject *
-pattern_set_extend (PycairoPattern *o, PyObject *args)
-{
- int extend;
+pattern_set_extend (PycairoPattern *o, PyObject *args) {
+ int extend;
- if (!PyArg_ParseTuple(args, "i:Pattern.set_extend", &extend))
- return NULL;
+ if (!PyArg_ParseTuple(args, "i:Pattern.set_extend", &extend))
+ return NULL;
- cairo_pattern_set_extend (o->pattern, extend);
- Py_RETURN_NONE;
+ cairo_pattern_set_extend (o->pattern, extend);
+ Py_RETURN_NONE;
}
static PyObject *
-pattern_set_matrix (PycairoPattern *o, PyObject *args)
-{
- PycairoMatrix *m;
+pattern_set_matrix (PycairoPattern *o, PyObject *args) {
+ PycairoMatrix *m;
- if (!PyArg_ParseTuple (args, "O!:Pattern.set_matrix",
- &PycairoMatrix_Type, &m))
- return NULL;
+ if (!PyArg_ParseTuple (args, "O!:Pattern.set_matrix",
+ &PycairoMatrix_Type, &m))
+ return NULL;
- cairo_pattern_set_matrix (o->pattern, &m->matrix);
- Py_RETURN_NONE;
+ cairo_pattern_set_matrix (o->pattern, &m->matrix);
+ Py_RETURN_NONE;
}
static PyMethodDef pattern_methods[] = {
- /* methods never exposed in a language binding:
- * cairo_pattern_destroy()
- * cairo_pattern_get_type()
- * cairo_pattern_reference()
- *
- * cairo_pattern_status()
- * - not needed since Pycairo handles status checking
- */
- {"get_extend", (PyCFunction)pattern_get_extend, METH_NOARGS },
- {"get_matrix", (PyCFunction)pattern_get_matrix, METH_NOARGS },
- {"set_extend", (PyCFunction)pattern_set_extend, METH_VARARGS },
- {"set_matrix", (PyCFunction)pattern_set_matrix, METH_VARARGS },
- {NULL, NULL, 0, NULL},
+ /* methods never exposed in a language binding:
+ * cairo_pattern_destroy()
+ * cairo_pattern_get_type()
+ * cairo_pattern_reference()
+ *
+ * cairo_pattern_status()
+ * - not needed since Pycairo handles status checking
+ */
+ {"get_extend", (PyCFunction)pattern_get_extend, METH_NOARGS },
+ {"get_matrix", (PyCFunction)pattern_get_matrix, METH_NOARGS },
+ {"set_extend", (PyCFunction)pattern_set_extend, METH_VARARGS },
+ {"set_matrix", (PyCFunction)pattern_set_matrix, METH_VARARGS },
+ {NULL, NULL, 0, NULL},
};
PyTypeObject PycairoPattern_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "cairo.Pattern", /* tp_name */
- sizeof(PycairoPattern), /* tp_basicsize */
- 0, /* tp_itemsize */
- (destructor)pattern_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,/* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- pattern_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* &PyBaseObject_Type, */ /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)pattern_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.Pattern", /* tp_name */
+ sizeof(PycairoPattern), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ (destructor)pattern_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,/* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ pattern_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PyBaseObject_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)pattern_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
};
/* Class SolidPattern ----------------------------------------------------- */
static PyObject *
-solid_pattern_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- double r, g, b, a = 1.0;
- if (!PyArg_ParseTuple (args, "ddd|d:SolidPattern.__new__", &r, &g, &b, &a))
- return NULL;
- return PycairoPattern_FromPattern (cairo_pattern_create_rgba (r, g, b, a),
- NULL);
+solid_pattern_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
+ double r, g, b, a = 1.0;
+ if (!PyArg_ParseTuple (args, "ddd|d:SolidPattern.__new__", &r, &g, &b, &a))
+ return NULL;
+ return PycairoPattern_FromPattern (cairo_pattern_create_rgba (r, g, b, a),
+ NULL);
}
static PyObject *
-solid_pattern_get_rgba (PycairoSolidPattern *o)
-{
- double red, green, blue, alpha;
- cairo_pattern_get_rgba (o->pattern, &red, &green, &blue, &alpha);
- return Py_BuildValue("(dddd)", red, green, blue, alpha);
+solid_pattern_get_rgba (PycairoSolidPattern *o) {
+ double red, green, blue, alpha;
+ cairo_pattern_get_rgba (o->pattern, &red, &green, &blue, &alpha);
+ return Py_BuildValue("(dddd)", red, green, blue, alpha);
}
static PyMethodDef solid_pattern_methods[] = {
- {"get_rgba", (PyCFunction)solid_pattern_get_rgba, METH_NOARGS },
- {NULL, NULL, 0, NULL},
+ {"get_rgba", (PyCFunction)solid_pattern_get_rgba, METH_NOARGS },
+ {NULL, NULL, 0, NULL},
};
PyTypeObject PycairoSolidPattern_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "cairo.SolidPattern", /* tp_name */
- sizeof(PycairoSolidPattern), /* tp_basicsize */
- 0, /* tp_itemsize */
- 0, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- solid_pattern_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* &PyPattern_Type, */ /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)solid_pattern_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.SolidPattern", /* tp_name */
+ sizeof(PycairoSolidPattern), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ solid_pattern_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PyPattern_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)solid_pattern_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
};
/* Class SurfacePattern --------------------------------------------------- */
static PyObject *
-surface_pattern_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PycairoSurface *s;
- if (!PyArg_ParseTuple (args, "O!:SurfacePattern.__new__",
- &PycairoSurface_Type, &s))
- return NULL;
- return PycairoPattern_FromPattern (
- cairo_pattern_create_for_surface (s->surface), (PyObject *)s);
+surface_pattern_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
+ PycairoSurface *s;
+ if (!PyArg_ParseTuple (args, "O!:SurfacePattern.__new__",
+ &PycairoSurface_Type, &s))
+ return NULL;
+ return PycairoPattern_FromPattern (
+ cairo_pattern_create_for_surface (s->surface), (PyObject *)s);
}
static PyObject *
-surface_pattern_get_filter (PycairoSurfacePattern *o)
-{
- return PyInt_FromLong (cairo_pattern_get_filter (o->pattern));
+surface_pattern_get_filter (PycairoSurfacePattern *o) {
+ return PyInt_FromLong (cairo_pattern_get_filter (o->pattern));
}
static PyObject *
-surface_pattern_get_surface (PycairoSurfacePattern *o)
-{
- /*
+surface_pattern_get_surface (PycairoSurfacePattern *o) {
+ /*
cairo_surface_t *surface;
cairo_pattern_get_surface (o->pattern, &surface);
return PycairoSurface_FromSurface (
- cairo_surface_reference (surface), NULL);
- */
- /* return the surface used to create the pattern */
- return Py_BuildValue("O", o->base);
+ cairo_surface_reference (surface), NULL);
+ */
+ /* return the surface used to create the pattern */
+ return Py_BuildValue("O", o->base);
}
static PyObject *
-surface_pattern_set_filter (PycairoSurfacePattern *o, PyObject *args)
-{
- int filter;
+surface_pattern_set_filter (PycairoSurfacePattern *o, PyObject *args) {
+ int filter;
- if (!PyArg_ParseTuple (args, "i:SurfacePattern.set_filter", &filter))
- return NULL;
+ if (!PyArg_ParseTuple (args, "i:SurfacePattern.set_filter", &filter))
+ return NULL;
- cairo_pattern_set_filter (o->pattern, filter);
- Py_RETURN_NONE;
+ cairo_pattern_set_filter (o->pattern, filter);
+ Py_RETURN_NONE;
}
static PyMethodDef surface_pattern_methods[] = {
- {"get_filter", (PyCFunction)surface_pattern_get_filter, METH_NOARGS },
- {"get_surface", (PyCFunction)surface_pattern_get_surface, METH_NOARGS },
- {"set_filter", (PyCFunction)surface_pattern_set_filter, METH_VARARGS },
- {NULL, NULL, 0, NULL},
+ {"get_filter", (PyCFunction)surface_pattern_get_filter, METH_NOARGS },
+ {"get_surface", (PyCFunction)surface_pattern_get_surface, METH_NOARGS },
+ {"set_filter", (PyCFunction)surface_pattern_set_filter, METH_VARARGS },
+ {NULL, NULL, 0, NULL},
};
PyTypeObject PycairoSurfacePattern_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "cairo.SurfacePattern", /* tp_name */
- sizeof(PycairoSurfacePattern), /* tp_basicsize */
- 0, /* tp_itemsize */
- 0, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- surface_pattern_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* &PycairoPattern_Type, */ /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)surface_pattern_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.SurfacePattern", /* tp_name */
+ sizeof(PycairoSurfacePattern), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ surface_pattern_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PycairoPattern_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)surface_pattern_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
};
/* Class Gradient --------------------------------------------------------- */
static PyObject *
-gradient_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PyErr_SetString(PyExc_TypeError,
- "The Gradient type cannot be instantiated");
- return NULL;
+gradient_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
+ PyErr_SetString(PyExc_TypeError,
+ "The Gradient type cannot be instantiated");
+ return NULL;
}
static PyObject *
-gradient_add_color_stop_rgb (PycairoGradient *o, PyObject *args)
-{
- double offset, red, green, blue;
- if (!PyArg_ParseTuple(args, "dddd:Gradient.add_color_stop_rgb",
- &offset, &red, &green, &blue))
- return NULL;
- cairo_pattern_add_color_stop_rgb (o->pattern, offset, red, green, blue);
- RETURN_NULL_IF_CAIRO_PATTERN_ERROR(o->pattern);
- Py_RETURN_NONE;
+gradient_add_color_stop_rgb (PycairoGradient *o, PyObject *args) {
+ double offset, red, green, blue;
+ if (!PyArg_ParseTuple(args, "dddd:Gradient.add_color_stop_rgb",
+ &offset, &red, &green, &blue))
+ return NULL;
+ cairo_pattern_add_color_stop_rgb (o->pattern, offset, red, green, blue);
+ RETURN_NULL_IF_CAIRO_PATTERN_ERROR(o->pattern);
+ Py_RETURN_NONE;
}
static PyObject *
-gradient_add_color_stop_rgba (PycairoGradient *o, PyObject *args)
-{
- double offset, red, green, blue, alpha;
- if (!PyArg_ParseTuple(args, "ddddd:Gradient.add_color_stop_rgba",
- &offset, &red, &green, &blue, &alpha))
- return NULL;
- cairo_pattern_add_color_stop_rgba (o->pattern, offset, red,
- green, blue, alpha);
- RETURN_NULL_IF_CAIRO_PATTERN_ERROR(o->pattern);
- Py_RETURN_NONE;
+gradient_add_color_stop_rgba (PycairoGradient *o, PyObject *args) {
+ double offset, red, green, blue, alpha;
+ if (!PyArg_ParseTuple(args, "ddddd:Gradient.add_color_stop_rgba",
+ &offset, &red, &green, &blue, &alpha))
+ return NULL;
+ cairo_pattern_add_color_stop_rgba (o->pattern, offset, red,
+ green, blue, alpha);
+ RETURN_NULL_IF_CAIRO_PATTERN_ERROR(o->pattern);
+ Py_RETURN_NONE;
}
static PyMethodDef gradient_methods[] = {
- {"add_color_stop_rgb",(PyCFunction)gradient_add_color_stop_rgb,
- METH_VARARGS },
- {"add_color_stop_rgba",(PyCFunction)gradient_add_color_stop_rgba,
- METH_VARARGS },
- {NULL, NULL, 0, NULL},
+ {"add_color_stop_rgb",(PyCFunction)gradient_add_color_stop_rgb,
+ METH_VARARGS },
+ {"add_color_stop_rgba",(PyCFunction)gradient_add_color_stop_rgba,
+ METH_VARARGS },
+ {NULL, NULL, 0, NULL},
};
PyTypeObject PycairoGradient_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "cairo.Gradient", /* tp_name */
- sizeof(PycairoGradient), /* tp_basicsize */
- 0, /* tp_itemsize */
- 0, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,/* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- gradient_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* &PycairoPattern_Type, */ /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)gradient_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.Gradient", /* tp_name */
+ sizeof(PycairoGradient), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,/* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ gradient_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PycairoPattern_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)gradient_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
};
/* Class LinearGradient --------------------------------------------------- */
static PyObject *
-linear_gradient_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- double x0, y0, x1, y1;
- if (!PyArg_ParseTuple(args, "dddd:LinearGradient.__new__",
- &x0, &y0, &x1, &y1))
- return NULL;
- return PycairoPattern_FromPattern (
+linear_gradient_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
+ double x0, y0, x1, y1;
+ if (!PyArg_ParseTuple(args, "dddd:LinearGradient.__new__",
+ &x0, &y0, &x1, &y1))
+ return NULL;
+ return PycairoPattern_FromPattern (
cairo_pattern_create_linear (x0, y0, x1, y1), NULL);
}
static PyObject *
-linear_gradient_get_linear_points (PycairoLinearGradient *o)
-{
- double x0, y0, x1, y1;
- cairo_pattern_get_linear_points (o->pattern, &x0, &y0, &x1, &y1);
- return Py_BuildValue("(dddd)", x0, y0, x1, y1);
+linear_gradient_get_linear_points (PycairoLinearGradient *o) {
+ double x0, y0, x1, y1;
+ cairo_pattern_get_linear_points (o->pattern, &x0, &y0, &x1, &y1);
+ return Py_BuildValue("(dddd)", x0, y0, x1, y1);
}
static PyMethodDef linear_gradient_methods[] = {
- {"get_linear_points", (PyCFunction)linear_gradient_get_linear_points,
- METH_NOARGS },
- {NULL, NULL, 0, NULL},
+ {"get_linear_points", (PyCFunction)linear_gradient_get_linear_points,
+ METH_NOARGS },
+ {NULL, NULL, 0, NULL},
};
PyTypeObject PycairoLinearGradient_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "cairo.LinearGradient", /* tp_name */
- sizeof(PycairoLinearGradient), /* tp_basicsize */
- 0, /* tp_itemsize */
- 0, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- linear_gradient_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* &PycairoGradient_Type, */ /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)linear_gradient_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.LinearGradient", /* tp_name */
+ sizeof(PycairoLinearGradient), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ linear_gradient_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PycairoGradient_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)linear_gradient_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
};
/* Class RadialGradient --------------------------------------------------- */
static PyObject *
-radial_gradient_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- double cx0, cy0, radius0, cx1, cy1, radius1;
- if (!PyArg_ParseTuple(args, "dddddd:RadialGradient.__new__",
- &cx0, &cy0, &radius0, &cx1, &cy1, &radius1))
- return NULL;
- return PycairoPattern_FromPattern (
+radial_gradient_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
+ double cx0, cy0, radius0, cx1, cy1, radius1;
+ if (!PyArg_ParseTuple(args, "dddddd:RadialGradient.__new__",
+ &cx0, &cy0, &radius0, &cx1, &cy1, &radius1))
+ return NULL;
+ return PycairoPattern_FromPattern (
cairo_pattern_create_radial (cx0, cy0, radius0, cx1, cy1, radius1),
NULL);
}
static PyObject *
-radial_gradient_get_radial_circles (PycairoRadialGradient *o)
-{
- double x0, y0, r0, x1, y1, r1;
- cairo_pattern_get_radial_circles (o->pattern, &x0, &y0, &r0,
- &x1, &y1, &r1);
- return Py_BuildValue("(dddddd)", x0, y0, r0, x1, y1, r1);
+radial_gradient_get_radial_circles (PycairoRadialGradient *o) {
+ double x0, y0, r0, x1, y1, r1;
+ cairo_pattern_get_radial_circles (o->pattern, &x0, &y0, &r0,
+ &x1, &y1, &r1);
+ return Py_BuildValue("(dddddd)", x0, y0, r0, x1, y1, r1);
}
static PyMethodDef radial_gradient_methods[] = {
- {"get_radial_circles", (PyCFunction)radial_gradient_get_radial_circles,
- METH_NOARGS },
- {NULL, NULL, 0, NULL},
+ {"get_radial_circles", (PyCFunction)radial_gradient_get_radial_circles,
+ METH_NOARGS },
+ {NULL, NULL, 0, NULL},
};
PyTypeObject PycairoRadialGradient_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "cairo.RadialGradient", /* tp_name */
- sizeof(PycairoRadialGradient), /* tp_basicsize */
- 0, /* tp_itemsize */
- 0, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- radial_gradient_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* &PycairoGradient_Type, */ /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)radial_gradient_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.RadialGradient", /* tp_name */
+ sizeof(PycairoRadialGradient), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ radial_gradient_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PycairoGradient_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)radial_gradient_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
};
diff --git a/src/pycairo-private.h b/src/pycairo-private.h
index d04e66e..5951104 100644
--- a/src/pycairo-private.h
+++ b/src/pycairo-private.h
@@ -1,4 +1,4 @@
-/* -*- mode: C; c-basic-offset: 4 -*-
+/* -*- mode: C; c-basic-offset: 2 -*-
*
* Pycairo - Python bindings for cairo
*
@@ -105,57 +105,57 @@ int Pycairo_Check_Status (cairo_status_t status);
/* error checking macros */
#define RETURN_NULL_IF_CAIRO_ERROR(status) \
- do { \
- if (status != CAIRO_STATUS_SUCCESS) { \
- Pycairo_Check_Status (status); \
- return NULL; \
- } \
- } while (0)
-
-#define RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(ctx) \
- do { \
- cairo_status_t status = cairo_status (ctx); \
- if (status != CAIRO_STATUS_SUCCESS) { \
- Pycairo_Check_Status (status); \
- return NULL; \
- } \
- } while (0)
-
-#define RETURN_NULL_IF_CAIRO_PATTERN_ERROR(pattern) \
- do { \
- cairo_status_t status = cairo_pattern_status (pattern); \
- if (status != CAIRO_STATUS_SUCCESS) { \
- Pycairo_Check_Status (status); \
- return NULL; \
- } \
- } while (0)
-
-#define RETURN_NULL_IF_CAIRO_SURFACE_ERROR(surface) \
- do { \
- cairo_status_t status = cairo_surface_status (surface); \
- if (status != CAIRO_STATUS_SUCCESS) { \
- Pycairo_Check_Status (status); \
- return NULL; \
- } \
- } while (0)
-
-#define RETURN_NULL_IF_CAIRO_SCALED_FONT_ERROR(sc_font) \
- do { \
- cairo_status_t status = cairo_scaled_font_status (sc_font); \
- if (status != CAIRO_STATUS_SUCCESS) { \
- Pycairo_Check_Status (status); \
- return NULL; \
- } \
- } while (0)
-
-#define RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(fo) \
- do { \
- cairo_status_t status = cairo_font_options_status (fo); \
- if (status != CAIRO_STATUS_SUCCESS) { \
- Pycairo_Check_Status (status); \
- return NULL; \
- } \
- } while (0)
+ do { \
+ if (status != CAIRO_STATUS_SUCCESS) { \
+ Pycairo_Check_Status (status); \
+ return NULL; \
+ } \
+ } while (0)
+
+#define RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(ctx) \
+ do { \
+ cairo_status_t status = cairo_status (ctx); \
+ if (status != CAIRO_STATUS_SUCCESS) { \
+ Pycairo_Check_Status (status); \
+ return NULL; \
+ } \
+ } while (0)
+
+#define RETURN_NULL_IF_CAIRO_PATTERN_ERROR(pattern) \
+ do { \
+ cairo_status_t status = cairo_pattern_status (pattern); \
+ if (status != CAIRO_STATUS_SUCCESS) { \
+ Pycairo_Check_Status (status); \
+ return NULL; \
+ } \
+ } while (0)
+
+#define RETURN_NULL_IF_CAIRO_SURFACE_ERROR(surface) \
+ do { \
+ cairo_status_t status = cairo_surface_status (surface); \
+ if (status != CAIRO_STATUS_SUCCESS) { \
+ Pycairo_Check_Status (status); \
+ return NULL; \
+ } \
+ } while (0)
+
+#define RETURN_NULL_IF_CAIRO_SCALED_FONT_ERROR(sc_font) \
+ do { \
+ cairo_status_t status = cairo_scaled_font_status (sc_font); \
+ if (status != CAIRO_STATUS_SUCCESS) { \
+ Pycairo_Check_Status (status); \
+ return NULL; \
+ } \
+ } while (0)
+
+#define RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(fo) \
+ do { \
+ cairo_status_t status = cairo_font_options_status (fo); \
+ if (status != CAIRO_STATUS_SUCCESS) { \
+ Pycairo_Check_Status (status); \
+ return NULL; \
+ } \
+ } while (0)
#endif /* _PYCAIRO_PRIVATE_H_ */
diff --git a/src/pycairo-surface.c b/src/pycairo-surface.c
index b4a4a2d..71c191a 100644
--- a/src/pycairo-surface.c
+++ b/src/pycairo-surface.c
@@ -1,4 +1,4 @@
-/* -*- mode: C; c-basic-offset: 4 -*-
+/* -*- mode: C; c-basic-offset: 2 -*-
*
* Pycairo - Python bindings for cairo
*
@@ -56,62 +56,61 @@
* Return value: New reference or NULL on failure
*/
PyObject *
-PycairoSurface_FromSurface (cairo_surface_t *surface, PyObject *base)
-{
- PyTypeObject *type = NULL;
- PyObject *o;
+PycairoSurface_FromSurface (cairo_surface_t *surface, PyObject *base) {
+ PyTypeObject *type = NULL;
+ PyObject *o;
- assert (surface != NULL);
+ assert (surface != NULL);
- if (Pycairo_Check_Status (cairo_surface_status (surface))) {
- cairo_surface_destroy (surface);
- return NULL;
- }
+ if (Pycairo_Check_Status (cairo_surface_status (surface))) {
+ cairo_surface_destroy (surface);
+ return NULL;
+ }
- switch (cairo_surface_get_type (surface)) {
+ switch (cairo_surface_get_type (surface)) {
#if CAIRO_HAS_IMAGE_SURFACE
- case CAIRO_SURFACE_TYPE_IMAGE:
- type = &PycairoImageSurface_Type;
- break;
+ case CAIRO_SURFACE_TYPE_IMAGE:
+ type = &PycairoImageSurface_Type;
+ break;
#endif
#if CAIRO_HAS_PDF_SURFACE
- case CAIRO_SURFACE_TYPE_PDF:
- type = &PycairoPDFSurface_Type;
- break;
+ case CAIRO_SURFACE_TYPE_PDF:
+ type = &PycairoPDFSurface_Type;
+ break;
#endif
#if CAIRO_HAS_PS_SURFACE
- case CAIRO_SURFACE_TYPE_PS:
- type = &PycairoPSSurface_Type;
- break;
+ case CAIRO_SURFACE_TYPE_PS:
+ type = &PycairoPSSurface_Type;
+ break;
#endif
#if CAIRO_HAS_SVG_SURFACE
- case CAIRO_SURFACE_TYPE_SVG:
- type = &PycairoSVGSurface_Type;
- break;
+ case CAIRO_SURFACE_TYPE_SVG:
+ type = &PycairoSVGSurface_Type;
+ break;
#endif
#if CAIRO_HAS_WIN32_SURFACE
- case CAIRO_SURFACE_TYPE_WIN32:
- type = &PycairoWin32Surface_Type;
- break;
+ case CAIRO_SURFACE_TYPE_WIN32:
+ type = &PycairoWin32Surface_Type;
+ break;
#endif
#if CAIRO_HAS_XLIB_SURFACE
- case CAIRO_SURFACE_TYPE_XLIB:
- type = &PycairoXlibSurface_Type;
- break;
+ case CAIRO_SURFACE_TYPE_XLIB:
+ type = &PycairoXlibSurface_Type;
+ break;
#endif
- default:
- type = &PycairoSurface_Type;
- break;
- }
- o = type->tp_alloc (type, 0);
- if (o == NULL) {
- cairo_surface_destroy (surface);
- } else {
- ((PycairoSurface *)o)->surface = surface;
- Py_XINCREF(base);
- ((PycairoSurface *)o)->base = base;
- }
- return o;
+ default:
+ type = &PycairoSurface_Type;
+ break;
+ }
+ o = type->tp_alloc (type, 0);
+ if (o == NULL) {
+ cairo_surface_destroy (surface);
+ } else {
+ ((PycairoSurface *)o)->surface = surface;
+ Py_XINCREF(base);
+ ((PycairoSurface *)o)->base = base;
+ }
+ return o;
}
/* for use with
@@ -119,284 +118,267 @@ PycairoSurface_FromSurface (cairo_surface_t *surface, PyObject *base)
* cairo_pdf/ps/svg_surface_create_for_stream()
*/
static cairo_status_t
-_write_func (void *closure, const unsigned char *data, unsigned int length)
-{
- PyGILState_STATE gstate = PyGILState_Ensure();
- PyObject *res = PyObject_CallMethod ((PyObject *)closure, "write", "(s#)",
- data, (Py_ssize_t)length);
- if (res == NULL) {
- /* an exception has occurred, it will be picked up later by
- * Pycairo_Check_Status()
- */
- PyGILState_Release(gstate);
- return CAIRO_STATUS_WRITE_ERROR;
- }
- Py_DECREF(res);
+_write_func (void *closure, const unsigned char *data, unsigned int length) {
+ PyGILState_STATE gstate = PyGILState_Ensure();
+ PyObject *res = PyObject_CallMethod ((PyObject *)closure, "write", "(s#)",
+ data, (Py_ssize_t)length);
+ if (res == NULL) {
+ /* an exception has occurred, it will be picked up later by
+ * Pycairo_Check_Status()
+ */
PyGILState_Release(gstate);
- return CAIRO_STATUS_SUCCESS;
+ return CAIRO_STATUS_WRITE_ERROR;
+ }
+ Py_DECREF(res);
+ PyGILState_Release(gstate);
+ return CAIRO_STATUS_SUCCESS;
}
static void
-surface_dealloc (PycairoSurface *o)
-{
- if (o->surface) {
- cairo_surface_destroy(o->surface);
- o->surface = NULL;
- }
- Py_CLEAR(o->base);
-
- o->ob_type->tp_free((PyObject *)o);
+surface_dealloc (PycairoSurface *o) {
+ if (o->surface) {
+ cairo_surface_destroy(o->surface);
+ o->surface = NULL;
+ }
+ Py_CLEAR(o->base);
+
+ o->ob_type->tp_free((PyObject *)o);
}
static PyObject *
-surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PyErr_SetString(PyExc_TypeError,
- "The Surface type cannot be instantiated");
- return NULL;
+surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
+ PyErr_SetString(PyExc_TypeError,
+ "The Surface type cannot be instantiated");
+ return NULL;
}
static PyObject *
-surface_copy_page (PycairoSurface *o)
-{
- Py_BEGIN_ALLOW_THREADS
- cairo_surface_copy_page (o->surface);
- Py_END_ALLOW_THREADS
- RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
- Py_RETURN_NONE;
+surface_copy_page (PycairoSurface *o) {
+ Py_BEGIN_ALLOW_THREADS;
+ cairo_surface_copy_page (o->surface);
+ Py_END_ALLOW_THREADS;
+ RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
+ Py_RETURN_NONE;
}
static PyObject *
-surface_create_similar (PycairoSurface *o, PyObject *args)
-{
- cairo_content_t content;
- int width, height;
-
- if (!PyArg_ParseTuple (args, "iii:Surface.create_similar",
- &content, &width, &height))
- return NULL;
- return PycairoSurface_FromSurface (
+surface_create_similar (PycairoSurface *o, PyObject *args) {
+ cairo_content_t content;
+ int width, height;
+
+ if (!PyArg_ParseTuple (args, "iii:Surface.create_similar",
+ &content, &width, &height))
+ return NULL;
+ return PycairoSurface_FromSurface (
cairo_surface_create_similar (o->surface, content, width, height),
NULL);
}
static PyObject *
-surface_finish (PycairoSurface *o)
-{
- cairo_surface_finish (o->surface);
- Py_CLEAR(o->base);
- RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
- Py_RETURN_NONE;
+surface_finish (PycairoSurface *o) {
+ cairo_surface_finish (o->surface);
+ Py_CLEAR(o->base);
+ RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
+ Py_RETURN_NONE;
}
static PyObject *
-surface_flush (PycairoSurface *o)
-{
- Py_BEGIN_ALLOW_THREADS
- cairo_surface_flush (o->surface);
- Py_END_ALLOW_THREADS
- RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
- Py_RETURN_NONE;
+surface_flush (PycairoSurface *o) {
+ Py_BEGIN_ALLOW_THREADS;
+ cairo_surface_flush (o->surface);
+ Py_END_ALLOW_THREADS;
+ RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
+ Py_RETURN_NONE;
}
static PyObject *
-surface_get_content (PycairoSurface *o)
-{
- return PyInt_FromLong (cairo_surface_get_content (o->surface));
+surface_get_content (PycairoSurface *o) {
+ return PyInt_FromLong (cairo_surface_get_content (o->surface));
}
static PyObject *
-surface_get_device_offset (PycairoSurface *o)
-{
- double x_offset, y_offset;
- cairo_surface_get_device_offset (o->surface, &x_offset, &y_offset);
- return Py_BuildValue("(dd)", x_offset, y_offset);
+surface_get_device_offset (PycairoSurface *o) {
+ double x_offset, y_offset;
+ cairo_surface_get_device_offset (o->surface, &x_offset, &y_offset);
+ return Py_BuildValue("(dd)", x_offset, y_offset);
}
static PyObject *
-surface_get_fallback_resolution (PycairoSurface *o)
-{
- double x_ppi, y_ppi;
- cairo_surface_get_fallback_resolution (o->surface, &x_ppi, &y_ppi);
- return Py_BuildValue("(dd)", x_ppi, y_ppi);
+surface_get_fallback_resolution (PycairoSurface *o) {
+ double x_ppi, y_ppi;
+ cairo_surface_get_fallback_resolution (o->surface, &x_ppi, &y_ppi);
+ return Py_BuildValue("(dd)", x_ppi, y_ppi);
}
static PyObject *
-surface_get_font_options (PycairoSurface *o)
-{
- cairo_font_options_t *options = cairo_font_options_create();
+surface_get_font_options (PycairoSurface *o) {
+ cairo_font_options_t *options = cairo_font_options_create();
- cairo_surface_get_font_options (o->surface, options);
- /* there is no reference fn */
- return PycairoFontOptions_FromFontOptions (options);
+ cairo_surface_get_font_options (o->surface, options);
+ /* there is no reference fn */
+ return PycairoFontOptions_FromFontOptions (options);
}
static PyObject *
-surface_mark_dirty (PycairoSurface *o)
-{
- cairo_surface_mark_dirty (o->surface);
- RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
- Py_RETURN_NONE;
+surface_mark_dirty (PycairoSurface *o) {
+ cairo_surface_mark_dirty (o->surface);
+ RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
+ Py_RETURN_NONE;
}
static PyObject *
-surface_mark_dirty_rectangle (PycairoSurface *o, PyObject *args)
-{
- int x, y, width, height;
+surface_mark_dirty_rectangle (PycairoSurface *o, PyObject *args) {
+ int x, y, width, height;
- if (!PyArg_ParseTuple(args, "iiii:Surface.mark_dirty_rectangle",
- &x, &y, &width, &height))
- return NULL;
+ if (!PyArg_ParseTuple(args, "iiii:Surface.mark_dirty_rectangle",
+ &x, &y, &width, &height))
+ return NULL;
- cairo_surface_mark_dirty_rectangle (o->surface, x, y, width, height);
- RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
- Py_RETURN_NONE;
+ cairo_surface_mark_dirty_rectangle (o->surface, x, y, width, height);
+ RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
+ Py_RETURN_NONE;
}
static PyObject *
-surface_set_device_offset (PycairoSurface *o, PyObject *args)
-{
- double x_offset, y_offset;
+surface_set_device_offset (PycairoSurface *o, PyObject *args) {
+ double x_offset, y_offset;
- if (!PyArg_ParseTuple (args, "dd:Surface.set_device_offset",
- &x_offset, &y_offset))
- return NULL;
+ if (!PyArg_ParseTuple (args, "dd:Surface.set_device_offset",
+ &x_offset, &y_offset))
+ return NULL;
- cairo_surface_set_device_offset (o->surface, x_offset, y_offset);
- Py_RETURN_NONE;
+ cairo_surface_set_device_offset (o->surface, x_offset, y_offset);
+ Py_RETURN_NONE;
}
static PyObject *
-surface_set_fallback_resolution (PycairoSurface *o, PyObject *args)
-{
- double x_ppi, y_ppi;
-
- if (!PyArg_ParseTuple(args, "dd:Surface.set_fallback_resolution",
- &x_ppi, &y_ppi))
- return NULL;
- cairo_surface_set_fallback_resolution (o->surface, x_ppi, y_ppi);
- Py_RETURN_NONE;
+surface_set_fallback_resolution (PycairoSurface *o, PyObject *args) {
+ double x_ppi, y_ppi;
+
+ if (!PyArg_ParseTuple(args, "dd:Surface.set_fallback_resolution",
+ &x_ppi, &y_ppi))
+ return NULL;
+ cairo_surface_set_fallback_resolution (o->surface, x_ppi, y_ppi);
+ Py_RETURN_NONE;
}
static PyObject *
-surface_show_page (PycairoSurface *o)
-{
- Py_BEGIN_ALLOW_THREADS
- cairo_surface_show_page (o->surface);
- Py_END_ALLOW_THREADS
- RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
- Py_RETURN_NONE;
+surface_show_page (PycairoSurface *o) {
+ Py_BEGIN_ALLOW_THREADS;
+ cairo_surface_show_page (o->surface);
+ Py_END_ALLOW_THREADS;
+ RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
+ Py_RETURN_NONE;
}
#ifdef CAIRO_HAS_PNG_FUNCTIONS
/* METH_O */
static PyObject *
-surface_write_to_png (PycairoSurface *o, PyObject *file)
-{
- cairo_status_t status;
-
- if (PyObject_TypeCheck (file, &PyBaseString_Type)) {
- /* string (filename) argument */
- Py_BEGIN_ALLOW_THREADS
- status = cairo_surface_write_to_png (o->surface,
- PyString_AsString(file));
- Py_END_ALLOW_THREADS
-
- } else { /* file or file-like object argument */
- PyObject* writer = PyObject_GetAttrString (file, "write");
- if (writer == NULL || !PyCallable_Check (writer)) {
- Py_XDECREF(writer);
- PyErr_SetString(PyExc_TypeError,
+surface_write_to_png (PycairoSurface *o, PyObject *file) {
+ cairo_status_t status;
+
+ if (PyObject_TypeCheck (file, &PyBaseString_Type)) {
+ /* string (filename) argument */
+ Py_BEGIN_ALLOW_THREADS;
+ status = cairo_surface_write_to_png (o->surface,
+ PyString_AsString(file));
+ Py_END_ALLOW_THREADS;
+
+ } else { /* file or file-like object argument */
+ PyObject* writer = PyObject_GetAttrString (file, "write");
+ if (writer == NULL || !PyCallable_Check (writer)) {
+ Py_XDECREF(writer);
+ PyErr_SetString(PyExc_TypeError,
"Surface.write_to_png takes one argument which must be a filename (str), file "
"object, or a file-like object which has a \"write\" method (like StringIO)");
- return NULL;
- }
- Py_DECREF(writer);
- Py_BEGIN_ALLOW_THREADS
- status = cairo_surface_write_to_png_stream (o->surface, _write_func,
- file);
- Py_END_ALLOW_THREADS
+ return NULL;
}
- RETURN_NULL_IF_CAIRO_ERROR(status);
- Py_RETURN_NONE;
+ Py_DECREF(writer);
+ Py_BEGIN_ALLOW_THREADS;
+ status = cairo_surface_write_to_png_stream (o->surface, _write_func,
+ file);
+ Py_END_ALLOW_THREADS;
+ }
+ RETURN_NULL_IF_CAIRO_ERROR(status);
+ Py_RETURN_NONE;
}
#endif /* CAIRO_HAS_PNG_FUNCTIONS */
static PyMethodDef surface_methods[] = {
- /* methods never exposed in a language binding:
- * cairo_surface_destroy()
- * cairo_surface_get_type()
- * cairo_surface_get_user_data()
- * cairo_surface_reference()
- * cairo_surface_set_user_data()
- */
- {"copy_page", (PyCFunction)surface_copy_page, METH_NOARGS},
- {"create_similar", (PyCFunction)surface_create_similar, METH_VARARGS},
- {"finish", (PyCFunction)surface_finish, METH_NOARGS},
- {"flush", (PyCFunction)surface_flush, METH_NOARGS},
- {"get_content", (PyCFunction)surface_get_content, METH_NOARGS},
- {"get_device_offset",(PyCFunction)surface_get_device_offset,METH_NOARGS},
- {"get_fallback_resolution",(PyCFunction)surface_get_fallback_resolution,
- METH_NOARGS},
- {"get_font_options",(PyCFunction)surface_get_font_options, METH_NOARGS},
- {"mark_dirty", (PyCFunction)surface_mark_dirty, METH_NOARGS},
- {"mark_dirty_rectangle", (PyCFunction)surface_mark_dirty_rectangle,
- METH_VARARGS},
- {"set_device_offset",(PyCFunction)surface_set_device_offset,METH_VARARGS},
- {"set_fallback_resolution",(PyCFunction)surface_set_fallback_resolution,
- METH_VARARGS},
- {"show_page", (PyCFunction)surface_show_page, METH_NOARGS},
+ /* methods never exposed in a language binding:
+ * cairo_surface_destroy()
+ * cairo_surface_get_type()
+ * cairo_surface_get_user_data()
+ * cairo_surface_reference()
+ * cairo_surface_set_user_data()
+ */
+ {"copy_page", (PyCFunction)surface_copy_page, METH_NOARGS},
+ {"create_similar", (PyCFunction)surface_create_similar, METH_VARARGS},
+ {"finish", (PyCFunction)surface_finish, METH_NOARGS},
+ {"flush", (PyCFunction)surface_flush, METH_NOARGS},
+ {"get_content", (PyCFunction)surface_get_content, METH_NOARGS},
+ {"get_device_offset",(PyCFunction)surface_get_device_offset,METH_NOARGS},
+ {"get_fallback_resolution",(PyCFunction)surface_get_fallback_resolution,
+ METH_NOARGS},
+ {"get_font_options",(PyCFunction)surface_get_font_options, METH_NOARGS},
+ {"mark_dirty", (PyCFunction)surface_mark_dirty, METH_NOARGS},
+ {"mark_dirty_rectangle", (PyCFunction)surface_mark_dirty_rectangle,
+ METH_VARARGS},
+ {"set_device_offset",(PyCFunction)surface_set_device_offset,METH_VARARGS},
+ {"set_fallback_resolution",(PyCFunction)surface_set_fallback_resolution,
+ METH_VARARGS},
+ {"show_page", (PyCFunction)surface_show_page, METH_NOARGS},
#ifdef CAIRO_HAS_PNG_FUNCTIONS
- {"write_to_png", (PyCFunction)surface_write_to_png, METH_O },
+ {"write_to_png", (PyCFunction)surface_write_to_png, METH_O },
#endif
- {NULL, NULL, 0, NULL},
+ {NULL, NULL, 0, NULL},
};
PyTypeObject PycairoSurface_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "cairo.Surface", /* tp_name */
- sizeof(PycairoSurface), /* tp_basicsize */
- 0, /* tp_itemsize */
- (destructor)surface_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,/* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- surface_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* &PyBaseObject_Type, */ /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)surface_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.Surface", /* tp_name */
+ sizeof(PycairoSurface), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ (destructor)surface_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,/* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ surface_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PyBaseObject_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)surface_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
};
@@ -404,289 +386,276 @@ PyTypeObject PycairoSurface_Type = {
#ifdef CAIRO_HAS_IMAGE_SURFACE
static PyObject *
-image_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- cairo_format_t format;
- int width, height;
-
- if (!PyArg_ParseTuple (args, "iii:ImageSurface.__new__",
- &format, &width, &height))
- return NULL;
- return PycairoSurface_FromSurface (
- cairo_image_surface_create (format, width, height),
- NULL);
+image_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
+ cairo_format_t format;
+ int width, height;
+
+ if (!PyArg_ParseTuple (args, "iii:ImageSurface.__new__",
+ &format, &width, &height))
+ return NULL;
+ return PycairoSurface_FromSurface (
+ cairo_image_surface_create (format, width, height),
+ NULL);
}
static PyObject *
-image_surface_create_for_data (PyTypeObject *type, PyObject *args)
-{
- cairo_surface_t *surface;
- cairo_format_t format;
- unsigned char *buffer;
- int width, height, stride = -1, res;
- Py_ssize_t buffer_len;
- PyObject *obj;
-
- if (!PyArg_ParseTuple(args, "Oiii|i:Surface.create_for_data",
- &obj, &format, &width, &height, &stride))
- return NULL;
-
- res = PyObject_AsWriteBuffer (obj, (void **)&buffer, &buffer_len);
- if (res == -1)
- return NULL;
-
- if (width <= 0) {
- PyErr_SetString(PyExc_ValueError, "width must be positive");
- return NULL;
- }
- if (height <= 0) {
- PyErr_SetString(PyExc_ValueError, "height must be positive");
- return NULL;
- }
- /* if stride is missing, calculate it from width */
- if (stride < 0) {
- stride = cairo_format_stride_for_width (format, width);
- if (stride == -1){
- PyErr_SetString(CairoError,
- "format is invalid or the width too large");
- return NULL;
- }
- }
- if (height * stride > buffer_len) {
- PyErr_SetString(PyExc_TypeError, "buffer is not long enough");
- return NULL;
+image_surface_create_for_data (PyTypeObject *type, PyObject *args) {
+ cairo_surface_t *surface;
+ cairo_format_t format;
+ unsigned char *buffer;
+ int width, height, stride = -1, res;
+ Py_ssize_t buffer_len;
+ PyObject *obj;
+
+ if (!PyArg_ParseTuple(args, "Oiii|i:Surface.create_for_data",
+ &obj, &format, &width, &height, &stride))
+ return NULL;
+
+ res = PyObject_AsWriteBuffer (obj, (void **)&buffer, &buffer_len);
+ if (res == -1)
+ return NULL;
+
+ if (width <= 0) {
+ PyErr_SetString(PyExc_ValueError, "width must be positive");
+ return NULL;
+ }
+ if (height <= 0) {
+ PyErr_SetString(PyExc_ValueError, "height must be positive");
+ return NULL;
+ }
+ /* if stride is missing, calculate it from width */
+ if (stride < 0) {
+ stride = cairo_format_stride_for_width (format, width);
+ if (stride == -1){
+ PyErr_SetString(CairoError,
+ "format is invalid or the width too large");
+ return NULL;
}
- Py_BEGIN_ALLOW_THREADS
- surface = cairo_image_surface_create_for_data (buffer, format, width,
- height, stride);
- Py_END_ALLOW_THREADS
- return PycairoSurface_FromSurface(surface, obj);
+ }
+ if (height * stride > buffer_len) {
+ PyErr_SetString(PyExc_TypeError, "buffer is not long enough");
+ return NULL;
+ }
+ Py_BEGIN_ALLOW_THREADS;
+ surface = cairo_image_surface_create_for_data (buffer, format, width,
+ height, stride);
+ Py_END_ALLOW_THREADS;
+ return PycairoSurface_FromSurface(surface, obj);
}
#ifdef CAIRO_HAS_PNG_FUNCTIONS
static cairo_status_t
-_read_func (void *closure, unsigned char *data, unsigned int length)
-{
- char *buffer;
- Py_ssize_t str_length;
- cairo_status_t status = CAIRO_STATUS_READ_ERROR;
- PyGILState_STATE gstate = PyGILState_Ensure();
- PyObject *pystr = PyObject_CallMethod ((PyObject *)closure, "read", "(i)",
- length);
- if (pystr == NULL) {
- /* an exception has occurred, it will be picked up later by
- * Pycairo_Check_Status()
- */
- goto end;
- }
- int ret = PyString_AsStringAndSize(pystr, &buffer, &str_length);
- if (ret == -1 || str_length < length) {
- goto end;
- }
- /* don't use strncpy() since png data may contain NUL bytes */
- memcpy (data, buffer, str_length);
- status = CAIRO_STATUS_SUCCESS;
+_read_func (void *closure, unsigned char *data, unsigned int length) {
+ char *buffer;
+ Py_ssize_t str_length;
+ cairo_status_t status = CAIRO_STATUS_READ_ERROR;
+ PyGILState_STATE gstate = PyGILState_Ensure();
+ PyObject *pystr = PyObject_CallMethod ((PyObject *)closure, "read", "(i)",
+ length);
+ if (pystr == NULL) {
+ /* an exception has occurred, it will be picked up later by
+ * Pycairo_Check_Status()
+ */
+ goto end;
+ }
+ int ret = PyString_AsStringAndSize(pystr, &buffer, &str_length);
+ if (ret == -1 || str_length < length) {
+ goto end;
+ }
+ /* don't use strncpy() since png data may contain NUL bytes */
+ memcpy (data, buffer, str_length);
+ status = CAIRO_STATUS_SUCCESS;
end:
- Py_XDECREF(pystr);
- PyGILState_Release(gstate);
- return status;
+ Py_XDECREF(pystr);
+ PyGILState_Release(gstate);
+ return status;
}
/* METH_O | METH_CLASS */
static PyObject *
-image_surface_create_from_png (PyTypeObject *type, PyObject *file)
-{
- PyObject* reader;
- cairo_surface_t *is;
-
- if (PyObject_TypeCheck (file, &PyBaseString_Type)) {
- Py_BEGIN_ALLOW_THREADS
- is = cairo_image_surface_create_from_png (PyString_AsString(file));
- Py_END_ALLOW_THREADS
- return PycairoSurface_FromSurface (is, NULL);
- }
+image_surface_create_from_png (PyTypeObject *type, PyObject *file) {
+ PyObject* reader;
+ cairo_surface_t *is;
+
+ if (PyObject_TypeCheck (file, &PyBaseString_Type)) {
+ Py_BEGIN_ALLOW_THREADS;
+ is = cairo_image_surface_create_from_png (PyString_AsString(file));
+ Py_END_ALLOW_THREADS;
+ return PycairoSurface_FromSurface (is, NULL);
+ }
- /* file or file-like object argument */
- reader = PyObject_GetAttrString (file, "read");
- if (reader == NULL || !PyCallable_Check (reader)) {
- Py_XDECREF(reader);
- PyErr_SetString(PyExc_TypeError,
+ /* file or file-like object argument */
+ reader = PyObject_GetAttrString (file, "read");
+ if (reader == NULL || !PyCallable_Check (reader)) {
+ Py_XDECREF(reader);
+ PyErr_SetString(PyExc_TypeError,
"ImageSurface.create_from_png argument must be a filename (str), file object, "
"or an object that has a \"read\" method (like StringIO)");
- return NULL;
- }
- Py_DECREF(reader);
+ return NULL;
+ }
+ Py_DECREF(reader);
- Py_BEGIN_ALLOW_THREADS
- is = cairo_image_surface_create_from_png_stream (_read_func, file);
- Py_END_ALLOW_THREADS
- return PycairoSurface_FromSurface (is, NULL);
+ Py_BEGIN_ALLOW_THREADS;
+ is = cairo_image_surface_create_from_png_stream (_read_func, file);
+ Py_END_ALLOW_THREADS;
+ return PycairoSurface_FromSurface (is, NULL);
}
#endif /* CAIRO_HAS_PNG_FUNCTIONS */
/* METH_STATIC */
static PyObject *
-image_surface_format_stride_for_width (PyObject *self, PyObject *args)
-{
- cairo_format_t format;
- int width;
- if (!PyArg_ParseTuple(args, "ii:format_stride_for_width", &format, &width))
- return NULL;
- return PyInt_FromLong (cairo_format_stride_for_width (format, width));
+image_surface_format_stride_for_width (PyObject *self, PyObject *args) {
+ cairo_format_t format;
+ int width;
+ if (!PyArg_ParseTuple(args, "ii:format_stride_for_width", &format, &width))
+ return NULL;
+ return PyInt_FromLong (cairo_format_stride_for_width (format, width));
}
static PyObject *
-image_surface_get_data (PycairoImageSurface *o)
-{
- return PyBuffer_FromReadWriteObject((PyObject *)o, 0, Py_END_OF_BUFFER);
+image_surface_get_data (PycairoImageSurface *o) {
+ return PyBuffer_FromReadWriteObject((PyObject *)o, 0, Py_END_OF_BUFFER);
}
static PyObject *
-image_surface_get_format (PycairoImageSurface *o)
-{
- return PyInt_FromLong (cairo_image_surface_get_format (o->surface));
+image_surface_get_format (PycairoImageSurface *o) {
+ return PyInt_FromLong (cairo_image_surface_get_format (o->surface));
}
static PyObject *
-image_surface_get_height (PycairoImageSurface *o)
-{
- return PyInt_FromLong (cairo_image_surface_get_height (o->surface));
+image_surface_get_height (PycairoImageSurface *o) {
+ return PyInt_FromLong (cairo_image_surface_get_height (o->surface));
}
static PyObject *
-image_surface_get_stride (PycairoImageSurface *o)
-{
- return PyInt_FromLong (cairo_image_surface_get_stride (o->surface));
+image_surface_get_stride (PycairoImageSurface *o) {
+ return PyInt_FromLong (cairo_image_surface_get_stride (o->surface));
}
static PyObject *
-image_surface_get_width (PycairoImageSurface *o)
-{
- return PyInt_FromLong (cairo_image_surface_get_width (o->surface));
+image_surface_get_width (PycairoImageSurface *o) {
+ return PyInt_FromLong (cairo_image_surface_get_width (o->surface));
}
/* Buffer interface functions, used by ImageSurface.get_data() */
static int
image_surface_buffer_getreadbuf (PycairoImageSurface *o, int segment,
- const void **ptr)
-{
- cairo_surface_t *surface = o->surface;
- int height, stride;
-
- if (segment != 0) {
- PyErr_SetString(PyExc_SystemError,
- "accessing non-existent ImageSurface segment");
- return -1;
- }
- height = cairo_image_surface_get_height (surface);
- stride = cairo_image_surface_get_stride (surface);
- *ptr = (void *) cairo_image_surface_get_data (surface);
- return height * stride;
+ const void **ptr) {
+ cairo_surface_t *surface = o->surface;
+ int height, stride;
+
+ if (segment != 0) {
+ PyErr_SetString(PyExc_SystemError,
+ "accessing non-existent ImageSurface segment");
+ return -1;
+ }
+ height = cairo_image_surface_get_height (surface);
+ stride = cairo_image_surface_get_stride (surface);
+ *ptr = (void *) cairo_image_surface_get_data (surface);
+ return height * stride;
}
static int
image_surface_buffer_getwritebuf (PycairoImageSurface *o, int segment,
- const void **ptr)
-{
- cairo_surface_t *surface = o->surface;
- int height, stride;
-
- if (segment != 0) {
- PyErr_SetString(PyExc_SystemError,
- "accessing non-existent ImageSurface segment");
- return -1;
- }
- height = cairo_image_surface_get_height (surface);
- stride = cairo_image_surface_get_stride (surface);
- *ptr = (void *) cairo_image_surface_get_data (surface);
- return height * stride;
+ const void **ptr) {
+ cairo_surface_t *surface = o->surface;
+ int height, stride;
+
+ if (segment != 0) {
+ PyErr_SetString(PyExc_SystemError,
+ "accessing non-existent ImageSurface segment");
+ return -1;
+ }
+ height = cairo_image_surface_get_height (surface);
+ stride = cairo_image_surface_get_stride (surface);
+ *ptr = (void *) cairo_image_surface_get_data (surface);
+ return height * stride;
}
static int
-image_surface_buffer_getsegcount (PycairoImageSurface *o, int *lenp)
-{
- if (lenp) {
- /* report the sum of the sizes (in bytes) of all segments */
- cairo_surface_t *surface = o->surface;
- int height = cairo_image_surface_get_height (surface);
- int stride = cairo_image_surface_get_stride (surface);
- *lenp = height * stride;
- }
- return 1; /* surface data is all in one segment */
+image_surface_buffer_getsegcount (PycairoImageSurface *o, int *lenp) {
+ if (lenp) {
+ /* report the sum of the sizes (in bytes) of all segments */
+ cairo_surface_t *surface = o->surface;
+ int height = cairo_image_surface_get_height (surface);
+ int stride = cairo_image_surface_get_stride (surface);
+ *lenp = height * stride;
+ }
+ return 1; /* surface data is all in one segment */
}
/* See Python C API Manual 10.7 */
static PyBufferProcs image_surface_as_buffer = {
- (readbufferproc) image_surface_buffer_getreadbuf,
- (writebufferproc)image_surface_buffer_getwritebuf,
- (segcountproc) image_surface_buffer_getsegcount,
- (charbufferproc) NULL,
+ (readbufferproc) image_surface_buffer_getreadbuf,
+ (writebufferproc)image_surface_buffer_getwritebuf,
+ (segcountproc) image_surface_buffer_getsegcount,
+ (charbufferproc) NULL,
};
static PyMethodDef image_surface_methods[] = {
- {"create_for_data",(PyCFunction)image_surface_create_for_data,
- METH_VARARGS | METH_CLASS},
+ {"create_for_data",(PyCFunction)image_surface_create_for_data,
+ METH_VARARGS | METH_CLASS},
#ifdef CAIRO_HAS_PNG_FUNCTIONS
- {"create_from_png", (PyCFunction)image_surface_create_from_png,
- METH_O | METH_CLASS},
+ {"create_from_png", (PyCFunction)image_surface_create_from_png,
+ METH_O | METH_CLASS},
#endif
- {"format_stride_for_width",
- (PyCFunction)image_surface_format_stride_for_width,
- METH_VARARGS | METH_STATIC},
- {"get_data", (PyCFunction)image_surface_get_data, METH_NOARGS},
- {"get_format", (PyCFunction)image_surface_get_format, METH_NOARGS},
- {"get_height", (PyCFunction)image_surface_get_height, METH_NOARGS},
- {"get_stride", (PyCFunction)image_surface_get_stride, METH_NOARGS},
- {"get_width", (PyCFunction)image_surface_get_width, METH_NOARGS},
- {NULL, NULL, 0, NULL},
+ {"format_stride_for_width",
+ (PyCFunction)image_surface_format_stride_for_width,
+ METH_VARARGS | METH_STATIC},
+ {"get_data", (PyCFunction)image_surface_get_data, METH_NOARGS},
+ {"get_format", (PyCFunction)image_surface_get_format, METH_NOARGS},
+ {"get_height", (PyCFunction)image_surface_get_height, METH_NOARGS},
+ {"get_stride", (PyCFunction)image_surface_get_stride, METH_NOARGS},
+ {"get_width", (PyCFunction)image_surface_get_width, METH_NOARGS},
+ {NULL, NULL, 0, NULL},
};
PyTypeObject PycairoImageSurface_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "cairo.ImageSurface", /* tp_name */
- sizeof(PycairoImageSurface), /* tp_basicsize */
- 0, /* tp_itemsize */
- 0, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- &image_surface_as_buffer, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- image_surface_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* &PycairoSurface_Type, */ /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)image_surface_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.ImageSurface", /* tp_name */
+ sizeof(PycairoImageSurface), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ &image_surface_as_buffer, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ image_surface_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PycairoSurface_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)image_surface_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
};
#endif /* CAIRO_HAS_IMAGE_SURFACE */
@@ -696,113 +665,111 @@ PyTypeObject PycairoImageSurface_Type = {
#include <cairo-pdf.h>
static PyObject *
-pdf_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- double width_in_points, height_in_points;
- PyObject *file, *writer;
- cairo_surface_t *sfc;
-
- if (!PyArg_ParseTuple(args, "Odd:PDFSurface.__new__",
- &file, &width_in_points, &height_in_points))
- return NULL;
-
- if (file == Py_None) {
- Py_BEGIN_ALLOW_THREADS
- sfc = cairo_pdf_surface_create (NULL,
- width_in_points, height_in_points);
- Py_END_ALLOW_THREADS
- return PycairoSurface_FromSurface (sfc, NULL);
- }else if (PyObject_TypeCheck (file, &PyBaseString_Type)) {
- /* string (filename) argument */
- Py_BEGIN_ALLOW_THREADS
- sfc = cairo_pdf_surface_create (PyString_AsString(file),
- width_in_points, height_in_points);
- Py_END_ALLOW_THREADS
- return PycairoSurface_FromSurface (sfc, NULL);
- }
- /* file or file-like object argument */
- writer = PyObject_GetAttrString (file, "write");
- if (writer == NULL || !PyCallable_Check (writer)) {
- Py_XDECREF(writer);
- PyErr_SetString(PyExc_TypeError,
+pdf_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
+ double width_in_points, height_in_points;
+ PyObject *file, *writer;
+ cairo_surface_t *sfc;
+
+ if (!PyArg_ParseTuple(args, "Odd:PDFSurface.__new__",
+ &file, &width_in_points, &height_in_points))
+ return NULL;
+
+ if (file == Py_None) {
+ Py_BEGIN_ALLOW_THREADS;
+ sfc = cairo_pdf_surface_create (NULL,
+ width_in_points, height_in_points);
+ Py_END_ALLOW_THREADS;
+ return PycairoSurface_FromSurface (sfc, NULL);
+ }else if (PyObject_TypeCheck (file, &PyBaseString_Type)) {
+ /* string (filename) argument */
+ Py_BEGIN_ALLOW_THREADS;
+ sfc = cairo_pdf_surface_create (PyString_AsString(file),
+ width_in_points, height_in_points);
+ Py_END_ALLOW_THREADS;
+ return PycairoSurface_FromSurface (sfc, NULL);
+ }
+ /* file or file-like object argument */
+ writer = PyObject_GetAttrString (file, "write");
+ if (writer == NULL || !PyCallable_Check (writer)) {
+ Py_XDECREF(writer);
+ PyErr_SetString(PyExc_TypeError,
"PDFSurface argument 1 must be\n"
" None, or\n"
" a filename (str), or\n"
" a file object, or\n"
" an object that has a \"write\" method (like StringIO)."
- );
- return NULL;
- }
- Py_DECREF(writer);
-
- Py_BEGIN_ALLOW_THREADS
- sfc = cairo_pdf_surface_create_for_stream (_write_func, file,
- width_in_points, height_in_points);
- Py_END_ALLOW_THREADS
- return PycairoSurface_FromSurface (sfc, file);
+ );
+ return NULL;
+ }
+ Py_DECREF(writer);
+
+ Py_BEGIN_ALLOW_THREADS;
+ sfc = cairo_pdf_surface_create_for_stream (_write_func, file,
+ width_in_points, height_in_points);
+ Py_END_ALLOW_THREADS;
+ return PycairoSurface_FromSurface (sfc, file);
}
static PyObject *
-pdf_surface_set_size (PycairoPDFSurface *o, PyObject *args)
-{
- double width_in_points, height_in_points;
-
- if (!PyArg_ParseTuple(args, "dd:PDFSurface.set_size", &width_in_points,
- &height_in_points))
- return NULL;
- cairo_pdf_surface_set_size (o->surface, width_in_points,
- height_in_points);
- Py_RETURN_NONE;
+pdf_surface_set_size (PycairoPDFSurface *o, PyObject *args) {
+ double width_in_points, height_in_points;
+
+ if (!PyArg_ParseTuple(args, "dd:PDFSurface.set_size", &width_in_points,
+ &height_in_points))
+ return NULL;
+ cairo_pdf_surface_set_size (o->surface, width_in_points,
+ height_in_points);
+ Py_RETURN_NONE;
}
static PyMethodDef pdf_surface_methods[] = {
- {"set_size", (PyCFunction)pdf_surface_set_size, METH_VARARGS },
- {NULL, NULL, 0, NULL},
+ {"set_size", (PyCFunction)pdf_surface_set_size, METH_VARARGS },
+ {NULL, NULL, 0, NULL},
};
PyTypeObject PycairoPDFSurface_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "cairo.PDFSurface", /* tp_name */
- sizeof(PycairoPDFSurface), /* tp_basicsize */
- 0, /* tp_itemsize */
- 0, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- pdf_surface_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* &PycairoSurface_Type, */ /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)pdf_surface_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.PDFSurface", /* tp_name */
+ sizeof(PycairoPDFSurface), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ pdf_surface_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PycairoSurface_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)pdf_surface_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
};
#endif /* CAIRO_HAS_PDF_SURFACE */
@@ -812,199 +779,190 @@ PyTypeObject PycairoPDFSurface_Type = {
#include <cairo-ps.h>
static PyObject *
-ps_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- double width_in_points, height_in_points;
- PyObject *file, *writer;
- cairo_surface_t *sfc;
-
- if (!PyArg_ParseTuple(args, "Odd:PSSurface.__new__",
- &file, &width_in_points, &height_in_points))
- return NULL;
-
- if (file == Py_None) {
- Py_BEGIN_ALLOW_THREADS
- sfc = cairo_ps_surface_create (NULL,
- width_in_points, height_in_points);
- Py_END_ALLOW_THREADS
- return PycairoSurface_FromSurface (sfc, NULL);
- }else if (PyObject_TypeCheck (file, &PyBaseString_Type)) {
- /* string (filename) argument */
- Py_BEGIN_ALLOW_THREADS
- sfc = cairo_ps_surface_create (PyString_AsString(file),
- width_in_points, height_in_points);
- Py_END_ALLOW_THREADS
- return PycairoSurface_FromSurface (sfc, NULL);
- }
- /* else: file or file-like object argument */
- writer = PyObject_GetAttrString (file, "write");
- if (writer == NULL || !PyCallable_Check (writer)) {
- Py_XDECREF(writer);
- PyErr_SetString(PyExc_TypeError,
+ps_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
+ double width_in_points, height_in_points;
+ PyObject *file, *writer;
+ cairo_surface_t *sfc;
+
+ if (!PyArg_ParseTuple(args, "Odd:PSSurface.__new__",
+ &file, &width_in_points, &height_in_points))
+ return NULL;
+
+ if (file == Py_None) {
+ Py_BEGIN_ALLOW_THREADS;
+ sfc = cairo_ps_surface_create (NULL,
+ width_in_points, height_in_points);
+ Py_END_ALLOW_THREADS;
+ return PycairoSurface_FromSurface (sfc, NULL);
+ }else if (PyObject_TypeCheck (file, &PyBaseString_Type)) {
+ /* string (filename) argument */
+ Py_BEGIN_ALLOW_THREADS;
+ sfc = cairo_ps_surface_create (PyString_AsString(file),
+ width_in_points, height_in_points);
+ Py_END_ALLOW_THREADS;
+ return PycairoSurface_FromSurface (sfc, NULL);
+ }
+ /* else: file or file-like object argument */
+ writer = PyObject_GetAttrString (file, "write");
+ if (writer == NULL || !PyCallable_Check (writer)) {
+ Py_XDECREF(writer);
+ PyErr_SetString(PyExc_TypeError,
"PSSurface argument 1 must be\n"
" None, or\n"
" a filename (str), or\n"
" a file object, or\n"
" an object that has a \"write\" method (like StringIO)."
- );
- return NULL;
- }
- Py_DECREF(writer);
-
- Py_BEGIN_ALLOW_THREADS
- sfc = cairo_ps_surface_create_for_stream (_write_func, file,
- width_in_points, height_in_points);
- Py_END_ALLOW_THREADS
- return PycairoSurface_FromSurface (sfc, file);
+ );
+ return NULL;
+ }
+ Py_DECREF(writer);
+
+ Py_BEGIN_ALLOW_THREADS;
+ sfc = cairo_ps_surface_create_for_stream (_write_func, file,
+ width_in_points, height_in_points);
+ Py_END_ALLOW_THREADS;
+ return PycairoSurface_FromSurface (sfc, file);
}
static PyObject *
-ps_surface_dsc_begin_page_setup (PycairoPSSurface *o)
-{
- cairo_ps_surface_dsc_begin_page_setup (o->surface);
- RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
- Py_RETURN_NONE;
+ps_surface_dsc_begin_page_setup (PycairoPSSurface *o) {
+ cairo_ps_surface_dsc_begin_page_setup (o->surface);
+ RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
+ Py_RETURN_NONE;
}
static PyObject *
-ps_surface_dsc_begin_setup (PycairoPSSurface *o)
-{
- cairo_ps_surface_dsc_begin_setup (o->surface);
- RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
- Py_RETURN_NONE;
+ps_surface_dsc_begin_setup (PycairoPSSurface *o) {
+ cairo_ps_surface_dsc_begin_setup (o->surface);
+ RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
+ Py_RETURN_NONE;
}
static PyObject *
-ps_surface_dsc_comment (PycairoPSSurface *o, PyObject *args)
-{
- const char *comment;
- if (!PyArg_ParseTuple(args, "s:PSSurface.dsc_comment", &comment))
- return NULL;
- cairo_ps_surface_dsc_comment (o->surface, comment);
- RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
- Py_RETURN_NONE;
+ps_surface_dsc_comment (PycairoPSSurface *o, PyObject *args) {
+ const char *comment;
+ if (!PyArg_ParseTuple(args, "s:PSSurface.dsc_comment", &comment))
+ return NULL;
+ cairo_ps_surface_dsc_comment (o->surface, comment);
+ RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
+ Py_RETURN_NONE;
}
static PyObject *
-ps_surface_get_eps (PycairoPSSurface *o)
-{
- PyObject *eps = cairo_ps_surface_get_eps (o->surface) ? Py_True : Py_False;
- RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
- Py_INCREF(eps);
- return eps;
+ps_surface_get_eps (PycairoPSSurface *o) {
+ PyObject *eps = cairo_ps_surface_get_eps (o->surface) ? Py_True : Py_False;
+ RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
+ Py_INCREF(eps);
+ return eps;
}
/* METH_STATIC */
static PyObject *
-ps_surface_ps_level_to_string (PyObject *self, PyObject *args)
-{
- int level;
- if (!PyArg_ParseTuple(args, "i:ps_level_to_string", &level))
- return NULL;
- const char *s = cairo_ps_level_to_string (level);
- if (s == NULL){
- PyErr_SetString(CairoError, "ps_level_to_string: "
- "invalid level argument");
- return NULL;
- }
- return PyString_FromString(s);
+ps_surface_ps_level_to_string (PyObject *self, PyObject *args) {
+ int level;
+ if (!PyArg_ParseTuple(args, "i:ps_level_to_string", &level))
+ return NULL;
+ const char *s = cairo_ps_level_to_string (level);
+ if (s == NULL){
+ PyErr_SetString(CairoError, "ps_level_to_string: "
+ "invalid level argument");
+ return NULL;
+ }
+ return PyString_FromString(s);
}
static PyObject *
-ps_surface_restrict_to_level (PycairoPSSurface *o, PyObject *args)
-{
- int level;
-
- if (!PyArg_ParseTuple(args, "i:PSSurface.restrict_to_level", &level))
- return NULL;
- cairo_ps_surface_restrict_to_level (o->surface, level);
- RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
- Py_RETURN_NONE;
+ps_surface_restrict_to_level (PycairoPSSurface *o, PyObject *args) {
+ int level;
+
+ if (!PyArg_ParseTuple(args, "i:PSSurface.restrict_to_level", &level))
+ return NULL;
+ cairo_ps_surface_restrict_to_level (o->surface, level);
+ RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
+ Py_RETURN_NONE;
}
static PyObject *
-ps_surface_set_eps (PycairoPSSurface *o, PyObject *args)
-{
- PyObject *py_eps;
- if (!PyArg_ParseTuple(args, "O!:PSSurface.set_eps",
- &PyBool_Type, &py_eps))
- return NULL;
- cairo_ps_surface_set_eps (o->surface, (py_eps == Py_True));
- RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
- Py_RETURN_NONE;
+ps_surface_set_eps (PycairoPSSurface *o, PyObject *args) {
+ PyObject *py_eps;
+ if (!PyArg_ParseTuple(args, "O!:PSSurface.set_eps",
+ &PyBool_Type, &py_eps))
+ return NULL;
+ cairo_ps_surface_set_eps (o->surface, (py_eps == Py_True));
+ RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
+ Py_RETURN_NONE;
}
static PyObject *
-ps_surface_set_size (PycairoPSSurface *o, PyObject *args)
-{
- double width_in_points, height_in_points;
-
- if (!PyArg_ParseTuple(args, "dd:PSSurface.set_size",
- &width_in_points, &height_in_points))
- return NULL;
- cairo_ps_surface_set_size (o->surface, width_in_points, height_in_points);
- Py_RETURN_NONE;
+ps_surface_set_size (PycairoPSSurface *o, PyObject *args) {
+ double width_in_points, height_in_points;
+
+ if (!PyArg_ParseTuple(args, "dd:PSSurface.set_size",
+ &width_in_points, &height_in_points))
+ return NULL;
+ cairo_ps_surface_set_size (o->surface, width_in_points, height_in_points);
+ Py_RETURN_NONE;
}
static PyMethodDef ps_surface_methods[] = {
- {"dsc_begin_page_setup",
- (PyCFunction)ps_surface_dsc_begin_page_setup, METH_NOARGS },
- {"dsc_begin_setup", (PyCFunction)ps_surface_dsc_begin_setup, METH_NOARGS },
- {"dsc_comment", (PyCFunction)ps_surface_dsc_comment, METH_VARARGS },
- {"get_eps", (PyCFunction)ps_surface_get_eps, METH_NOARGS },
- /* ps_get_levels - not implemented yet*/
- {"ps_level_to_string", (PyCFunction)ps_surface_ps_level_to_string,
- METH_VARARGS | METH_STATIC},
- {"restrict_to_level", (PyCFunction)ps_surface_restrict_to_level,
- METH_VARARGS },
- {"set_eps", (PyCFunction)ps_surface_set_eps, METH_VARARGS },
- {"set_size", (PyCFunction)ps_surface_set_size, METH_VARARGS },
- {NULL, NULL, 0, NULL},
+ {"dsc_begin_page_setup",
+ (PyCFunction)ps_surface_dsc_begin_page_setup, METH_NOARGS },
+ {"dsc_begin_setup", (PyCFunction)ps_surface_dsc_begin_setup, METH_NOARGS },
+ {"dsc_comment", (PyCFunction)ps_surface_dsc_comment, METH_VARARGS },
+ {"get_eps", (PyCFunction)ps_surface_get_eps, METH_NOARGS },
+ /* ps_get_levels - not implemented yet*/
+ {"ps_level_to_string", (PyCFunction)ps_surface_ps_level_to_string,
+ METH_VARARGS | METH_STATIC},
+ {"restrict_to_level", (PyCFunction)ps_surface_restrict_to_level,
+ METH_VARARGS },
+ {"set_eps", (PyCFunction)ps_surface_set_eps, METH_VARARGS },
+ {"set_size", (PyCFunction)ps_surface_set_size, METH_VARARGS },
+ {NULL, NULL, 0, NULL},
};
PyTypeObject PycairoPSSurface_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "cairo.PSSurface", /* tp_name */
- sizeof(PycairoPSSurface), /* tp_basicsize */
- 0, /* tp_itemsize */
- 0, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- ps_surface_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* &PycairoSurface_Type, */ /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)ps_surface_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.PSSurface", /* tp_name */
+ sizeof(PycairoPSSurface), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ ps_surface_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PycairoSurface_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)ps_surface_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
};
#endif /* CAIRO_HAS_PS_SURFACE */
@@ -1014,104 +972,103 @@ PyTypeObject PycairoPSSurface_Type = {
#include <cairo-svg.h>
static PyObject *
-svg_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- double width_in_points, height_in_points;
- PyObject *file, *writer;
- cairo_surface_t *sfc;
-
- if (!PyArg_ParseTuple(args, "Odd:SVGSurface.__new__",
- &file, &width_in_points, &height_in_points))
- return NULL;
-
- if (file == Py_None) {
- Py_BEGIN_ALLOW_THREADS
- sfc = cairo_svg_surface_create (NULL,
- width_in_points, height_in_points);
- Py_END_ALLOW_THREADS
- return PycairoSurface_FromSurface (sfc, NULL);
- }else if (PyObject_TypeCheck (file, &PyBaseString_Type)) {
- /* string (filename) argument */
- Py_BEGIN_ALLOW_THREADS
- sfc = cairo_svg_surface_create (PyString_AsString(file),
- width_in_points, height_in_points);
- Py_END_ALLOW_THREADS
- return PycairoSurface_FromSurface (sfc, NULL);
- }
- /* else: file or file-like object argument */
- writer = PyObject_GetAttrString (file, "write");
- if (writer == NULL || !PyCallable_Check (writer)) {
- Py_XDECREF(writer);
- PyErr_SetString(PyExc_TypeError,
+svg_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
+ double width_in_points, height_in_points;
+ PyObject *file, *writer;
+ cairo_surface_t *sfc;
+
+ if (!PyArg_ParseTuple(args, "Odd:SVGSurface.__new__",
+ &file, &width_in_points, &height_in_points))
+ return NULL;
+
+ if (file == Py_None) {
+ Py_BEGIN_ALLOW_THREADS;
+ sfc = cairo_svg_surface_create (NULL,
+ width_in_points, height_in_points);
+ Py_END_ALLOW_THREADS;
+ return PycairoSurface_FromSurface (sfc, NULL);
+ }else if (PyObject_TypeCheck (file, &PyBaseString_Type)) {
+ /* string (filename) argument */
+ Py_BEGIN_ALLOW_THREADS;
+ sfc = cairo_svg_surface_create (PyString_AsString(file),
+ width_in_points, height_in_points);
+ Py_END_ALLOW_THREADS;
+ return PycairoSurface_FromSurface (sfc, NULL);
+ }
+ /* else: file or file-like object argument */
+ writer = PyObject_GetAttrString (file, "write");
+ if (writer == NULL || !PyCallable_Check (writer)) {
+ Py_XDECREF(writer);
+ PyErr_SetString(PyExc_TypeError,
"SVGSurface argument 1 must be\n"
" None, or\n"
" a filename (str), or\n"
" a file object, or\n"
" an object that has a \"write\" method (like StringIO)."
- );
- return NULL;
- }
- Py_DECREF(writer);
-
- Py_BEGIN_ALLOW_THREADS
- sfc = cairo_svg_surface_create_for_stream (_write_func, file,
- width_in_points, height_in_points);
- Py_END_ALLOW_THREADS
- return PycairoSurface_FromSurface (sfc, file);
+ );
+ return NULL;
+ }
+ Py_DECREF(writer);
+
+ Py_BEGIN_ALLOW_THREADS;
+ sfc = cairo_svg_surface_create_for_stream (_write_func, file,
+ width_in_points, height_in_points);
+ Py_END_ALLOW_THREADS;
+ return PycairoSurface_FromSurface (sfc, file);
}
static PyMethodDef svg_surface_methods[] = {
- /* TODO
- * cairo_svg_surface_restrict_to_version
- * cairo_svg_get_versions
- * cairo_svg_version_to_string
- */
+ /* TODO
+ * cairo_svg_surface_restrict_to_version
+ * cairo_svg_get_versions
+ * cairo_svg_version_to_string
+ */
{NULL, NULL, 0, NULL},
};
PyTypeObject PycairoSVGSurface_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "cairo.SVGSurface", /* tp_name */
- sizeof(PycairoSVGSurface), /* tp_basicsize */
- 0, /* tp_itemsize */
- 0, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- svg_surface_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* &PycairoSurface_Type, */ /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)svg_surface_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.SVGSurface", /* tp_name */
+ sizeof(PycairoSVGSurface), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ svg_surface_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PycairoSurface_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)svg_surface_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
};
#endif /* CAIRO_HAS_SVG_SURFACE */
@@ -1121,63 +1078,62 @@ PyTypeObject PycairoSVGSurface_Type = {
#include <cairo-win32.h>
static PyObject *
-win32_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- int hdc;
-
- if (!PyArg_ParseTuple(args, "i:Win32Surface.__new__", &hdc))
- return NULL;
- return PycairoSurface_FromSurface (
- cairo_win32_surface_create ((HDC)hdc), NULL);
+win32_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
+ int hdc;
+
+ if (!PyArg_ParseTuple(args, "i:Win32Surface.__new__", &hdc))
+ return NULL;
+ return PycairoSurface_FromSurface (
+ cairo_win32_surface_create ((HDC)hdc), NULL);
}
static PyMethodDef win32_surface_methods[] = {
- {NULL, NULL, 0, NULL},
+ {NULL, NULL, 0, NULL},
};
PyTypeObject PycairoWin32Surface_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "cairo.Win32Surface", /* tp_name */
- sizeof(PycairoWin32Surface), /* tp_basicsize */
- 0, /* tp_itemsize */
- 0, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- win32_surface_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* &PycairoSurface_Type, */ /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)win32_surface_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.Win32Surface", /* tp_name */
+ sizeof(PycairoWin32Surface), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ win32_surface_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PycairoSurface_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)win32_surface_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
};
#endif /* CAIRO_HAS_WIN32_SURFACE */
@@ -1187,80 +1143,76 @@ PyTypeObject PycairoWin32Surface_Type = {
#include <cairo-xlib.h>
static PyObject *
-xlib_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PyErr_SetString(PyExc_TypeError,
- "The XlibSurface type cannot be directly instantiated");
- return NULL;
+xlib_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
+ PyErr_SetString(PyExc_TypeError,
+ "The XlibSurface type cannot be directly instantiated");
+ return NULL;
}
static PyObject *
-xlib_surface_get_depth (PycairoXlibSurface *o)
-{
- return PyInt_FromLong (cairo_xlib_surface_get_depth (o->surface));
+xlib_surface_get_depth (PycairoXlibSurface *o) {
+ return PyInt_FromLong (cairo_xlib_surface_get_depth (o->surface));
}
static PyObject *
-xlib_surface_get_height (PycairoXlibSurface *o)
-{
- return PyInt_FromLong (cairo_xlib_surface_get_height (o->surface));
+xlib_surface_get_height (PycairoXlibSurface *o) {
+ return PyInt_FromLong (cairo_xlib_surface_get_height (o->surface));
}
static PyObject *
-xlib_surface_get_width (PycairoXlibSurface *o)
-{
- return PyInt_FromLong (cairo_xlib_surface_get_width (o->surface));
+xlib_surface_get_width (PycairoXlibSurface *o) {
+ return PyInt_FromLong (cairo_xlib_surface_get_width (o->surface));
}
static PyMethodDef xlib_surface_methods[] = {
- {"get_depth", (PyCFunction)xlib_surface_get_depth, METH_NOARGS },
- {"get_height",(PyCFunction)xlib_surface_get_height, METH_NOARGS },
- {"get_width", (PyCFunction)xlib_surface_get_width, METH_NOARGS },
- {NULL, NULL, 0, NULL},
+ {"get_depth", (PyCFunction)xlib_surface_get_depth, METH_NOARGS },
+ {"get_height",(PyCFunction)xlib_surface_get_height, METH_NOARGS },
+ {"get_width", (PyCFunction)xlib_surface_get_width, METH_NOARGS },
+ {NULL, NULL, 0, NULL},
};
PyTypeObject PycairoXlibSurface_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "cairo.XlibSurface", /* tp_name */
- sizeof(PycairoXlibSurface), /* tp_basicsize */
- 0, /* tp_itemsize */
- 0, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- xlib_surface_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* &PycairoSurface_Type, */ /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)xlib_surface_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "cairo.XlibSurface", /* tp_name */
+ sizeof(PycairoXlibSurface), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ xlib_surface_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* &PycairoSurface_Type, */ /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)xlib_surface_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
};
#endif /* CAIRO_HAS_XLIB_SURFACE */
diff --git a/src/pycairo.h b/src/pycairo.h
index ba56801..255bc74 100644
--- a/src/pycairo.h
+++ b/src/pycairo.h
@@ -1,4 +1,4 @@
-/* -*- mode: C; c-basic-offset: 4 -*-
+/* -*- mode: C; c-basic-offset: 2 -*-
*
* Pycairo - Python bindings for cairo
*
@@ -37,37 +37,37 @@
typedef struct {
- PyObject_HEAD
- cairo_t *ctx;
- PyObject *base; /* base object used to create context, or NULL */
+ PyObject_HEAD
+ cairo_t *ctx;
+ PyObject *base; /* base object used to create context, or NULL */
} PycairoContext;
typedef struct {
- PyObject_HEAD
- cairo_font_face_t *font_face;
+ PyObject_HEAD
+ cairo_font_face_t *font_face;
} PycairoFontFace;
#define PycairoToyFontFace PycairoFontFace
typedef struct {
- PyObject_HEAD
- cairo_font_options_t *font_options;
+ PyObject_HEAD
+ cairo_font_options_t *font_options;
} PycairoFontOptions;
typedef struct {
- PyObject_HEAD
- cairo_matrix_t matrix;
+ PyObject_HEAD
+ cairo_matrix_t matrix;
} PycairoMatrix;
typedef struct {
- PyObject_HEAD
- cairo_path_t *path;
+ PyObject_HEAD
+ cairo_path_t *path;
} PycairoPath;
typedef struct {
- PyObject_HEAD
- cairo_pattern_t *pattern;
- PyObject *base; /* base object used to create pattern, or NULL */
+ PyObject_HEAD
+ cairo_pattern_t *pattern;
+ PyObject *base; /* base object used to create pattern, or NULL */
} PycairoPattern;
#define PycairoSolidPattern PycairoPattern
@@ -77,14 +77,14 @@ typedef struct {
#define PycairoRadialGradient PycairoPattern
typedef struct {
- PyObject_HEAD
- cairo_scaled_font_t *scaled_font;
+ PyObject_HEAD
+ cairo_scaled_font_t *scaled_font;
} PycairoScaledFont;
typedef struct {
- PyObject_HEAD
- cairo_surface_t *surface;
- PyObject *base; /* base object used to create surface, or NULL */
+ PyObject_HEAD
+ cairo_surface_t *surface;
+ PyObject *base; /* base object used to create surface, or NULL */
} PycairoSurface;
#define PycairoImageSurface PycairoSurface
@@ -99,43 +99,43 @@ typedef struct {
/* Define structure for C API. */
typedef struct {
- /* (type object, constructor) pairs */
- PyTypeObject *Context_Type;
- PyObject *(*Context_FromContext)(cairo_t *ctx, PyTypeObject *type,
- PyObject *base);
- PyTypeObject *FontFace_Type;
- PyTypeObject *ToyFontFace_Type;
- PyObject *(*FontFace_FromFontFace)(cairo_font_face_t *font_face);
- PyTypeObject *FontOptions_Type;
- PyObject *(*FontOptions_FromFontOptions)(
- cairo_font_options_t *font_options);
- PyTypeObject *Matrix_Type;
- PyObject *(*Matrix_FromMatrix)(const cairo_matrix_t *matrix);
- PyTypeObject *Path_Type;
- PyObject *(*Path_FromPath)(cairo_path_t *path);
-
- PyTypeObject *Pattern_Type;
- PyTypeObject *SolidPattern_Type;
- PyTypeObject *SurfacePattern_Type;
- PyTypeObject *Gradient_Type;
- PyTypeObject *LinearGradient_Type;
- PyTypeObject *RadialGradient_Type;
- PyObject *(*Pattern_FromPattern)(cairo_pattern_t *pattern, PyObject *base);
-
- PyTypeObject *ScaledFont_Type;
- PyObject *(*ScaledFont_FromScaledFont)(cairo_scaled_font_t *scaled_font);
-
- PyTypeObject *Surface_Type;
- PyTypeObject *ImageSurface_Type;
- PyTypeObject *PDFSurface_Type;
- PyTypeObject *PSSurface_Type;
- PyTypeObject *SVGSurface_Type;
- PyTypeObject *Win32Surface_Type;
- PyTypeObject *XlibSurface_Type;
- PyObject *(*Surface_FromSurface)(cairo_surface_t *surface, PyObject *base);
-
- /* misc functions */
- int (*Check_Status)(cairo_status_t status);
+ /* (type object, constructor) pairs */
+ PyTypeObject *Context_Type;
+ PyObject *(*Context_FromContext)(cairo_t *ctx, PyTypeObject *type,
+ PyObject *base);
+ PyTypeObject *FontFace_Type;
+ PyTypeObject *ToyFontFace_Type;
+ PyObject *(*FontFace_FromFontFace)(cairo_font_face_t *font_face);
+ PyTypeObject *FontOptions_Type;
+ PyObject *(*FontOptions_FromFontOptions)(
+ cairo_font_options_t *font_options);
+ PyTypeObject *Matrix_Type;
+ PyObject *(*Matrix_FromMatrix)(const cairo_matrix_t *matrix);
+ PyTypeObject *Path_Type;
+ PyObject *(*Path_FromPath)(cairo_path_t *path);
+
+ PyTypeObject *Pattern_Type;
+ PyTypeObject *SolidPattern_Type;
+ PyTypeObject *SurfacePattern_Type;
+ PyTypeObject *Gradient_Type;
+ PyTypeObject *LinearGradient_Type;
+ PyTypeObject *RadialGradient_Type;
+ PyObject *(*Pattern_FromPattern)(cairo_pattern_t *pattern, PyObject *base);
+
+ PyTypeObject *ScaledFont_Type;
+ PyObject *(*ScaledFont_FromScaledFont)(cairo_scaled_font_t *scaled_font);
+
+ PyTypeObject *Surface_Type;
+ PyTypeObject *ImageSurface_Type;
+ PyTypeObject *PDFSurface_Type;
+ PyTypeObject *PSSurface_Type;
+ PyTypeObject *SVGSurface_Type;
+ PyTypeObject *Win32Surface_Type;
+ PyTypeObject *XlibSurface_Type;
+ PyObject *(*Surface_FromSurface)(cairo_surface_t *surface, PyObject *base);
+
+ /* misc functions */
+ int (*Check_Status)(cairo_status_t status);
} Pycairo_CAPI_t;