| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
r |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#define PY_SSIZE_T_CLEAN |
| 32 |
#include <Python.h> |
| 33 |
|
| 34 |
#include "private.h" |
| 35 |
|
| 36 |
|
| 37 |
int |
| 38 |
_PyTextCluster_AsTextCluster (PyObject *pyobj, cairo_text_cluster_t *cluster) { |
| 39 |
long num_bytes, num_glyphs; |
| 40 |
|
| 41 |
if (!PyObject_TypeCheck (pyobj, &PycairoTextCluster_Type)) { |
| 42 |
PyErr_SetString (PyExc_TypeError, |
| 43 |
"item must be of type cairo.TextCluster"); |
| 44 |
return -1; |
| 45 |
} |
| 46 |
|
| 47 |
num_bytes = PyLong_AsLong ( |
| 48 |
PySequence_Fast_GET_ITEM (pyobj, 0)); |
| 49 |
if (PyErr_Occurred ()) |
| 50 |
return -1; |
| 51 |
if (num_bytes > INT_MAX || num_bytes < INT_MIN) { |
| 52 |
PyErr_SetString (PyExc_ValueError, "num_bytes out of range"); |
| 53 |
return -1; |
| 54 |
} |
| 55 |
cluster->num_bytes = (int)num_bytes; |
| 56 |
|
| 57 |
num_glyphs = PyLong_AsLong ( |
| 58 |
PySequence_Fast_GET_ITEM (pyobj, 1)); |
| 59 |
if (PyErr_Occurred ()) |
| 60 |
return -1; |
| 61 |
if (num_glyphs > INT_MAX || num_glyphs < INT_MIN) { |
| 62 |
PyErr_SetString (PyExc_ValueError, "num_glyphs out of range"); |
| 63 |
return -1; |
| 64 |
} |
| 65 |
cluster->num_glyphs = (int)num_glyphs; |
| 66 |
|
| 67 |
return 0; |
| 68 |
} |
| 69 |
|
| 70 |
static char *KWDS[] = {"num_bytes", "num_glyphs", NULL}; |
| 71 |
|
| 72 |
static PyObject * |
| 73 |
text_cluster_new (PyTypeObject *type, PyObject *args, PyObject *kwds) { |
| 74 |
int num_bytes, num_glyphs; |
| 75 |
PyObject *tuple_args, *result; |
| 76 |
|
| 77 |
if (!PyArg_ParseTupleAndKeywords (args, kwds, "ii:TextCluster.__new__", |
| 78 |
KWDS, &num_bytes, &num_glyphs)) |
| 79 |
return NULL; |
| 80 |
|
| 81 |
tuple_args = Py_BuildValue ("((ii))", num_bytes, num_glyphs); |
| 82 |
if (tuple_args == NULL) |
| 83 |
return NULL; |
| 84 |
result = PyTuple_Type.tp_new (type, tuple_args, NULL); |
| 85 |
Py_DECREF (tuple_args); |
| 86 |
return result; |
| 87 |
} |
| 88 |
|
| 89 |
static PyObject* |
| 90 |
text_cluster_repr(PyObject *self) { |
| 91 |
PyObject *format, *result; |
| 92 |
|
| 93 |
format = PyUnicode_FromString ( |
| 94 |
"cairo.TextCluster(num_bytes=%r, num_glyphs=%r)"); |
| 95 |
if (format == NULL) |
| 96 |
return NULL; |
| 97 |
result = PyUnicode_Format (format, self); |
| 98 |
Py_DECREF (format); |
| 99 |
return result; |
| 100 |
} |
| 101 |
|
| 102 |
static PyObject * |
| 103 |
text_cluster_get_num_bytes(PyObject *self, void *closure) |
| 104 |
{ |
| 105 |
PyObject *obj = PyTuple_GetItem (self, 0); |
| 106 |
Py_XINCREF (obj); |
| 107 |
return obj; |
| 108 |
} |
| 109 |
|
| 110 |
static PyObject * |
| 111 |
text_cluster_get_num_glyphs(PyObject *self, void *closure) |
| 112 |
{ |
| 113 |
PyObject *obj = PyTuple_GetItem (self, 1); |
| 114 |
Py_XINCREF (obj); |
| 115 |
return obj; |
| 116 |
} |
| 117 |
|
| 118 |
static PyGetSetDef text_cluster_getset[] = { |
| 119 |
{"num_bytes", (getter)text_cluster_get_num_bytes}, |
| 120 |
{"num_glyphs", (getter)text_cluster_get_num_glyphs}, |
| 121 |
{NULL,}, |
| 122 |
}; |
| 123 |
|
| 124 |
PyTypeObject PycairoTextCluster_Type = { |
| 125 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 126 |
"cairo.TextCluster", |
| 127 |
sizeof(PycairTextCluster), |
| 128 |
0, |
| 129 |
0, |
| 130 |
0, |
| 131 |
0, |
| 132 |
0, |
| 133 |
0, |
| 134 |
(reprfunc)text_cluster_repr, |
| 135 |
0, |
| 136 |
0, |
| 137 |
0, |
| 138 |
0, |
| 139 |
0, |
| 140 |
0, |
| 141 |
0, |
| 142 |
0, |
| 143 |
0, |
| 144 |
Py_TPFLAGS_DEFAULT, |
| 145 |
0, |
| 146 |
0, |
| 147 |
0, |
| 148 |
0, |
| 149 |
0, |
| 150 |
0, |
| 151 |
0, |
| 152 |
0, |
| 153 |
0, |
| 154 |
text_cluster_getset, |
| 155 |
0, |
| 156 |
0, |
| 157 |
0, |
| 158 |
0, |
| 159 |
0, |
| 160 |
0, |
| 161 |
0, |
| 162 |
(newfunc)text_cluster_new, |
| 163 |
0, |
| 164 |
0, |
| 165 |
0, |
| 166 |
}; |