[cairo-commit] pycairo/cairo pycairo-context.c,1.78,1.79
Steve Chaplin
commit at pdx.freedesktop.org
Sat Jan 13 02:50:41 PST 2007
Committed by: stevech1097
Update of /cvs/cairo/pycairo/cairo
In directory kemper:/tmp/cvs-serv19504/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.78
retrieving revision 1.79
diff -u -d -r1.78 -r1.79
--- pycairo-context.c 8 Jan 2007 01:17:49 -0000 1.78
+++ pycairo-context.c 13 Jan 2007 10:50:37 -0000 1.79
@@ -491,6 +491,120 @@
}
static PyObject *
+pycairo_glyph_extents (PycairoContext *o, PyObject *args)
+{
+ /* almost identical code to pycairo_show_glyphs */
+ int num_glyphs = -1, length, i;
+ cairo_glyph_t *glyphs = NULL, *glyph;
+ cairo_text_extents_t extents;
+ PyObject *py_glyphs, *py_seq = NULL;
+
+ if (!PyArg_ParseTuple (args, "O|i:Context.glyph_path",
+ &py_glyphs, &num_glyphs))
+ return NULL;
+
+ py_glyphs = PySequence_Fast (py_glyphs,
+ "first argument 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,
+ "glyph items 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);
+ }
+ cairo_glyph_extents (o->ctx, glyphs, num_glyphs, &extents);
+ PyMem_Free (glyphs);
+ Py_DECREF(py_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);
+ error:
+ PyMem_Free (glyphs);
+ Py_DECREF(py_glyphs);
+ Py_XDECREF(py_seq);
+ return NULL;
+}
+
+static PyObject *
+pycairo_glyph_path (PycairoContext *o, PyObject *args)
+{
+ /* almost identical code to pycairo_show_glyphs */
+ int num_glyphs = -1, length, i;
+ cairo_glyph_t *glyphs = NULL, *glyph;
+ PyObject *py_glyphs, *py_seq = NULL;
+
+ if (!PyArg_ParseTuple (args, "O|i:Context.glyph_path",
+ &py_glyphs, &num_glyphs))
+ return NULL;
+
+ py_glyphs = PySequence_Fast (py_glyphs,
+ "first argument 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,
+ "glyph items 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);
+ }
+ cairo_glyph_path (o->ctx, glyphs, num_glyphs);
+ PyMem_Free (glyphs);
+ Py_DECREF(py_glyphs);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
+ error:
+ PyMem_Free (glyphs);
+ Py_DECREF(py_glyphs);
+ Py_XDECREF(py_seq);
+ return NULL;
+}
+
+static PyObject *
pycairo_identity_matrix (PycairoContext *o)
{
cairo_identity_matrix (o->ctx);
@@ -1040,16 +1154,68 @@
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, length, i;
+ cairo_glyph_t *glyphs = NULL, *glyph;
+ PyObject *py_glyphs, *py_seq = NULL;
+
+ if (!PyArg_ParseTuple (args, "O|i:Context.show_glyphs",
+ &py_glyphs, &num_glyphs))
+ return NULL;
+
+ py_glyphs = PySequence_Fast (py_glyphs,
+ "first argument 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,
+ "glyph items 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);
+ }
+ cairo_show_glyphs (o->ctx, glyphs, num_glyphs);
+ PyMem_Free (glyphs);
+ Py_DECREF(py_glyphs);
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_RETURN_NONE;
+ error:
+ PyMem_Free (glyphs);
+ Py_DECREF(py_glyphs);
+ Py_XDECREF(py_seq);
+ return NULL;
+}
+
+static PyObject *
pycairo_show_page (PycairoContext *o)
{
cairo_show_page (o->ctx);
@@ -1237,8 +1403,8 @@
{"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 */
- /* glyph_path - undocumented */
+ {"glyph_extents", (PyCFunction)pycairo_glyph_extents, METH_VARARGS},
+ {"glyph_path", (PyCFunction)pycairo_glyph_path, METH_VARARGS},
{"identity_matrix", (PyCFunction)pycairo_identity_matrix, METH_NOARGS},
{"in_fill", (PyCFunction)pycairo_in_fill, METH_VARARGS},
{"in_stroke", (PyCFunction)pycairo_in_stroke, METH_VARARGS},
@@ -1286,7 +1452,7 @@
{"set_source_surface",(PyCFunction)pycairo_set_source_surface,
METH_VARARGS},
{"set_tolerance", (PyCFunction)pycairo_set_tolerance, METH_VARARGS},
- /* show_glyphs - undocumented */
+ {"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},
More information about the cairo-commit
mailing list