[cairo-commit] pycairo/cairo pycairo-context.c,1.66,1.67
Steve Chaplin
commit at pdx.freedesktop.org
Sat Jan 21 23:31:43 PST 2006
Committed by: stevech1097
Update of /cvs/cairo/pycairo/cairo
In directory gabe:/tmp/cvs-serv12208/cairo
Modified Files:
pycairo-context.c
Log Message:
'SC'
Index: pycairo-context.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-context.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- pycairo-context.c 5 Sep 2005 01:22:18 -0000 1.66
+++ pycairo-context.c 22 Jan 2006 07:31:41 -0000 1.67
@@ -35,6 +35,27 @@
#endif
#include "pycairo-private.h"
+/* Take a PyBaseString (str or unicode) object and return a pointer to the
+ * UTF-8 encoded string.
+ */
+static char *
+__PyBaseString_AsUTF8 (PyObject *o)
+{
+ if (PyString_Check(o)) {
+ /* A plain ASCII string is also a valid UTF-8 string */
+ return PyString_AsString(o);
+
+ } else if (PyUnicode_Check(o)) {
+ PyObject *u = PyUnicode_AsUTF8String(o);
+ if (u != NULL) {
+ char *utf8 = PyString_AsString(u);
+ Py_DECREF(u);
+ return utf8;
+ }
+ }
+ return NULL;
+}
+
/* PycairoContext_FromContext
* Create a new PycairoContext from a cairo_t
* ctx - a cairo_t to 'wrap' into a Python object.
@@ -649,12 +670,17 @@
static PyObject *
pycairo_select_font_face (PycairoContext *o, PyObject *args)
{
+ PyObject *obj;
const char *family;
cairo_font_slant_t slant = CAIRO_FONT_SLANT_NORMAL;
cairo_font_weight_t weight = CAIRO_FONT_WEIGHT_NORMAL;
- if (!PyArg_ParseTuple(args, "s|ii:Context.select_font_face",
- &family, &slant, &weight))
+ if (!PyArg_ParseTuple(args, "O!|ii:Context.select_font_face",
+ &PyBaseString_Type, &obj, &slant, &weight))
+ return NULL;
+
+ family = __PyBaseString_AsUTF8 (obj);
+ if (family==NULL)
return NULL;
cairo_select_font_face (o->ctx, family, slant, weight);
@@ -961,12 +987,15 @@
}
static PyObject *
-pycairo_show_text (PycairoContext *o, PyObject *args)
+pycairo_show_text (PycairoContext *o, PyObject *obj)
{
- const char *utf8;
-
- if (!PyArg_ParseTuple(args, "s:Context.show_text", &utf8))
+ const char *utf8 = __PyBaseString_AsUTF8 (obj);
+ if (utf8==NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "Context.show_text() argument must be a string or "
+ "unicode object");
return NULL;
+ }
cairo_show_text (o->ctx, utf8);
if (Pycairo_Check_Status (cairo_status (o->ctx)))
@@ -1003,13 +1032,16 @@
}
static PyObject *
-pycairo_text_extents (PycairoContext *o, PyObject *args)
+pycairo_text_extents (PycairoContext *o, PyObject *obj)
{
- const char *utf8;
cairo_text_extents_t extents;
-
- if (!PyArg_ParseTuple (args, "s:Context.text_extents", &utf8))
+ const char *utf8 = __PyBaseString_AsUTF8 (obj);
+ if (utf8==NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "Context.text_extents() argument must be a string or "
+ "unicode object");
return NULL;
+ }
cairo_text_extents (o->ctx, utf8, &extents);
if (Pycairo_Check_Status (cairo_status (o->ctx)))
@@ -1020,12 +1052,15 @@
}
static PyObject *
-pycairo_text_path (PycairoContext *o, PyObject *args)
+pycairo_text_path (PycairoContext *o, PyObject *obj)
{
- const char *utf8;
-
- if (!PyArg_ParseTuple (args, "s:Context.text_path", &utf8))
+ const char *utf8 = __PyBaseString_AsUTF8 (obj);
+ if (utf8==NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "Context.text_path() argument must be a string or "
+ "unicode object");
return NULL;
+ }
cairo_text_path (o->ctx, utf8);
if (Pycairo_Check_Status (cairo_status (o->ctx)))
@@ -1177,12 +1212,12 @@
{"set_tolerance", (PyCFunction)pycairo_set_tolerance, METH_VARARGS},
/* show_glyphs - undocumented */
{"show_page", (PyCFunction)pycairo_show_page, METH_NOARGS},
- {"show_text", (PyCFunction)pycairo_show_text, METH_VARARGS},
+ {"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_VARARGS},
- {"text_path", (PyCFunction)pycairo_text_path, METH_VARARGS},
+ {"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},
More information about the cairo-commit
mailing list