| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
n |
| 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 |
|
| 38 |
|
| 39 |
PyObject * |
| 40 |
PycairoFontFace_FromFontFace (cairo_font_face_t *font_face) { |
| 41 |
PyTypeObject *type = NULL; |
| 42 |
PyObject *o; |
| 43 |
|
| 44 |
assert (font_face != NULL); |
| 45 |
|
| 46 |
if (Pycairo_Check_Status (cairo_font_face_status (font_face))) { |
| 47 |
cairo_font_face_destroy (font_face); |
| 48 |
return NULL; |
| 49 |
} |
| 50 |
|
| 51 |
switch (cairo_font_face_get_type (font_face)) { |
| 52 |
case CAIRO_FONT_TYPE_TOY: |
| 53 |
type = &PycairoToyFontFace_Type; |
| 54 |
break; |
| 55 |
default: |
| 56 |
type = &PycairoFontFace_Type; |
| 57 |
break; |
| 58 |
} |
| 59 |
o = type->tp_alloc (type, 0); |
| 60 |
if (o == NULL) |
| 61 |
cairo_font_face_destroy (font_face); |
| 62 |
else |
| 63 |
((PycairoFontFace *)o)->font_face = font_face; |
| 64 |
return o; |
| 65 |
} |
| 66 |
|
| 67 |
static void |
| 68 |
font_face_dealloc (PycairoFontFace *o) { |
| 69 |
if (o->font_face) { |
| 70 |
cairo_font_face_destroy (o->font_face); |
| 71 |
o->font_face = NULL; |
| 72 |
} |
| 73 |
Py_TYPE(o)->tp_free(o); |
| 74 |
} |
| 75 |
|
| 76 |
static PyObject * |
| 77 |
font_face_new (PyTypeObject *type, PyObject *args, PyObject *kwds) { |
| 78 |
PyErr_SetString (PyExc_TypeError, "The FontFace type cannot be " |
| 79 |
"instantiated directly, use Context.get_font_face()"); |
| 80 |
return NULL; |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
static PyObject* |
| 97 |
font_face_richcompare (PyObject *self, PyObject *other, int op) |
| 98 |
{ |
| 99 |
if (Py_TYPE(self) == Py_TYPE(other)) |
| 100 |
return Pycairo_richcompare ( |
| 101 |
((PycairoFontFace *)self)->font_face, |
| 102 |
((PycairoFontFace *)other)->font_face, |
| 103 |
op); |
| 104 |
else { |
| 105 |
Py_INCREF(Py_NotImplemented); |
| 106 |
return Py_NotImplemented; |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
static Py_hash_t |
| 111 |
font_face_hash (PyObject *self) |
| 112 |
{ |
| 113 |
return PYCAIRO_Py_hash_t_FromVoidPtr (((PycairoFontFace *)self)->font_face); |
| 114 |
} |
| 115 |
|
| 116 |
PyTypeObject PycairoFontFace_Type = { |
| 117 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 118 |
"cairo.FontFace", |
| 119 |
sizeof(PycairoFontFace), |
| 120 |
0, |
| 121 |
(destructor)font_face_dealloc, |
| 122 |
0, |
| 123 |
0, |
| 124 |
0, |
| 125 |
0, |
| 126 |
0, |
| 127 |
0, |
| 128 |
0, |
| 129 |
0, |
| 130 |
font_face_hash, |
| 131 |
0, |
| 132 |
0, |
| 133 |
0, |
| 134 |
0, |
| 135 |
0, |
| 136 |
Py_TPFLAGS_DEFAULT, |
| 137 |
0, |
| 138 |
0, |
| 139 |
0, |
| 140 |
font_face_richcompare, |
| 141 |
0, |
| 142 |
0, |
| 143 |
0, |
| 144 |
0, |
| 145 |
0, |
| 146 |
0, |
| 147 |
0, |
| 148 |
0, |
| 149 |
0, |
| 150 |
0, |
| 151 |
0, |
| 152 |
0, |
| 153 |
0, |
| 154 |
(newfunc)font_face_new, |
| 155 |
0, |
| 156 |
0, |
| 157 |
0, |
| 158 |
}; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
static PyObject * |
| 164 |
toy_font_face_new (PyTypeObject *type, PyObject *args, PyObject *kwds) { |
| 165 |
const char *utf8; |
| 166 |
PyObject *o; |
| 167 |
cairo_font_slant_t slant; |
| 168 |
cairo_font_weight_t weight; |
| 169 |
int slant_arg = CAIRO_FONT_SLANT_NORMAL; |
| 170 |
int weight_arg = CAIRO_FONT_WEIGHT_NORMAL; |
| 171 |
|
| 172 |
if (!PyArg_ParseTuple (args, "es|ii:ToyFontFace.__new__", |
| 173 |
"utf-8", &utf8, &slant_arg, &weight_arg)) |
| 174 |
return NULL; |
| 175 |
|
| 176 |
slant = (cairo_font_slant_t)slant_arg; |
| 177 |
weight = (cairo_font_weight_t)weight_arg; |
| 178 |
|
| 179 |
o = PycairoFontFace_FromFontFace ( |
| 180 |
cairo_toy_font_face_create (utf8, slant, weight)); |
| 181 |
PyMem_Free((void *)utf8); |
| 182 |
return o; |
| 183 |
} |
| 184 |
|
| 185 |
static PyObject * |
| 186 |
toy_font_get_family (PycairoToyFontFace *o, PyObject *ignored) { |
| 187 |
return PyUnicode_FromString (cairo_toy_font_face_get_family (o->font_face)); |
| 188 |
} |
| 189 |
|
| 190 |
static PyObject * |
| 191 |
toy_font_get_slant (PycairoToyFontFace *o, PyObject *ignored) { |
| 192 |
RETURN_INT_ENUM (FontSlant, cairo_toy_font_face_get_slant (o->font_face)); |
| 193 |
} |
| 194 |
|
| 195 |
static PyObject * |
| 196 |
toy_font_get_weight (PycairoToyFontFace *o, PyObject *ignored) { |
| 197 |
RETURN_INT_ENUM (FontWeight, cairo_toy_font_face_get_weight (o->font_face)); |
| 198 |
} |
| 199 |
|
| 200 |
static PyMethodDef toy_font_face_methods[] = { |
| 201 |
{"get_family", (PyCFunction)toy_font_get_family, METH_NOARGS}, |
| 202 |
{"get_slant", (PyCFunction)toy_font_get_slant, METH_NOARGS}, |
| 203 |
{"get_weight", (PyCFunction)toy_font_get_weight, METH_NOARGS}, |
| 204 |
{NULL, NULL, 0, NULL}, |
| 205 |
}; |
| 206 |
|
| 207 |
|
| 208 |
PyTypeObject PycairoToyFontFace_Type = { |
| 209 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 210 |
"cairo.ToyFontFace", |
| 211 |
sizeof(PycairoToyFontFace), |
| 212 |
0, |
| 213 |
0, |
| 214 |
0, |
| 215 |
0, |
| 216 |
0, |
| 217 |
0, |
| 218 |
0, |
| 219 |
0, |
| 220 |
0, |
| 221 |
0, |
| 222 |
0, |
| 223 |
0, |
| 224 |
0, |
| 225 |
0, |
| 226 |
0, |
| 227 |
0, |
| 228 |
Py_TPFLAGS_DEFAULT, |
| 229 |
0, |
| 230 |
0, |
| 231 |
0, |
| 232 |
0, |
| 233 |
0, |
| 234 |
0, |
| 235 |
0, |
| 236 |
toy_font_face_methods, |
| 237 |
0, |
| 238 |
0, |
| 239 |
&PycairoFontFace_Type, |
| 240 |
0, |
| 241 |
0, |
| 242 |
0, |
| 243 |
0, |
| 244 |
0, |
| 245 |
0, |
| 246 |
(newfunc)toy_font_face_new, |
| 247 |
0, |
| 248 |
0, |
| 249 |
0, |
| 250 |
}; |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
PyObject * |
| 256 |
PycairoScaledFont_FromScaledFont (cairo_scaled_font_t *scaled_font) { |
| 257 |
PyObject *o; |
| 258 |
|
| 259 |
assert (scaled_font != NULL); |
| 260 |
|
| 261 |
if (Pycairo_Check_Status (cairo_scaled_font_status (scaled_font))) { |
| 262 |
cairo_scaled_font_destroy (scaled_font); |
| 263 |
return NULL; |
| 264 |
} |
| 265 |
|
| 266 |
o = PycairoScaledFont_Type.tp_alloc (&PycairoScaledFont_Type, 0); |
| 267 |
if (o == NULL) |
| 268 |
cairo_scaled_font_destroy (scaled_font); |
| 269 |
else |
| 270 |
((PycairoScaledFont *)o)->scaled_font = scaled_font; |
| 271 |
return o; |
| 272 |
} |
| 273 |
|
| 274 |
static void |
| 275 |
scaled_font_dealloc(PycairoScaledFont *o) { |
| 276 |
if (o->scaled_font) { |
| 277 |
cairo_scaled_font_destroy (o->scaled_font); |
| 278 |
o->scaled_font = NULL; |
| 279 |
} |
| 280 |
Py_TYPE(o)->tp_free(o); |
| 281 |
} |
| 282 |
|
| 283 |
static PyObject * |
| 284 |
scaled_font_new (PyTypeObject *type, PyObject *args, PyObject *kwds) { |
| 285 |
PycairoFontFace *ff; |
| 286 |
PycairoFontOptions *fo; |
| 287 |
PycairoMatrix *mx1, *mx2; |
| 288 |
|
| 289 |
if (!PyArg_ParseTuple(args, "O!O!O!O!:ScaledFont.__new__", |
| 290 |
&PycairoFontFace_Type, &ff, |
| 291 |
&PycairoMatrix_Type, &mx1, |
| 292 |
&PycairoMatrix_Type, &mx2, |
| 293 |
&PycairoFontOptions_Type, &fo)) |
| 294 |
return NULL; |
| 295 |
return PycairoScaledFont_FromScaledFont ( |
| 296 |
cairo_scaled_font_create (ff->font_face, &mx1->matrix, |
| 297 |
&mx2->matrix, fo->font_options)); |
| 298 |
} |
| 299 |
|
| 300 |
static PyObject * |
| 301 |
scaled_font_extents (PycairoScaledFont *o, PyObject *ignored) { |
| 302 |
cairo_font_extents_t e; |
| 303 |
|
| 304 |
cairo_scaled_font_extents (o->scaled_font, &e); |
| 305 |
RETURN_NULL_IF_CAIRO_SCALED_FONT_ERROR(o->scaled_font); |
| 306 |
return Py_BuildValue ("(ddddd)", e.ascent, e.descent, e.height, |
| 307 |
e.max_x_advance, e.max_y_advance); |
| 308 |
} |
| 309 |
|
| 310 |
static PyObject * |
| 311 |
scaled_font_get_font_face (PycairoScaledFont *o, PyObject *ignored) { |
| 312 |
return PycairoFontFace_FromFontFace ( |
| 313 |
cairo_font_face_reference ( |
| 314 |
cairo_scaled_font_get_font_face (o->scaled_font))); |
| 315 |
} |
| 316 |
|
| 317 |
static PyObject * |
| 318 |
scaled_font_get_scale_matrix (PycairoScaledFont *o, PyObject *ignored) { |
| 319 |
cairo_matrix_t matrix; |
| 320 |
cairo_scaled_font_get_scale_matrix (o->scaled_font, &matrix); |
| 321 |
return PycairoMatrix_FromMatrix (&matrix); |
| 322 |
} |
| 323 |
|
| 324 |
static PyObject * |
| 325 |
scaled_font_text_extents (PycairoScaledFont *o, PyObject *args) { |
| 326 |
cairo_text_extents_t extents; |
| 327 |
const char *utf8; |
| 328 |
PyObject *ext_args, *res; |
| 329 |
|
| 330 |
if (!PyArg_ParseTuple (args, |
| 331 |
"es:ScaledFont.text_extents", "utf-8", &utf8)) |
| 332 |
return NULL; |
| 333 |
|
| 334 |
Py_BEGIN_ALLOW_THREADS; |
| 335 |
cairo_scaled_font_text_extents (o->scaled_font, utf8, &extents); |
| 336 |
Py_END_ALLOW_THREADS; |
| 337 |
|
| 338 |
PyMem_Free ((void *)utf8); |
| 339 |
|
| 340 |
RETURN_NULL_IF_CAIRO_SCALED_FONT_ERROR (o->scaled_font); |
| 341 |
ext_args = Py_BuildValue ("(dddddd)", extents.x_bearing, extents.y_bearing, |
| 342 |
extents.width, extents.height, extents.x_advance, |
| 343 |
extents.y_advance); |
| 344 |
res = PyObject_Call ((PyObject *)&PycairoTextExtents_Type, ext_args, NULL); |
| 345 |
Py_DECREF (ext_args); |
| 346 |
return res; |
| 347 |
} |
| 348 |
|
| 349 |
static PyObject * |
| 350 |
scaled_font_get_ctm (PycairoScaledFont *o, PyObject *ignored) { |
| 351 |
cairo_matrix_t matrix; |
| 352 |
|
| 353 |
Py_BEGIN_ALLOW_THREADS; |
| 354 |
cairo_scaled_font_get_ctm (o->scaled_font, &matrix); |
| 355 |
Py_END_ALLOW_THREADS; |
| 356 |
|
| 357 |
return PycairoMatrix_FromMatrix (&matrix); |
| 358 |
} |
| 359 |
|
| 360 |
static PyObject * |
| 361 |
scaled_font_get_font_matrix (PycairoScaledFont *o, PyObject *ignored) { |
| 362 |
cairo_matrix_t matrix; |
| 363 |
|
| 364 |
Py_BEGIN_ALLOW_THREADS; |
| 365 |
cairo_scaled_font_get_font_matrix (o->scaled_font, &matrix); |
| 366 |
Py_END_ALLOW_THREADS; |
| 367 |
|
| 368 |
return PycairoMatrix_FromMatrix (&matrix); |
| 369 |
} |
| 370 |
|
| 371 |
static PyObject * |
| 372 |
scaled_font_get_font_options (PycairoScaledFont *o, PyObject *ignored) { |
| 373 |
cairo_font_options_t *options = cairo_font_options_create(); |
| 374 |
|
| 375 |
Py_BEGIN_ALLOW_THREADS; |
| 376 |
cairo_scaled_font_get_font_options (o->scaled_font, options); |
| 377 |
Py_END_ALLOW_THREADS; |
| 378 |
|
| 379 |
return PycairoFontOptions_FromFontOptions (options); |
| 380 |
} |
| 381 |
|
| 382 |
static PyObject * |
| 383 |
scaled_font_text_to_glyphs (PycairoScaledFont *o, PyObject *args) { |
| 384 |
const char *utf8; |
| 385 |
double x, y; |
| 386 |
int with_clusters = 1; |
| 387 |
|
| 388 |
cairo_status_t status; |
| 389 |
cairo_glyph_t *glyphs = NULL; |
| 390 |
int num_glyphs; |
| 391 |
cairo_text_cluster_t *clusters = NULL; |
| 392 |
int num_clusters; |
| 393 |
cairo_text_cluster_flags_t cluster_flags; |
| 394 |
|
| 395 |
int i; |
| 396 |
PyObject *glyph_list = NULL; |
| 397 |
PyObject *cluster_list = NULL; |
| 398 |
PyObject *flags = NULL; |
| 399 |
PyObject *pyglyph, *glyph_args; |
| 400 |
PyObject *pycluster, *cluster_args; |
| 401 |
|
| 402 |
if (!PyArg_ParseTuple (args, |
| 403 |
"ddes|i:ScaledFont.text_to_glyphs", |
| 404 |
&x, &y, "utf-8", &utf8, &with_clusters)) |
| 405 |
return NULL; |
| 406 |
|
| 407 |
Py_BEGIN_ALLOW_THREADS; |
| 408 |
status = cairo_scaled_font_text_to_glyphs ( |
| 409 |
o->scaled_font, |
| 410 |
x, y, |
| 411 |
utf8, -1, |
| 412 |
&glyphs, &num_glyphs, |
| 413 |
(with_clusters) ? &clusters : NULL, |
| 414 |
(with_clusters) ? &num_clusters : NULL, |
| 415 |
(with_clusters) ? &cluster_flags : NULL); |
| 416 |
Py_END_ALLOW_THREADS; |
| 417 |
|
| 418 |
PyMem_Free ((void *)utf8); |
| 419 |
RETURN_NULL_IF_CAIRO_ERROR (status); |
| 420 |
|
| 421 |
glyph_list = PyList_New (num_glyphs); |
| 422 |
if (glyph_list == NULL) |
| 423 |
goto error; |
| 424 |
for(i=0; i < num_glyphs; i++) { |
| 425 |
cairo_glyph_t *glyph = &glyphs[i]; |
| 426 |
glyph_args = Py_BuildValue( |
| 427 |
"(kdd)", glyph->index, glyph->x, glyph->y); |
| 428 |
if (glyph_args == NULL) |
| 429 |
goto error; |
| 430 |
pyglyph = PyObject_Call( |
| 431 |
(PyObject *)&PycairoGlyph_Type, glyph_args, NULL); |
| 432 |
if (pyglyph == NULL) { |
| 433 |
Py_DECREF (glyph_args); |
| 434 |
goto error; |
| 435 |
} |
| 436 |
PyList_SET_ITEM (glyph_list, i, pyglyph); |
| 437 |
} |
| 438 |
cairo_glyph_free (glyphs); |
| 439 |
glyphs = NULL; |
| 440 |
|
| 441 |
if (with_clusters) { |
| 442 |
cluster_list = PyList_New (num_clusters); |
| 443 |
if (cluster_list == NULL) |
| 444 |
goto error; |
| 445 |
for(i=0; i < num_clusters; i++) { |
| 446 |
cairo_text_cluster_t *cluster = &clusters[i]; |
| 447 |
cluster_args = Py_BuildValue( |
| 448 |
"(ii)", cluster->num_bytes, cluster->num_glyphs); |
| 449 |
if (cluster_args == NULL) |
| 450 |
goto error; |
| 451 |
pycluster = PyObject_Call( |
| 452 |
(PyObject *)&PycairoTextCluster_Type, cluster_args, NULL); |
| 453 |
if (pycluster == NULL) { |
| 454 |
Py_DECREF (cluster_args); |
| 455 |
goto error; |
| 456 |
} |
| 457 |
PyList_SET_ITEM (cluster_list, i, pycluster); |
| 458 |
} |
| 459 |
cairo_text_cluster_free (clusters); |
| 460 |
clusters = NULL; |
| 461 |
|
| 462 |
flags = CREATE_INT_ENUM (TextClusterFlags, cluster_flags); |
| 463 |
if (flags == NULL) |
| 464 |
goto error; |
| 465 |
|
| 466 |
return Py_BuildValue ("(NNN)", glyph_list, cluster_list, flags); |
| 467 |
} else { |
| 468 |
return glyph_list; |
| 469 |
} |
| 470 |
error: |
| 471 |
cairo_glyph_free (glyphs); |
| 472 |
cairo_text_cluster_free (clusters); |
| 473 |
Py_XDECREF (glyph_list); |
| 474 |
Py_XDECREF (cluster_list); |
| 475 |
Py_XDECREF (flags); |
| 476 |
return NULL; |
| 477 |
} |
| 478 |
|
| 479 |
static PyObject * |
| 480 |
scaled_font_glyph_extents (PycairoScaledFont *o, PyObject *args) { |
| 481 |
int num_glyphs = -1; |
| 482 |
cairo_glyph_t *glyphs; |
| 483 |
cairo_text_extents_t extents; |
| 484 |
PyObject *py_object, *ext_args, *res; |
| 485 |
|
| 486 |
if (!PyArg_ParseTuple (args, "O|i:ScaledFont.glyph_extents", |
| 487 |
&py_object, &num_glyphs)) |
| 488 |
return NULL; |
| 489 |
|
| 490 |
glyphs = _PycairoGlyphs_AsGlyphs (py_object, &num_glyphs); |
| 491 |
if (glyphs == NULL) |
| 492 |
return NULL; |
| 493 |
|
| 494 |
Py_BEGIN_ALLOW_THREADS |
| 495 |
cairo_scaled_font_glyph_extents ( |
| 496 |
o->scaled_font, glyphs, num_glyphs, &extents); |
| 497 |
Py_END_ALLOW_THREADS; |
| 498 |
|
| 499 |
PyMem_Free (glyphs); |
| 500 |
RETURN_NULL_IF_CAIRO_SCALED_FONT_ERROR (o->scaled_font); |
| 501 |
ext_args = Py_BuildValue ("(dddddd)", extents.x_bearing, extents.y_bearing, |
| 502 |
extents.width, extents.height, extents.x_advance, |
| 503 |
extents.y_advance); |
| 504 |
res = PyObject_Call ((PyObject *)&PycairoTextExtents_Type, ext_args, NULL); |
| 505 |
Py_DECREF (ext_args); |
| 506 |
return res; |
| 507 |
} |
| 508 |
|
| 509 |
static PyMethodDef scaled_font_methods[] = { |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
{"extents", (PyCFunction)scaled_font_extents, METH_NOARGS}, |
| 516 |
{"get_font_face", (PyCFunction)scaled_font_get_font_face, METH_NOARGS}, |
| 517 |
{"get_ctm", (PyCFunction)scaled_font_get_ctm, METH_NOARGS}, |
| 518 |
{"get_font_matrix", (PyCFunction)scaled_font_get_font_matrix, METH_NOARGS}, |
| 519 |
{"get_font_options", (PyCFunction)scaled_font_get_font_options, METH_NOARGS}, |
| 520 |
{"get_scale_matrix", (PyCFunction)scaled_font_get_scale_matrix, METH_VARARGS}, |
| 521 |
{"text_extents", (PyCFunction)scaled_font_text_extents, METH_VARARGS}, |
| 522 |
{"text_to_glyphs", (PyCFunction)scaled_font_text_to_glyphs, METH_VARARGS}, |
| 523 |
{"glyph_extents", (PyCFunction)scaled_font_glyph_extents, METH_VARARGS}, |
| 524 |
{NULL, NULL, 0, NULL}, |
| 525 |
}; |
| 526 |
|
| 527 |
static PyObject* |
| 528 |
scaled_font_richcompare (PyObject *self, PyObject *other, int op) |
| 529 |
{ |
| 530 |
if (Py_TYPE(self) == Py_TYPE(other)) |
| 531 |
return Pycairo_richcompare ( |
| 532 |
((PycairoScaledFont *)self)->scaled_font, |
| 533 |
((PycairoScaledFont *)other)->scaled_font, |
| 534 |
op); |
| 535 |
else { |
| 536 |
Py_INCREF(Py_NotImplemented); |
| 537 |
return Py_NotImplemented; |
| 538 |
} |
| 539 |
} |
| 540 |
|
| 541 |
static Py_hash_t |
| 542 |
scaled_font_hash (PyObject *self) |
| 543 |
{ |
| 544 |
return PYCAIRO_Py_hash_t_FromVoidPtr ( |
| 545 |
((PycairoScaledFont *)self)->scaled_font); |
| 546 |
} |
| 547 |
|
| 548 |
PyTypeObject PycairoScaledFont_Type = { |
| 549 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 550 |
"cairo.ScaledFont", |
| 551 |
sizeof(PycairoScaledFont), |
| 552 |
0, |
| 553 |
(destructor)scaled_font_dealloc, |
| 554 |
0, |
| 555 |
0, |
| 556 |
0, |
| 557 |
0, |
| 558 |
0, |
| 559 |
0, |
| 560 |
0, |
| 561 |
0, |
| 562 |
scaled_font_hash, |
| 563 |
0, |
| 564 |
0, |
| 565 |
0, |
| 566 |
0, |
| 567 |
0, |
| 568 |
Py_TPFLAGS_DEFAULT, |
| 569 |
0, |
| 570 |
0, |
| 571 |
0, |
| 572 |
scaled_font_richcompare, |
| 573 |
0, |
| 574 |
0, |
| 575 |
0, |
| 576 |
scaled_font_methods, |
| 577 |
0, |
| 578 |
0, |
| 579 |
0, |
| 580 |
0, |
| 581 |
0, |
| 582 |
0, |
| 583 |
0, |
| 584 |
0, |
| 585 |
0, |
| 586 |
(newfunc)scaled_font_new, |
| 587 |
0, |
| 588 |
0, |
| 589 |
0, |
| 590 |
}; |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
PyObject * |
| 596 |
PycairoFontOptions_FromFontOptions (cairo_font_options_t *font_options) { |
| 597 |
PyObject *o; |
| 598 |
|
| 599 |
assert (font_options != NULL); |
| 600 |
|
| 601 |
if (Pycairo_Check_Status (cairo_font_options_status (font_options))) { |
| 602 |
cairo_font_options_destroy (font_options); |
| 603 |
return NULL; |
| 604 |
} |
| 605 |
|
| 606 |
o = PycairoFontOptions_Type.tp_alloc (&PycairoFontOptions_Type, 0); |
| 607 |
if (o == NULL) |
| 608 |
cairo_font_options_destroy (font_options); |
| 609 |
else |
| 610 |
((PycairoFontOptions *)o)->font_options = font_options; |
| 611 |
return o; |
| 612 |
} |
| 613 |
|
| 614 |
static void |
| 615 |
font_options_dealloc(PycairoFontOptions *o) { |
| 616 |
if (o->font_options) { |
| 617 |
cairo_font_options_destroy (o->font_options); |
| 618 |
o->font_options = NULL; |
| 619 |
} |
| 620 |
Py_TYPE(o)->tp_free(o); |
| 621 |
} |
| 622 |
|
| 623 |
static PyObject * |
| 624 |
font_options_new (PyTypeObject *type, PyObject *args, PyObject *kwds) { |
| 625 |
|
| 626 |
if (!PyArg_ParseTuple (args, ":FontOptions.__new__")) |
| 627 |
return NULL; |
| 628 |
|
| 629 |
return PycairoFontOptions_FromFontOptions (cairo_font_options_create()); |
| 630 |
} |
| 631 |
|
| 632 |
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 15, 12) |
| 633 |
static PyObject * |
| 634 |
font_options_set_variations (PycairoFontOptions *o, PyObject *args) { |
| 635 |
const char *variations; |
| 636 |
PyObject *maybe_none; |
| 637 |
|
| 638 |
if (!PyArg_ParseTuple (args, "O:FontOptions.set_variations", &maybe_none)) |
| 639 |
return NULL; |
| 640 |
|
| 641 |
if (maybe_none != Py_None) { |
| 642 |
if (!PyArg_ParseTuple (args, |
| 643 |
"es:FontOptions.set_variations", "utf-8", |
| 644 |
&variations)) |
| 645 |
return NULL; |
| 646 |
} else { |
| 647 |
variations = NULL; |
| 648 |
} |
| 649 |
|
| 650 |
Py_BEGIN_ALLOW_THREADS; |
| 651 |
cairo_font_options_set_variations (o->font_options, variations); |
| 652 |
Py_END_ALLOW_THREADS; |
| 653 |
|
| 654 |
if (variations != NULL) |
| 655 |
PyMem_Free((void *)variations); |
| 656 |
|
| 657 |
RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(o->font_options); |
| 658 |
Py_RETURN_NONE; |
| 659 |
} |
| 660 |
|
| 661 |
static PyObject * |
| 662 |
font_options_get_variations (PycairoFontOptions *o, PyObject *ignored) { |
| 663 |
const char *variations; |
| 664 |
|
| 665 |
Py_BEGIN_ALLOW_THREADS; |
| 666 |
variations = cairo_font_options_get_variations (o->font_options); |
| 667 |
Py_END_ALLOW_THREADS; |
| 668 |
|
| 669 |
if (variations == NULL) |
| 670 |
Py_RETURN_NONE; |
| 671 |
|
| 672 |
return PyUnicode_FromString (variations); |
| 673 |
} |
| 674 |
#endif |
| 675 |
|
| 676 |
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 17, 8) |
| 677 |
static PyObject * |
| 678 |
font_options_set_color_mode (PycairoFontOptions *o, PyObject *args) { |
| 679 |
cairo_color_mode_t color_mode; |
| 680 |
int color_mode_arg; |
| 681 |
|
| 682 |
if (!PyArg_ParseTuple (args, "i:FontOptions.set_color_mode", &color_mode_arg)) |
| 683 |
return NULL; |
| 684 |
|
| 685 |
color_mode = (cairo_color_mode_t)color_mode_arg; |
| 686 |
|
| 687 |
cairo_font_options_set_color_mode (o->font_options, color_mode); |
| 688 |
RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(o->font_options); |
| 689 |
Py_RETURN_NONE; |
| 690 |
} |
| 691 |
|
| 692 |
static PyObject * |
| 693 |
font_options_get_color_mode (PycairoFontOptions *o, PyObject *ignored) { |
| 694 |
RETURN_INT_ENUM (ColorMode, cairo_font_options_get_color_mode (o->font_options)); |
| 695 |
} |
| 696 |
|
| 697 |
static PyObject * |
| 698 |
font_options_set_color_palette (PycairoFontOptions *o, PyObject *args) { |
| 699 |
unsigned int color_palette; |
| 700 |
|
| 701 |
if (!PyArg_ParseTuple (args, "I:FontOptions.set_color_palette", &color_palette)) |
| 702 |
return NULL; |
| 703 |
|
| 704 |
cairo_font_options_set_color_palette (o->font_options, color_palette); |
| 705 |
RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(o->font_options); |
| 706 |
Py_RETURN_NONE; |
| 707 |
} |
| 708 |
|
| 709 |
static PyObject * |
| 710 |
font_options_get_color_palette (PycairoFontOptions *o, PyObject *ignored) { |
| 711 |
return PyLong_FromUnsignedLong (cairo_font_options_get_color_palette (o->font_options)); |
| 712 |
} |
| 713 |
|
| 714 |
static PyObject * |
| 715 |
font_options_set_custom_palette_color (PycairoFontOptions *o, PyObject *args) { |
| 716 |
double red, green, blue, alpha; |
| 717 |
unsigned int index; |
| 718 |
|
| 719 |
if (!PyArg_ParseTuple (args, "Idddd:FontOptions.set_custom_palette_color", |
| 720 |
&index, &red, &green, &blue, &alpha)) |
| 721 |
return NULL; |
| 722 |
|
| 723 |
cairo_font_options_set_custom_palette_color (o->font_options, index, red, green, blue, alpha); |
| 724 |
RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(o->font_options); |
| 725 |
Py_RETURN_NONE; |
| 726 |
} |
| 727 |
|
| 728 |
static PyObject * |
| 729 |
font_options_get_custom_palette_color (PycairoFontOptions *o, PyObject *args) { |
| 730 |
double red, green, blue, alpha; |
| 731 |
unsigned int index; |
| 732 |
cairo_status_t status; |
| 733 |
|
| 734 |
if (!PyArg_ParseTuple (args, "I:FontOptions.get_custom_palette_color", &index)) |
| 735 |
return NULL; |
| 736 |
|
| 737 |
status = cairo_font_options_get_custom_palette_color (o->font_options, index, &red, &green, &blue, &alpha); |
| 738 |
RETURN_NULL_IF_CAIRO_ERROR (status); |
| 739 |
return Py_BuildValue("(dddd)", red, green, blue, alpha); |
| 740 |
} |
| 741 |
#endif |
| 742 |
|
| 743 |
static PyObject * |
| 744 |
font_options_get_antialias (PycairoFontOptions *o, PyObject *ignored) { |
| 745 |
RETURN_INT_ENUM (Antialias, cairo_font_options_get_antialias (o->font_options)); |
| 746 |
} |
| 747 |
|
| 748 |
static PyObject * |
| 749 |
font_options_get_hint_metrics (PycairoFontOptions *o, PyObject *ignored) { |
| 750 |
RETURN_INT_ENUM (HintMetrics, |
| 751 |
cairo_font_options_get_hint_metrics (o->font_options)); |
| 752 |
} |
| 753 |
|
| 754 |
static PyObject * |
| 755 |
font_options_get_hint_style (PycairoFontOptions *o, PyObject *ignored) { |
| 756 |
RETURN_INT_ENUM (HintStyle, |
| 757 |
cairo_font_options_get_hint_style (o->font_options)); |
| 758 |
} |
| 759 |
|
| 760 |
static PyObject * |
| 761 |
font_options_get_subpixel_order (PycairoFontOptions *o, PyObject *ignored) { |
| 762 |
RETURN_INT_ENUM (SubpixelOrder, |
| 763 |
cairo_font_options_get_subpixel_order (o->font_options)); |
| 764 |
} |
| 765 |
|
| 766 |
static PyObject * |
| 767 |
font_options_set_antialias (PycairoFontOptions *o, PyObject *args) { |
| 768 |
cairo_antialias_t antialias; |
| 769 |
int antialias_arg = CAIRO_ANTIALIAS_DEFAULT; |
| 770 |
|
| 771 |
if (!PyArg_ParseTuple (args, "|i:FontOptions.set_antialias", &antialias_arg)) |
| 772 |
return NULL; |
| 773 |
|
| 774 |
antialias = (cairo_antialias_t)antialias_arg; |
| 775 |
|
| 776 |
cairo_font_options_set_antialias (o->font_options, antialias); |
| 777 |
RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(o->font_options); |
| 778 |
Py_RETURN_NONE; |
| 779 |
} |
| 780 |
|
| 781 |
static PyObject * |
| 782 |
font_options_set_hint_metrics (PycairoFontOptions *o, PyObject *args) { |
| 783 |
cairo_hint_metrics_t hint_metrics; |
| 784 |
int hint_metrics_arg = CAIRO_HINT_METRICS_DEFAULT; |
| 785 |
|
| 786 |
if (!PyArg_ParseTuple (args, "|i:FontOptions.set_hint_metrics", |
| 787 |
&hint_metrics_arg)) |
| 788 |
return NULL; |
| 789 |
|
| 790 |
hint_metrics = (cairo_hint_metrics_t)hint_metrics_arg; |
| 791 |
|
| 792 |
cairo_font_options_set_hint_metrics (o->font_options, hint_metrics); |
| 793 |
RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(o->font_options); |
| 794 |
Py_RETURN_NONE; |
| 795 |
} |
| 796 |
|
| 797 |
static PyObject * |
| 798 |
font_options_set_hint_style (PycairoFontOptions *o, PyObject *args) { |
| 799 |
cairo_hint_style_t hint_style; |
| 800 |
int hint_style_arg = CAIRO_HINT_STYLE_DEFAULT; |
| 801 |
|
| 802 |
if (!PyArg_ParseTuple (args, "|i:FontOptions.set_hint_style", |
| 803 |
&hint_style_arg)) |
| 804 |
return NULL; |
| 805 |
|
| 806 |
hint_style = (cairo_hint_style_t)hint_style_arg; |
| 807 |
|
| 808 |
cairo_font_options_set_hint_style (o->font_options, hint_style); |
| 809 |
RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(o->font_options); |
| 810 |
Py_RETURN_NONE; |
| 811 |
} |
| 812 |
|
| 813 |
static PyObject * |
| 814 |
font_options_set_subpixel_order (PycairoFontOptions *o, PyObject *args) { |
| 815 |
cairo_subpixel_order_t subpixel_order; |
| 816 |
int subpixel_order_arg = CAIRO_SUBPIXEL_ORDER_DEFAULT; |
| 817 |
|
| 818 |
if (!PyArg_ParseTuple (args, "|i:FontOptions.set_subpixel_order", |
| 819 |
&subpixel_order_arg)) |
| 820 |
return NULL; |
| 821 |
|
| 822 |
subpixel_order = (cairo_subpixel_order_t)subpixel_order_arg; |
| 823 |
|
| 824 |
cairo_font_options_set_subpixel_order (o->font_options, subpixel_order); |
| 825 |
RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(o->font_options); |
| 826 |
Py_RETURN_NONE; |
| 827 |
} |
| 828 |
|
| 829 |
static PyObject * |
| 830 |
font_options_copy (PycairoFontOptions *o, PyObject *ignored) { |
| 831 |
cairo_font_options_t *new; |
| 832 |
|
| 833 |
Py_BEGIN_ALLOW_THREADS; |
| 834 |
new = cairo_font_options_copy (o->font_options); |
| 835 |
Py_END_ALLOW_THREADS; |
| 836 |
|
| 837 |
return PycairoFontOptions_FromFontOptions (new); |
| 838 |
} |
| 839 |
|
| 840 |
static PyObject * |
| 841 |
font_options_hash (PycairoFontOptions *o, PyObject *ignored) { |
| 842 |
unsigned long hash; |
| 843 |
|
| 844 |
Py_BEGIN_ALLOW_THREADS; |
| 845 |
hash = cairo_font_options_hash (o->font_options); |
| 846 |
Py_END_ALLOW_THREADS; |
| 847 |
|
| 848 |
return PyLong_FromUnsignedLong (hash); |
| 849 |
} |
| 850 |
|
| 851 |
static PyObject * |
| 852 |
font_options_equal (PycairoFontOptions *o, PyObject *args) { |
| 853 |
PycairoFontOptions *other; |
| 854 |
cairo_bool_t result; |
| 855 |
|
| 856 |
if (!PyArg_ParseTuple(args, "O!:FontOptions.equal", |
| 857 |
&PycairoFontOptions_Type, &other)) |
| 858 |
return NULL; |
| 859 |
|
| 860 |
Py_BEGIN_ALLOW_THREADS; |
| 861 |
result = cairo_font_options_equal (o->font_options, other->font_options); |
| 862 |
Py_END_ALLOW_THREADS; |
| 863 |
|
| 864 |
return PyBool_FromLong(result); |
| 865 |
} |
| 866 |
|
| 867 |
static PyObject * |
| 868 |
font_options_merge (PycairoFontOptions *o, PyObject *args) { |
| 869 |
PycairoFontOptions *other; |
| 870 |
|
| 871 |
if (!PyArg_ParseTuple(args, "O!:FontOptions.merge", |
| 872 |
&PycairoFontOptions_Type, &other)) |
| 873 |
return NULL; |
| 874 |
|
| 875 |
Py_BEGIN_ALLOW_THREADS; |
| 876 |
cairo_font_options_merge (o->font_options, other->font_options); |
| 877 |
Py_END_ALLOW_THREADS; |
| 878 |
|
| 879 |
Py_RETURN_NONE; |
| 880 |
} |
| 881 |
|
| 882 |
static PyMethodDef font_options_methods[] = { |
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 15, 12) |
| 888 |
{"get_variations", (PyCFunction)font_options_get_variations, METH_NOARGS}, |
| 889 |
{"set_variations", (PyCFunction)font_options_set_variations, METH_VARARGS}, |
| 890 |
#endif |
| 891 |
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 17, 8) |
| 892 |
{"get_color_mode", (PyCFunction)font_options_get_color_mode, METH_NOARGS}, |
| 893 |
{"set_color_mode", (PyCFunction)font_options_set_color_mode, METH_VARARGS}, |
| 894 |
{"get_color_palette", (PyCFunction)font_options_get_color_palette, METH_NOARGS}, |
| 895 |
{"set_color_palette", (PyCFunction)font_options_set_color_palette, METH_VARARGS}, |
| 896 |
{"get_custom_palette_color", (PyCFunction)font_options_get_custom_palette_color, METH_VARARGS}, |
| 897 |
{"set_custom_palette_color", (PyCFunction)font_options_set_custom_palette_color, METH_VARARGS}, |
| 898 |
#endif |
| 899 |
{"get_antialias", (PyCFunction)font_options_get_antialias, METH_NOARGS}, |
| 900 |
{"get_hint_metrics", (PyCFunction)font_options_get_hint_metrics, |
| 901 |
METH_NOARGS}, |
| 902 |
{"get_hint_style", (PyCFunction)font_options_get_hint_style, METH_NOARGS}, |
| 903 |
{"get_subpixel_order",(PyCFunction)font_options_get_subpixel_order, |
| 904 |
METH_NOARGS}, |
| 905 |
{"set_antialias", (PyCFunction)font_options_set_antialias, METH_VARARGS}, |
| 906 |
{"set_hint_metrics", (PyCFunction)font_options_set_hint_metrics, |
| 907 |
METH_VARARGS}, |
| 908 |
{"set_hint_style", (PyCFunction)font_options_set_hint_style, METH_VARARGS}, |
| 909 |
{"set_subpixel_order",(PyCFunction)font_options_set_subpixel_order, |
| 910 |
METH_VARARGS}, |
| 911 |
{"copy", (PyCFunction)font_options_copy, METH_NOARGS}, |
| 912 |
{"hash", (PyCFunction)font_options_hash, METH_NOARGS}, |
| 913 |
{"equal", (PyCFunction)font_options_equal, METH_VARARGS}, |
| 914 |
{"merge", (PyCFunction)font_options_merge, METH_VARARGS}, |
| 915 |
{NULL, NULL, 0, NULL}, |
| 916 |
}; |
| 917 |
|
| 918 |
static PyObject * |
| 919 |
font_options_tp_richcompare (PyObject *a, PyObject *b, int op) { |
| 920 |
PycairoFontOptions *other; |
| 921 |
cairo_bool_t is_equal; |
| 922 |
|
| 923 |
if (!PyObject_TypeCheck (b, &PycairoFontOptions_Type) || |
| 924 |
(op != Py_EQ && op != Py_NE)) { |
| 925 |
Py_INCREF (Py_NotImplemented); |
| 926 |
return Py_NotImplemented; |
| 927 |
} |
| 928 |
|
| 929 |
other = (PycairoFontOptions *)b; |
| 930 |
|
| 931 |
Py_BEGIN_ALLOW_THREADS; |
| 932 |
is_equal = cairo_font_options_equal (((PycairoFontOptions *)a)->font_options, |
| 933 |
other->font_options); |
| 934 |
Py_END_ALLOW_THREADS; |
| 935 |
|
| 936 |
if (is_equal == (op == Py_EQ)) |
| 937 |
Py_RETURN_TRUE; |
| 938 |
else |
| 939 |
Py_RETURN_FALSE; |
| 940 |
} |
| 941 |
|
| 942 |
PyTypeObject PycairoFontOptions_Type = { |
| 943 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 944 |
"cairo.FontOptions", |
| 945 |
sizeof(PycairoFontOptions), |
| 946 |
0, |
| 947 |
(destructor)font_options_dealloc, |
| 948 |
0, |
| 949 |
0, |
| 950 |
0, |
| 951 |
0, |
| 952 |
0, |
| 953 |
0, |
| 954 |
0, |
| 955 |
0, |
| 956 |
(hashfunc)PyObject_HashNotImplemented, |
| 957 |
0, |
| 958 |
0, |
| 959 |
0, |
| 960 |
0, |
| 961 |
0, |
| 962 |
Py_TPFLAGS_DEFAULT, |
| 963 |
0, |
| 964 |
0, |
| 965 |
0, |
| 966 |
font_options_tp_richcompare, |
| 967 |
0, |
| 968 |
0, |
| 969 |
0, |
| 970 |
font_options_methods, |
| 971 |
0, |
| 972 |
0, |
| 973 |
0, |
| 974 |
0, |
| 975 |
0, |
| 976 |
0, |
| 977 |
0, |
| 978 |
0, |
| 979 |
0, |
| 980 |
(newfunc)font_options_new, |
| 981 |
0, |
| 982 |
0, |
| 983 |
0, |
| 984 |
}; |