summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSteve Chaplin <>2010-09-12 21:04:44 +0800
committerSteve Chaplin <>2010-09-12 21:04:44 +0800
commitf3df40256010a0425d820136c532d54dc467f67c (patch)
tree0390a3e3c50a23d8f4d1d1dba23ba93b3e0b3d27 /src
parent59415110e1811019d49562fd06ad75d9182b9b77 (diff)
=== Pycairo 1.8.10 ===
Many changes to make the code work with Python 3.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/__init__.py2
-rw-r--r--src/cairomodule.c129
-rw-r--r--src/context.c135
-rw-r--r--src/font.c101
-rw-r--r--src/matrix.c84
-rw-r--r--src/path.c33
-rw-r--r--src/pattern.c37
-rw-r--r--src/surface.c249
-rw-r--r--src/wscript14
9 files changed, 437 insertions, 347 deletions
diff --git a/src/__init__.py b/src/__init__.py
index 85e07e2..b0f3bf6 100755
--- a/src/__init__.py
+++ b/src/__init__.py
@@ -15,4 +15,4 @@ more details.
You should have received a copy of the GNU Lesser General Public License
along with pycairo. If not, see <http://www.gnu.org/licenses/>.
'''
-from _cairo import *
+from ._cairo import *
diff --git a/src/cairomodule.c b/src/cairomodule.c
index 02da659..58e665c 100644
--- a/src/cairomodule.c
+++ b/src/cairomodule.c
@@ -145,15 +145,16 @@ static Pycairo_CAPI_t CAPI = {
static PyObject *
pycairo_cairo_version (PyObject *self) {
- return PyInt_FromLong (cairo_version());
+ return PyLong_FromLong (cairo_version());
}
static PyObject *
pycairo_cairo_version_string (PyObject *self) {
- return PyString_FromString (cairo_version_string());
+ return PyUnicode_FromString (cairo_version_string());
}
-static PyMethodDef cairo_functions[] = {
+//static PyMethodDef cairo_functions[] = {
+static PyMethodDef cairo_methods[] = {
{"cairo_version", (PyCFunction)pycairo_cairo_version, METH_NOARGS},
{"cairo_version_string", (PyCFunction)pycairo_cairo_version_string,
METH_NOARGS},
@@ -161,77 +162,133 @@ static PyMethodDef cairo_functions[] = {
};
-DL_EXPORT(void)
-init_cairo(void)
+// Module initialization
+struct cairo_state {
+ PyObject *ErrorObject;
+};
+
+#define GETSTATE(m) ((struct cairo_state*)PyModule_GetState(m))
+
+static int
+cairo_traverse(PyObject *m, visitproc v, void *arg)
+{
+ // Py_VISIT(GETSTATE(m)->ErrorObject);
+ /* gives error
+ ImportError: ./_cairo.so: undefined symbol: visit
+ */
+ return 0;
+}
+
+static int
+cairo_clear(PyObject *m)
{
- PyObject *m;
+ Py_CLEAR(GETSTATE(m)->ErrorObject);
+ return 0;
+}
+static struct PyModuleDef cairomodule = {
+ PyModuleDef_HEAD_INIT,
+ "cairo",
+ NULL,
+ sizeof(struct cairo_state),
+ cairo_methods,
+ 0, /* m_reload */
+ cairo_traverse,
+ cairo_clear,
+ 0, /* m_free - not needed, since all is done in m_clear */
+};
+
+PyObject *
+PyInit__cairo(void)
+{
if (PyType_Ready(&PycairoContext_Type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PycairoFontFace_Type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PycairoToyFontFace_Type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PycairoFontOptions_Type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PycairoMatrix_Type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PycairoPath_Type) < 0)
- return;
+ return NULL;
PycairoPathiter_Type.tp_iter=&PyObject_SelfIter;
if (PyType_Ready(&PycairoPathiter_Type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PycairoPattern_Type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PycairoSolidPattern_Type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PycairoSurfacePattern_Type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PycairoGradient_Type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PycairoLinearGradient_Type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PycairoRadialGradient_Type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PycairoScaledFont_Type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PycairoSurface_Type) < 0)
- return;
+ return NULL;
#ifdef CAIRO_HAS_IMAGE_SURFACE
if (PyType_Ready(&PycairoImageSurface_Type) < 0)
- return;
+ return NULL;
#endif
#ifdef CAIRO_HAS_PDF_SURFACE
if (PyType_Ready(&PycairoPDFSurface_Type) < 0)
- return;
+ return NULL;
#endif
#ifdef CAIRO_HAS_PS_SURFACE
if (PyType_Ready(&PycairoPSSurface_Type) < 0)
- return;
+ return NULL;
#endif
#ifdef CAIRO_HAS_SVG_SURFACE
if (PyType_Ready(&PycairoSVGSurface_Type) < 0)
- return;
+ return NULL;
#endif
#ifdef CAIRO_HAS_WIN32_SURFACE
if (PyType_Ready(&PycairoWin32Surface_Type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PycairoWin32PrintingSurface_Type) < 0)
- return;
+ return NULL;
#endif
#ifdef CAIRO_HAS_XCB_SURFACE
if (PyType_Ready(&PycairoXCBSurface_Type) < 0)
- return;
+ return NULL;
#endif
#ifdef CAIRO_HAS_XLIB_SURFACE
if (PyType_Ready(&PycairoXlibSurface_Type) < 0)
- return;
+ return NULL;
#endif
- m = Py_InitModule("cairo._cairo", cairo_functions);
+
+ PyObject *m = PyModule_Create(&cairomodule);
+ //PyObject *m;
+ //m = Py_InitModule("cairo._cairo", cairo_functions);
+ if (m==NULL)
+ return NULL;
+ GETSTATE(m)->ErrorObject = PyErr_NewException("cairo.Error", NULL, NULL);
+ if (GETSTATE(m)->ErrorObject == NULL) {
+ Py_DECREF(m);
+ return NULL;
+ }
+ /* Add 'cairo.Error' to the module */
+ // if (CairoError == NULL) {
+ // CairoError = PyErr_NewException("cairo.Error", NULL, NULL);
+ // if (CairoError == NULL)
+ // return NULL;
+ //}
+ //Py_INCREF(CairoError);
+ // not needed ?
+ //if (PyModule_AddObject(m, "Error", CairoError) < 0)
+ // return NULL;
+
+
PyModule_AddStringConstant(m, "version", VERSION);
PyModule_AddObject(m, "version_info",
@@ -322,16 +379,6 @@ init_cairo(void)
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;
-
/* constants */
#if CAIRO_HAS_ATSUI_FONT
PyModule_AddIntConstant(m, "HAS_ATSUI_FONT", 1);
@@ -493,4 +540,6 @@ init_cairo(void)
CONSTANT(SUBPIXEL_ORDER_VRGB);
CONSTANT(SUBPIXEL_ORDER_VBGR);
#undef CONSTANT
+
+ return m;
}
diff --git a/src/context.c b/src/context.c
index cf56f5d..60cb0d7 100644
--- a/src/context.c
+++ b/src/context.c
@@ -65,8 +65,8 @@ pycairo_dealloc(PycairoContext *o) {
o->ctx = NULL;
}
Py_CLEAR(o->base);
-
- o->ob_type->tp_free((PyObject *)o);
+ //o->ob_type->tp_free((PyObject *)o);
+ Py_TYPE(o)->tp_free(o);
}
static PyObject *
@@ -286,7 +286,7 @@ pycairo_font_extents (PycairoContext *o) {
static PyObject *
pycairo_get_antialias (PycairoContext *o) {
- return PyInt_FromLong (cairo_get_antialias (o->ctx));
+ return PyLong_FromLong (cairo_get_antialias (o->ctx));
}
static PyObject *
@@ -328,12 +328,12 @@ pycairo_get_dash (PycairoContext *o) {
static PyObject *
pycairo_get_dash_count (PycairoContext *o) {
- return PyInt_FromLong (cairo_get_dash_count (o->ctx));
+ return PyLong_FromLong (cairo_get_dash_count (o->ctx));
}
static PyObject *
pycairo_get_fill_rule (PycairoContext *o) {
- return PyInt_FromLong(cairo_get_fill_rule (o->ctx));
+ return PyLong_FromLong(cairo_get_fill_rule (o->ctx));
}
static PyObject *
@@ -368,12 +368,12 @@ pycairo_get_group_target (PycairoContext *o) {
static PyObject *
pycairo_get_line_cap (PycairoContext *o) {
- return PyInt_FromLong(cairo_get_line_cap (o->ctx));
+ return PyLong_FromLong(cairo_get_line_cap (o->ctx));
}
static PyObject *
pycairo_get_line_join (PycairoContext *o) {
- return PyInt_FromLong(cairo_get_line_join (o->ctx));
+ return PyLong_FromLong(cairo_get_line_join (o->ctx));
}
static PyObject *
@@ -395,7 +395,7 @@ pycairo_get_miter_limit (PycairoContext *o) {
static PyObject *
pycairo_get_operator (PycairoContext *o) {
- return PyInt_FromLong (cairo_get_operator (o->ctx));
+ return PyLong_FromLong (cairo_get_operator (o->ctx));
}
static PyObject *
@@ -457,7 +457,7 @@ _PyGlyphs_AsGlyphs (PyObject *py_object, int *num_glyphs)
"each glyph item must be an (i,x,y) sequence");
goto error;
}
- glyph->index = PyInt_AsLong(PySequence_Fast_GET_ITEM(py_seq, 0));
+ glyph->index = PyLong_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())
@@ -784,32 +784,21 @@ pycairo_scale (PycairoContext *o, PyObject *args) {
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))
+ if (!PyArg_ParseTuple(args, "U|ii:Context.select_font_face",
+ &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");
- }
- if (utf8family == NULL)
+ PyObject *pyUTF8 = PyUnicode_AsUTF8String(obj);
+ if (pyUTF8 == NULL)
+ return NULL;
+ const char *utf8 = PyBytes_AS_STRING(pyUTF8);
+ if (utf8 == NULL)
return NULL;
- cairo_select_font_face (o->ctx, utf8family, slant, weight);
+ cairo_select_font_face (o->ctx, utf8, slant, weight);
Py_XDECREF(pyUTF8);
RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
Py_RETURN_NONE;
@@ -1109,23 +1098,16 @@ pycairo_show_page (PycairoContext *o) {
}
static PyObject *
-pycairo_show_text (PycairoContext *o, PyObject *obj) {
- PyObject *pyUTF8 = NULL;
- const char *utf8 = NULL;
+pycairo_show_text (PycairoContext *o, PyObject *args) {
+ PyObject *obj;
- /* 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");
- }
+ if (!PyArg_ParseTuple(args, "U:Context.show_text", &obj))
+ return NULL;
+
+ PyObject *pyUTF8 = PyUnicode_AsUTF8String(obj);
+ if (pyUTF8 == NULL)
+ return NULL;
+ const char *utf8 = PyBytes_AS_STRING(pyUTF8);
if (utf8 == NULL)
return NULL;
@@ -1164,27 +1146,20 @@ pycairo_stroke_preserve (PycairoContext *o) {
}
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 *args) {
+ PyObject *obj;
+
+ if (!PyArg_ParseTuple(args, "U:Context.text_extents", &obj))
+ return NULL;
+
+ PyObject *pyUTF8 = PyUnicode_AsUTF8String(obj);
+ if (pyUTF8 == NULL)
+ return NULL;
+ const char *utf8 = PyBytes_AS_STRING(pyUTF8);
if (utf8 == NULL)
return NULL;
+ cairo_text_extents_t extents;
cairo_text_extents (o->ctx, utf8, &extents);
Py_XDECREF(pyUTF8);
RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
@@ -1194,23 +1169,16 @@ pycairo_text_extents (PycairoContext *o, PyObject *obj) {
}
static PyObject *
-pycairo_text_path (PycairoContext *o, PyObject *obj) {
- PyObject *pyUTF8 = NULL;
- const char *utf8 = NULL;
+pycairo_text_path (PycairoContext *o, PyObject *args) {
+ PyObject *obj;
- /* 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");
- }
+ if (!PyArg_ParseTuple(args, "U:Context.text_path", &obj))
+ return NULL;
+
+ PyObject *pyUTF8 = PyUnicode_AsUTF8String(obj);
+ if (pyUTF8 == NULL)
+ return NULL;
+ const char *utf8 = PyBytes_AS_STRING(pyUTF8);
if (utf8 == NULL)
return NULL;
@@ -1373,12 +1341,12 @@ static PyMethodDef pycairo_methods[] = {
{"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},
+ {"show_text", (PyCFunction)pycairo_show_text, METH_VARARGS},
{"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},
+ {"text_extents", (PyCFunction)pycairo_text_extents, METH_VARARGS},
+ {"text_path", (PyCFunction)pycairo_text_path, METH_VARARGS},
{"transform", (PyCFunction)pycairo_transform, METH_VARARGS},
{"translate", (PyCFunction)pycairo_translate, METH_VARARGS},
{"user_to_device", (PyCFunction)pycairo_user_to_device, METH_VARARGS},
@@ -1388,8 +1356,9 @@ static PyMethodDef pycairo_methods[] = {
};
PyTypeObject PycairoContext_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ // PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.Context", /* tp_name */
sizeof(PycairoContext), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/src/font.c b/src/font.c
index 4377aeb..10d90e7 100644
--- a/src/font.c
+++ b/src/font.c
@@ -66,7 +66,8 @@ font_face_dealloc (PycairoFontFace *o) {
cairo_font_face_destroy (o->font_face);
o->font_face = NULL;
}
- o->ob_type->tp_free((PyObject *) o);
+ //o->ob_type->tp_free((PyObject *) o);
+ Py_TYPE(o)->tp_free(o);
}
static PyObject *
@@ -89,8 +90,9 @@ static PyMethodDef font_face_methods[] = {
*/
PyTypeObject PycairoFontFace_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ //PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.FontFace", /* tp_name */
sizeof(PycairoFontFace), /* tp_basicsize */
0, /* tp_itemsize */
@@ -139,50 +141,39 @@ PyTypeObject PycairoFontFace_Type = {
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))
+ if (!PyArg_ParseTuple(args, "U|ii:ToyFontFace.__new__",
+ &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");
- }
- if (utf8family == NULL)
+ PyObject *pyUTF8 = PyUnicode_AsUTF8String(obj);
+ if (pyUTF8 == NULL)
+ return NULL;
+ const char *utf8 = PyBytes_AS_STRING(pyUTF8);
+ if (utf8 == NULL)
return NULL;
PyObject *o = PycairoFontFace_FromFontFace (
- cairo_toy_font_face_create (utf8family, slant, weight));
+ cairo_toy_font_face_create (utf8, 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));
+ return PyUnicode_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));
+ return PyLong_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));
+ return PyLong_FromLong (cairo_toy_font_face_get_weight (o->font_face));
}
static PyMethodDef toy_font_face_methods[] = {
@@ -194,8 +185,9 @@ static PyMethodDef toy_font_face_methods[] = {
PyTypeObject PycairoToyFontFace_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ //PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.ToyFontFace", /* tp_name */
sizeof(PycairoToyFontFace), /* tp_basicsize */
0, /* tp_itemsize */
@@ -272,7 +264,8 @@ scaled_font_dealloc(PycairoScaledFont *o) {
cairo_scaled_font_destroy (o->scaled_font);
o->scaled_font = NULL;
}
- o->ob_type->tp_free((PyObject *) o);
+ //o->ob_type->tp_free((PyObject *) o);
+ Py_TYPE(o)->tp_free(o);
}
static PyObject *
@@ -317,27 +310,20 @@ scaled_font_get_scale_matrix (PycairoScaledFont *o) {
}
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 *args) {
+ PyObject *obj;
+
+ if (!PyArg_ParseTuple(args, "U:ScaledFont.text_extents", &obj))
+ return NULL;
+
+ PyObject *pyUTF8 = PyUnicode_AsUTF8String(obj);
+ if (pyUTF8 == NULL)
+ return NULL;
+ const char *utf8 = PyBytes_AS_STRING(pyUTF8);
if (utf8 == NULL)
return NULL;
+ cairo_text_extents_t extents;
cairo_scaled_font_text_extents (o->scaled_font, utf8, &extents);
Py_XDECREF(pyUTF8);
RETURN_NULL_IF_CAIRO_SCALED_FONT_ERROR(o->scaled_font);
@@ -362,14 +348,15 @@ static PyMethodDef scaled_font_methods[] = {
{"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},
+ {"text_extents", (PyCFunction)scaled_font_text_extents, METH_VARARGS},
{NULL, NULL, 0, NULL},
};
PyTypeObject PycairoScaledFont_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ //PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.ScaledFont", /* tp_name */
sizeof(PycairoScaledFont), /* tp_basicsize */
0, /* tp_itemsize */
@@ -446,7 +433,8 @@ font_options_dealloc(PycairoFontOptions *o) {
cairo_font_options_destroy (o->font_options);
o->font_options = NULL;
}
- o->ob_type->tp_free((PyObject *) o);
+ //o->ob_type->tp_free((PyObject *) o);
+ Py_TYPE(o)->tp_free(o);
}
static PyObject *
@@ -456,24 +444,24 @@ font_options_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
static PyObject *
font_options_get_antialias (PycairoFontOptions *o) {
- return PyInt_FromLong (cairo_font_options_get_antialias (o->font_options));
+ return PyLong_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
+ return PyLong_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
+ return PyLong_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
+ return PyLong_FromLong (cairo_font_options_get_subpixel_order
(o->font_options));
}
@@ -553,8 +541,9 @@ static PyMethodDef font_options_methods[] = {
PyTypeObject PycairoFontOptions_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ //PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.FontOptions", /* tp_name */
sizeof(PycairoFontOptions), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/src/matrix.c b/src/matrix.c
index 98ccd9f..122e700 100644
--- a/src/matrix.c
+++ b/src/matrix.c
@@ -41,7 +41,8 @@ PycairoMatrix_FromMatrix (const cairo_matrix_t *matrix) {
static void
matrix_dealloc (PycairoMatrix *o) {
- o->ob_type->tp_free((PyObject *)o);
+ //o->ob_type->tp_free((PyObject *)o);
+ Py_TYPE(o)->tp_free(o);
}
static PyObject *
@@ -108,7 +109,7 @@ matrix_repr (PycairoMatrix *o) {
o->matrix.xx, o->matrix.yx,
o->matrix.xy, o->matrix.yy,
o->matrix.x0, o->matrix.y0);
- return PyString_FromString(buf);
+ return PyUnicode_FromString(buf);
}
static PyObject *
@@ -213,45 +214,41 @@ matrix_item (PycairoMatrix *o, Py_ssize_t i) {
}
static PyNumberMethods matrix_as_number = {
- (binaryfunc)0, /*nb_add*/
- (binaryfunc)0, /*nb_subtract*/
- (binaryfunc)matrix_operator_multiply, /*nb_multiply*/
- (binaryfunc)0, /*nb_divide*/
- (binaryfunc)0, /*nb_remainder*/
- (binaryfunc)0, /*nb_divmod*/
- (ternaryfunc)0, /*nb_power*/
- (unaryfunc)0, /*nb_negative*/
- (unaryfunc)0, /*nb_positive*/
- (unaryfunc)0, /*nb_absolute*/
- (inquiry)0, /*nb_nonzero*/
- (unaryfunc)0, /*nb_invert*/
- (binaryfunc)0, /*nb_lshift*/
- (binaryfunc)0, /*nb_rshift*/
- (binaryfunc)0, /*nb_and*/
- (binaryfunc)0, /*nb_xor*/
- (binaryfunc)0, /*nb_or*/
- (coercion)0, /*nb_coerce*/
- (unaryfunc)0, /*nb_int*/
- (unaryfunc)0, /*nb_long*/
- (unaryfunc)0, /*nb_float*/
- (unaryfunc)0, /*nb_oct*/
- (unaryfunc)0, /*nb_hex*/
- 0, /*nb_inplace_add*/
- 0, /*nb_inplace_subtract*/
- 0, /*nb_inplace_multiply*/
- 0, /*nb_inplace_divide*/
- 0, /*nb_inplace_remainder*/
- 0, /*nb_inplace_power*/
- 0, /*nb_inplace_lshift*/
- 0, /*nb_inplace_rshift*/
- 0, /*nb_inplace_and*/
- 0, /*nb_inplace_xor*/
- 0, /*nb_inplace_or*/
- (binaryfunc)0, /* nb_floor_divide */
- 0, /* nb_true_divide */
- 0, /* nb_inplace_floor_divide */
- 0, /* nb_inplace_true_divide */
- (unaryfunc)0, /* nb_index */
+ 0, /* nb_add*/
+ 0, /* nb_subtract*/
+ (binaryfunc)matrix_operator_multiply, /* nb_multiply*/
+ 0, /* nb_remainder*/
+ 0, /* nb_divmod*/
+ 0, /* nb_power*/
+ 0, /* nb_negative*/
+ 0, /* nb_positive*/
+ 0, /* nb_absolute*/
+ 0, /* nb_bool*/
+ 0, /* nb_invert*/
+ 0, /* nb_lshift*/
+ 0, /* nb_rshift*/
+ 0, /* nb_and*/
+ 0, /* nb_xor*/
+ 0, /* nb_or*/
+ 0, /* nb_int*/
+ 0, /* nb_reserved*/
+ 0, /* nb_float*/
+ 0, /* nb_inplace_add*/
+ 0, /* nb_inplace_subtract*/
+ 0, /* nb_inplace_multiply*/
+ 0, /* nb_inplace_divide*/
+ 0, /* nb_inplace_remainder*/
+ 0, /* nb_inplace_power*/
+ 0, /* nb_inplace_lshift*/
+ 0, /* nb_inplace_rshift*/
+ 0, /* nb_inplace_and*/
+ 0, /* nb_inplace_xor*/
+ 0, /* nb_inplace_or*/
+ 0, /* nb_floor_divide */
+ 0, /* nb_true_divide */
+ 0, /* nb_inplace_floor_divide */
+ 0, /* nb_inplace_true_divide */
+ // 0, /* nb_index */
};
static PySequenceMethods matrix_as_sequence = {
@@ -287,8 +284,9 @@ static PyMethodDef matrix_methods[] = {
};
PyTypeObject PycairoMatrix_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ //PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.Matrix", /* tp_name */
sizeof(PycairoMatrix), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/src/path.c b/src/path.c
index 394f25c..e0814d8 100644
--- a/src/path.c
+++ b/src/path.c
@@ -55,15 +55,16 @@ PycairoPath_FromPath (cairo_path_t *path) {
}
static void
-path_dealloc(PycairoPath *p) {
+path_dealloc(PycairoPath *o) {
#ifdef DEBUG
printf("path_dealloc start\n");
#endif
- if (p->path) {
- cairo_path_destroy(p->path);
- p->path = NULL;
+ if (o->path) {
+ cairo_path_destroy(o->path);
+ o->path = NULL;
}
- p->ob_type->tp_free((PyObject *)p);
+ //o->ob_type->tp_free((PyObject *)o);
+ Py_TYPE(o)->tp_free(o);
#ifdef DEBUG
printf("path_dealloc end\n");
#endif
@@ -102,7 +103,7 @@ path_str(PycairoPath *p) {
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);
+ s = PyUnicode_FromString(buf);
if (!s)
goto Done;
ret = PyList_Append(pieces, s);
@@ -114,7 +115,7 @@ path_str(PycairoPath *p) {
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);
+ s = PyUnicode_FromString(buf);
if (!s)
goto Done;
ret = PyList_Append(pieces, s);
@@ -128,7 +129,7 @@ path_str(PycairoPath *p) {
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);
+ s = PyUnicode_FromString(buf);
if (!s)
goto Done;
ret = PyList_Append(pieces, s);
@@ -138,7 +139,7 @@ path_str(PycairoPath *p) {
break;
case CAIRO_PATH_CLOSE_PATH:
- s = PyString_FromString("close path");
+ s = PyUnicode_FromString("close path");
if (!s)
goto Done;
ret = PyList_Append(pieces, s);
@@ -149,10 +150,10 @@ path_str(PycairoPath *p) {
}
}
/* result = "\n".join(pieces) */
- s = PyString_FromString("\n");
+ s = PyUnicode_FromString("\n");
if (s == NULL)
goto Done;
- result = _PyString_Join(s, pieces);
+ result = PyUnicode_Join(s, pieces);
Py_DECREF(s);
Done:
@@ -164,8 +165,9 @@ static PyObject * path_iter(PyObject *seq); /* forward declaration */
PyTypeObject PycairoPath_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ //PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.Path", /* tp_name */
sizeof(PycairoPath), /* tp_basicsize */
0, /* tp_itemsize */
@@ -284,8 +286,9 @@ pathiter_next(PycairoPathiter *it) {
}
PyTypeObject PycairoPathiter_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ //PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.Pathiter", /* tp_name */
sizeof(PycairoPathiter), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/src/pattern.c b/src/pattern.c
index 0676114..61ae1c5 100644
--- a/src/pattern.c
+++ b/src/pattern.c
@@ -90,7 +90,8 @@ pattern_dealloc (PycairoPattern *o) {
}
Py_CLEAR(o->base);
- o->ob_type->tp_free((PyObject *)o);
+ //o->ob_type->tp_free((PyObject *)o);
+ Py_TYPE(o)->tp_free(o);
}
static PyObject *
@@ -102,7 +103,7 @@ pattern_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
static PyObject *
pattern_get_extend (PycairoPattern *o) {
- return PyInt_FromLong (cairo_pattern_get_extend (o->pattern));
+ return PyLong_FromLong (cairo_pattern_get_extend (o->pattern));
}
static PyObject *
@@ -152,8 +153,9 @@ static PyMethodDef pattern_methods[] = {
};
PyTypeObject PycairoPattern_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ //PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.Pattern", /* tp_name */
sizeof(PycairoPattern), /* tp_basicsize */
0, /* tp_itemsize */
@@ -221,8 +223,9 @@ static PyMethodDef solid_pattern_methods[] = {
};
PyTypeObject PycairoSolidPattern_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ //PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.SolidPattern", /* tp_name */
sizeof(PycairoSolidPattern), /* tp_basicsize */
0, /* tp_itemsize */
@@ -279,7 +282,7 @@ surface_pattern_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
static PyObject *
surface_pattern_get_filter (PycairoSurfacePattern *o) {
- return PyInt_FromLong (cairo_pattern_get_filter (o->pattern));
+ return PyLong_FromLong (cairo_pattern_get_filter (o->pattern));
}
static PyObject *
@@ -313,8 +316,9 @@ static PyMethodDef surface_pattern_methods[] = {
};
PyTypeObject PycairoSurfacePattern_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ //PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.SurfacePattern", /* tp_name */
sizeof(PycairoSurfacePattern), /* tp_basicsize */
0, /* tp_itemsize */
@@ -398,8 +402,9 @@ static PyMethodDef gradient_methods[] = {
};
PyTypeObject PycairoGradient_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ //PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.Gradient", /* tp_name */
sizeof(PycairoGradient), /* tp_basicsize */
0, /* tp_itemsize */
@@ -468,8 +473,9 @@ static PyMethodDef linear_gradient_methods[] = {
};
PyTypeObject PycairoLinearGradient_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ //PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.LinearGradient", /* tp_name */
sizeof(PycairoLinearGradient), /* tp_basicsize */
0, /* tp_itemsize */
@@ -540,8 +546,9 @@ static PyMethodDef radial_gradient_methods[] = {
};
PyTypeObject PycairoRadialGradient_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ //PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.RadialGradient", /* tp_name */
sizeof(PycairoRadialGradient), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/src/surface.c b/src/surface.c
index 2e19f14..50480df 100644
--- a/src/surface.c
+++ b/src/surface.c
@@ -117,7 +117,9 @@ PycairoSurface_FromSurface (cairo_surface_t *surface, PyObject *base) {
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#)",
+ // PyObject *res = PyObject_CallMethod ((PyObject *)closure, "write", "(s#)",
+ // data, (Py_ssize_t)length);
+ PyObject *res = PyObject_CallMethod ((PyObject *)closure, "write", "(y#)",
data, (Py_ssize_t)length);
if (res == NULL) {
/* an exception has occurred, it will be picked up later by
@@ -139,7 +141,8 @@ surface_dealloc (PycairoSurface *o) {
}
Py_CLEAR(o->base);
- o->ob_type->tp_free((PyObject *)o);
+ //o->ob_type->tp_free((PyObject *)o);
+ Py_TYPE(o)->tp_free(o);
}
static PyObject *
@@ -190,7 +193,7 @@ surface_flush (PycairoSurface *o) {
static PyObject *
surface_get_content (PycairoSurface *o) {
- return PyInt_FromLong (cairo_surface_get_content (o->surface));
+ return PyLong_FromLong (cairo_surface_get_content (o->surface));
}
static PyObject *
@@ -271,18 +274,27 @@ surface_show_page (PycairoSurface *o) {
#ifdef CAIRO_HAS_PNG_FUNCTIONS
/* METH_O */
static PyObject *
-surface_write_to_png (PycairoSurface *o, PyObject *file) {
+surface_write_to_png (PycairoSurface *o, PyObject *obj) {
cairo_status_t status;
- if (PyObject_TypeCheck (file, &PyString_Type)) {
- /* string (filename) argument */
+ if (PyObject_TypeCheck (obj, &PyUnicode_Type)) {
+ /* unicode (filename) argument */
+
+ PyObject *pyUTF8 = PyUnicode_AsUTF8String(obj);
+ if (pyUTF8 == NULL)
+ return NULL;
+ const char *utf8 = PyBytes_AS_STRING(pyUTF8);
+ if (utf8 == NULL)
+ return NULL;
+
Py_BEGIN_ALLOW_THREADS;
- status = cairo_surface_write_to_png (o->surface,
- PyString_AsString(file));
+ status = cairo_surface_write_to_png (o->surface, utf8);
Py_END_ALLOW_THREADS;
+ Py_XDECREF(pyUTF8);
+
} else { /* file or file-like object argument */
- PyObject* writer = PyObject_GetAttrString (file, "write");
+ PyObject* writer = PyObject_GetAttrString (obj, "write");
if (writer == NULL || !PyCallable_Check (writer)) {
Py_XDECREF(writer);
PyErr_SetString(PyExc_TypeError,
@@ -293,7 +305,7 @@ surface_write_to_png (PycairoSurface *o, PyObject *file) {
Py_DECREF(writer);
Py_BEGIN_ALLOW_THREADS;
status = cairo_surface_write_to_png_stream (o->surface, _write_func,
- file);
+ obj);
Py_END_ALLOW_THREADS;
}
RETURN_NULL_IF_CAIRO_ERROR(status);
@@ -334,8 +346,9 @@ static PyMethodDef surface_methods[] = {
PyTypeObject PycairoSurface_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ //PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.Surface", /* tp_name */
sizeof(PycairoSurface), /* tp_basicsize */
0, /* tp_itemsize */
@@ -404,6 +417,10 @@ image_surface_create_for_data (PyTypeObject *type, PyObject *args) {
Py_ssize_t buffer_len;
PyObject *obj;
+ // buffer function disabled
+ PyErr_SetString(PyExc_NotImplementedError, "Surface.create_for_data: Not Implemented yet.");
+ return NULL;
+
if (!PyArg_ParseTuple(args, "Oiii|i:Surface.create_for_data",
&obj, &format, &width, &height, &stride))
return NULL;
@@ -448,15 +465,15 @@ _read_func (void *closure, unsigned char *data, unsigned int length) {
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)",
+ PyObject *pyBytes = PyObject_CallMethod ((PyObject *)closure, "read", "(i)",
length);
- if (pystr == NULL) {
+ if (pyBytes == 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);
+ int ret = PyBytes_AsStringAndSize(pyBytes, &buffer, &str_length);
if (ret == -1 || str_length < length) {
goto end;
}
@@ -464,26 +481,38 @@ _read_func (void *closure, unsigned char *data, unsigned int length) {
memcpy (data, buffer, str_length);
status = CAIRO_STATUS_SUCCESS;
end:
- Py_XDECREF(pystr);
+ Py_XDECREF(pyBytes);
PyGILState_Release(gstate);
return status;
}
/* METH_O | METH_CLASS */
static PyObject *
-image_surface_create_from_png (PyTypeObject *type, PyObject *file) {
+image_surface_create_from_png (PyTypeObject *type, PyObject *obj) {
PyObject* reader;
cairo_surface_t *is;
- if (PyObject_TypeCheck (file, &PyBaseString_Type)) {
+ // filename (str)
+ if (PyObject_TypeCheck (obj, &PyUnicode_Type)) {
+
+ PyObject *pyUTF8 = PyUnicode_AsUTF8String(obj);
+ if (pyUTF8 == NULL)
+ return NULL;
+ const char *utf8 = PyBytes_AS_STRING(pyUTF8);
+ if (utf8 == NULL)
+ return NULL;
+
Py_BEGIN_ALLOW_THREADS;
- is = cairo_image_surface_create_from_png (PyString_AsString(file));
+ is = cairo_image_surface_create_from_png (utf8);
Py_END_ALLOW_THREADS;
+
+ Py_XDECREF(pyUTF8);
+
return PycairoSurface_FromSurface (is, NULL);
}
/* file or file-like object argument */
- reader = PyObject_GetAttrString (file, "read");
+ reader = PyObject_GetAttrString (obj, "read");
if (reader == NULL || !PyCallable_Check (reader)) {
Py_XDECREF(reader);
PyErr_SetString(PyExc_TypeError,
@@ -494,7 +523,7 @@ image_surface_create_from_png (PyTypeObject *type, PyObject *file) {
Py_DECREF(reader);
Py_BEGIN_ALLOW_THREADS;
- is = cairo_image_surface_create_from_png_stream (_read_func, file);
+ is = cairo_image_surface_create_from_png_stream (_read_func, obj);
Py_END_ALLOW_THREADS;
return PycairoSurface_FromSurface (is, NULL);
}
@@ -507,36 +536,39 @@ image_surface_format_stride_for_width (PyObject *self, PyObject *args) {
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));
+ return PyLong_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);
+ PyErr_SetString(PyExc_NotImplementedError, "Surface.get_data: Not Implemented yet.");
+ return NULL;
+ // 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));
+ return PyLong_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));
+ return PyLong_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));
+ return PyLong_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));
+ return PyLong_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) {
@@ -574,22 +606,25 @@ image_surface_buffer_getwritebuf (PycairoImageSurface *o, int segment,
static int
image_surface_buffer_getsegcount (PycairoImageSurface *o, int *lenp) {
if (lenp) {
- /* report the sum of the sizes (in bytes) of all segments */
+ // 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 */
+ 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,
};
+*/
static PyMethodDef image_surface_methods[] = {
{"create_for_data",(PyCFunction)image_surface_create_for_data,
@@ -611,8 +646,9 @@ static PyMethodDef image_surface_methods[] = {
PyTypeObject PycairoImageSurface_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ // PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.ImageSurface", /* tp_name */
sizeof(PycairoImageSurface), /* tp_basicsize */
0, /* tp_itemsize */
@@ -630,7 +666,8 @@ PyTypeObject PycairoImageSurface_Type = {
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
- &image_surface_as_buffer, /* tp_as_buffer */
+ // &image_surface_as_buffer, /* tp_as_buffer */
+ 0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
0, /* tp_doc */
0, /* tp_traverse */
@@ -664,29 +701,39 @@ PyTypeObject PycairoImageSurface_Type = {
static PyObject *
pdf_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
double width_in_points, height_in_points;
- PyObject *file, *writer;
+ PyObject *obj, *writer;
cairo_surface_t *sfc;
if (!PyArg_ParseTuple(args, "Odd:PDFSurface.__new__",
- &file, &width_in_points, &height_in_points))
+ &obj, &width_in_points, &height_in_points))
return NULL;
- if (file == Py_None) {
+ if (obj == Py_None) {
Py_BEGIN_ALLOW_THREADS;
- sfc = cairo_pdf_surface_create (NULL,
- width_in_points, height_in_points);
+ 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)) {
+
+ }else if (PyObject_TypeCheck (obj, &PyUnicode_Type)) {
/* string (filename) argument */
+
+ PyObject *pyUTF8 = PyUnicode_AsUTF8String(obj);
+ if (pyUTF8 == NULL)
+ return NULL;
+ const char *utf8 = PyBytes_AS_STRING(pyUTF8);
+ if (utf8 == NULL)
+ return NULL;
+
Py_BEGIN_ALLOW_THREADS;
- sfc = cairo_pdf_surface_create (PyString_AsString(file),
- width_in_points, height_in_points);
+ sfc = cairo_pdf_surface_create (utf8, width_in_points, height_in_points);
Py_END_ALLOW_THREADS;
+
+ Py_XDECREF(pyUTF8);
return PycairoSurface_FromSurface (sfc, NULL);
}
+
/* file or file-like object argument */
- writer = PyObject_GetAttrString (file, "write");
+ writer = PyObject_GetAttrString (obj, "write");
if (writer == NULL || !PyCallable_Check (writer)) {
Py_XDECREF(writer);
PyErr_SetString(PyExc_TypeError,
@@ -701,10 +748,10 @@ pdf_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
Py_DECREF(writer);
Py_BEGIN_ALLOW_THREADS;
- sfc = cairo_pdf_surface_create_for_stream (_write_func, file,
+ sfc = cairo_pdf_surface_create_for_stream (_write_func, obj,
width_in_points, height_in_points);
Py_END_ALLOW_THREADS;
- return PycairoSurface_FromSurface (sfc, file);
+ return PycairoSurface_FromSurface (sfc, obj);
}
static PyObject *
@@ -725,8 +772,9 @@ static PyMethodDef pdf_surface_methods[] = {
};
PyTypeObject PycairoPDFSurface_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ // PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.PDFSurface", /* tp_name */
sizeof(PycairoPDFSurface), /* tp_basicsize */
0, /* tp_itemsize */
@@ -778,29 +826,38 @@ PyTypeObject PycairoPDFSurface_Type = {
static PyObject *
ps_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
double width_in_points, height_in_points;
- PyObject *file, *writer;
+ PyObject *obj, *writer;
cairo_surface_t *sfc;
if (!PyArg_ParseTuple(args, "Odd:PSSurface.__new__",
- &file, &width_in_points, &height_in_points))
+ &obj, &width_in_points, &height_in_points))
return NULL;
- if (file == Py_None) {
+ if (obj == Py_None) {
Py_BEGIN_ALLOW_THREADS;
- sfc = cairo_ps_surface_create (NULL,
- width_in_points, height_in_points);
+ 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)) {
+
+ }else if (PyObject_TypeCheck (obj, &PyUnicode_Type)) {
/* string (filename) argument */
+
+ PyObject *pyUTF8 = PyUnicode_AsUTF8String(obj);
+ if (pyUTF8 == NULL)
+ return NULL;
+ const char *utf8 = PyBytes_AS_STRING(pyUTF8);
+ if (utf8 == NULL)
+ return NULL;
+
Py_BEGIN_ALLOW_THREADS;
- sfc = cairo_ps_surface_create (PyString_AsString(file),
- width_in_points, height_in_points);
+ sfc = cairo_ps_surface_create (utf8, width_in_points, height_in_points);
Py_END_ALLOW_THREADS;
+
+ Py_XDECREF(pyUTF8);
return PycairoSurface_FromSurface (sfc, NULL);
}
/* else: file or file-like object argument */
- writer = PyObject_GetAttrString (file, "write");
+ writer = PyObject_GetAttrString (obj, "write");
if (writer == NULL || !PyCallable_Check (writer)) {
Py_XDECREF(writer);
PyErr_SetString(PyExc_TypeError,
@@ -815,10 +872,10 @@ ps_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
Py_DECREF(writer);
Py_BEGIN_ALLOW_THREADS;
- sfc = cairo_ps_surface_create_for_stream (_write_func, file,
+ sfc = cairo_ps_surface_create_for_stream (_write_func, obj,
width_in_points, height_in_points);
Py_END_ALLOW_THREADS;
- return PycairoSurface_FromSurface (sfc, file);
+ return PycairoSurface_FromSurface (sfc, obj);
}
static PyObject *
@@ -865,7 +922,8 @@ ps_surface_ps_level_to_string (PyObject *self, PyObject *args) {
"invalid level argument");
return NULL;
}
- return PyString_FromString(s);
+ //return PyUnicode_FromString(s);
+ return PyUnicode_DecodeASCII(s, strlen(s), NULL);
}
static PyObject *
@@ -918,8 +976,9 @@ static PyMethodDef ps_surface_methods[] = {
};
PyTypeObject PycairoPSSurface_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ //PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.PSSurface", /* tp_name */
sizeof(PycairoPSSurface), /* tp_basicsize */
0, /* tp_itemsize */
@@ -971,29 +1030,38 @@ PyTypeObject PycairoPSSurface_Type = {
static PyObject *
svg_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
double width_in_points, height_in_points;
- PyObject *file, *writer;
+ PyObject *obj, *writer;
cairo_surface_t *sfc;
if (!PyArg_ParseTuple(args, "Odd:SVGSurface.__new__",
- &file, &width_in_points, &height_in_points))
+ &obj, &width_in_points, &height_in_points))
return NULL;
- if (file == Py_None) {
+ if (obj == Py_None) {
Py_BEGIN_ALLOW_THREADS;
- sfc = cairo_svg_surface_create (NULL,
- width_in_points, height_in_points);
+ 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)) {
+
+ }else if (PyObject_TypeCheck (obj, &PyUnicode_Type)) {
/* string (filename) argument */
+
+ PyObject *pyUTF8 = PyUnicode_AsUTF8String(obj);
+ if (pyUTF8 == NULL)
+ return NULL;
+ const char *utf8 = PyBytes_AS_STRING(pyUTF8);
+ if (utf8 == NULL)
+ return NULL;
+
Py_BEGIN_ALLOW_THREADS;
- sfc = cairo_svg_surface_create (PyString_AsString(file),
- width_in_points, height_in_points);
+ sfc = cairo_svg_surface_create (utf8, width_in_points, height_in_points);
Py_END_ALLOW_THREADS;
+
+ Py_XDECREF(pyUTF8);
return PycairoSurface_FromSurface (sfc, NULL);
}
/* else: file or file-like object argument */
- writer = PyObject_GetAttrString (file, "write");
+ writer = PyObject_GetAttrString (obj, "write");
if (writer == NULL || !PyCallable_Check (writer)) {
Py_XDECREF(writer);
PyErr_SetString(PyExc_TypeError,
@@ -1008,10 +1076,10 @@ svg_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
Py_DECREF(writer);
Py_BEGIN_ALLOW_THREADS;
- sfc = cairo_svg_surface_create_for_stream (_write_func, file,
+ sfc = cairo_svg_surface_create_for_stream (_write_func, obj,
width_in_points, height_in_points);
Py_END_ALLOW_THREADS;
- return PycairoSurface_FromSurface (sfc, file);
+ return PycairoSurface_FromSurface (sfc, obj);
}
static PyMethodDef svg_surface_methods[] = {
@@ -1024,8 +1092,9 @@ static PyMethodDef svg_surface_methods[] = {
};
PyTypeObject PycairoSVGSurface_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ //PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.SVGSurface", /* tp_name */
sizeof(PycairoSVGSurface), /* tp_basicsize */
0, /* tp_itemsize */
@@ -1089,8 +1158,9 @@ static PyMethodDef win32_surface_methods[] = {
};
PyTypeObject PycairoWin32Surface_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ //PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.Win32Surface", /* tp_name */
sizeof(PycairoWin32Surface), /* tp_basicsize */
0, /* tp_itemsize */
@@ -1151,8 +1221,9 @@ static PyMethodDef win32_printing_surface_methods[] = {
};
PyTypeObject PycairoWin32PrintingSurface_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ //PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.Win32PrintingSurface", /* tp_name */
sizeof(PycairoWin32PrintingSurface), /* tp_basicsize */
0, /* tp_itemsize */
@@ -1212,12 +1283,14 @@ PyTypeObject PycairoWin32PrintingSurface_Type = {
const void *
xpyb2struct(PyObject *obj, Py_ssize_t *len)
{
- const void *data;
+ const void *data;
- if (PyObject_AsReadBuffer(obj, &data, len) < 0)
- return NULL;
+ // buffer function disabled
+ return NULL;
+ if (PyObject_AsReadBuffer(obj, &data, len) < 0)
+ return NULL;
- return data;
+ return data;
}
static int
@@ -1298,8 +1371,9 @@ static PyMethodDef xcb_surface_methods[] = {
};
PyTypeObject PycairoXCBSurface_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ //PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.XCBSurface", /* tp_name */
sizeof(PycairoXCBSurface), /* tp_basicsize */
0, /* tp_itemsize */
@@ -1357,17 +1431,17 @@ xlib_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
static PyObject *
xlib_surface_get_depth (PycairoXlibSurface *o) {
- return PyInt_FromLong (cairo_xlib_surface_get_depth (o->surface));
+ return PyLong_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));
+ return PyLong_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));
+ return PyLong_FromLong (cairo_xlib_surface_get_width (o->surface));
}
static PyMethodDef xlib_surface_methods[] = {
@@ -1378,8 +1452,9 @@ static PyMethodDef xlib_surface_methods[] = {
};
PyTypeObject PycairoXlibSurface_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ //PyObject_HEAD_INIT(NULL)
+ //0, /* ob_size */
"cairo.XlibSurface", /* tp_name */
sizeof(PycairoXlibSurface), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/src/wscript b/src/wscript
index 41b89c7..7fdeffc 100644
--- a/src/wscript
+++ b/src/wscript
@@ -5,18 +5,18 @@ import os
d = 'src'
-def build(bld):
- print(' %s/build' %d)
+def build(ctx):
+ print(' %s/build()' %d)
# .py files
- bld.new_task_gen(
- features = 'py',
- source = '__init__.py',
+ ctx.new_task_gen(
+ features = 'py',
+ source = '__init__.py',
install_path = '${PYTHONDIR}/cairo',
)
# C extension module
- bld.new_task_gen(
+ ctx.new_task_gen(
features = 'cc cshlib pyext',
source = 'cairomodule.c context.c font.c path.c pattern.c matrix.c surface.c',
target = '_cairo',
@@ -26,7 +26,7 @@ def build(bld):
)
# C API
- bld.install_files(os.path.join(bld.env['PREFIX'], 'include', 'pycairo'),
+ ctx.install_files(os.path.join(ctx.env['PREFIX'], 'include', 'pycairo'),
'py3cairo.h')
# how to strip binaries ?