| 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 |
PycairoPattern_FromPattern (cairo_pattern_t *pattern, PyObject *base) { |
| 41 |
PyTypeObject *type = NULL; |
| 42 |
PyObject *o; |
| 43 |
|
| 44 |
assert (pattern != NULL); |
| 45 |
|
| 46 |
if (Pycairo_Check_Status (cairo_pattern_status (pattern))) { |
| 47 |
cairo_pattern_destroy (pattern); |
| 48 |
return NULL; |
| 49 |
} |
| 50 |
|
| 51 |
switch (cairo_pattern_get_type (pattern)) { |
| 52 |
case CAIRO_PATTERN_TYPE_SOLID: |
| 53 |
type = &PycairoSolidPattern_Type; |
| 54 |
break; |
| 55 |
case CAIRO_PATTERN_TYPE_SURFACE: |
| 56 |
type = &PycairoSurfacePattern_Type; |
| 57 |
break; |
| 58 |
case CAIRO_PATTERN_TYPE_LINEAR: |
| 59 |
type = &PycairoLinearGradient_Type; |
| 60 |
break; |
| 61 |
case CAIRO_PATTERN_TYPE_RADIAL: |
| 62 |
type = &PycairoRadialGradient_Type; |
| 63 |
break; |
| 64 |
case CAIRO_PATTERN_TYPE_MESH: |
| 65 |
type = &PycairoMeshPattern_Type; |
| 66 |
break; |
| 67 |
case CAIRO_PATTERN_TYPE_RASTER_SOURCE: |
| 68 |
type = &PycairoRasterSourcePattern_Type; |
| 69 |
break; |
| 70 |
default: |
| 71 |
type = &PycairoPattern_Type; |
| 72 |
break; |
| 73 |
} |
| 74 |
|
| 75 |
o = type->tp_alloc(type, 0); |
| 76 |
if (o == NULL) { |
| 77 |
cairo_pattern_destroy (pattern); |
| 78 |
} else { |
| 79 |
((PycairoPattern *)o)->pattern = pattern; |
| 80 |
Py_XINCREF(base); |
| 81 |
((PycairoPattern *)o)->base = base; |
| 82 |
} |
| 83 |
return o; |
| 84 |
} |
| 85 |
|
| 86 |
static void |
| 87 |
pattern_dealloc (PycairoPattern *o) { |
| 88 |
if (o->pattern) { |
| 89 |
cairo_pattern_destroy (o->pattern); |
| 90 |
o->pattern = NULL; |
| 91 |
} |
| 92 |
Py_CLEAR(o->base); |
| 93 |
|
| 94 |
Py_TYPE(o)->tp_free(o); |
| 95 |
} |
| 96 |
|
| 97 |
static PyObject * |
| 98 |
pattern_new (PyTypeObject *type, PyObject *args, PyObject *kwds) { |
| 99 |
PyErr_SetString(PyExc_TypeError, |
| 100 |
"The Pattern type cannot be instantiated"); |
| 101 |
return NULL; |
| 102 |
} |
| 103 |
|
| 104 |
static PyObject * |
| 105 |
pattern_get_extend (PycairoPattern *o, PyObject *ignored) { |
| 106 |
RETURN_INT_ENUM (Extend, cairo_pattern_get_extend (o->pattern)); |
| 107 |
} |
| 108 |
|
| 109 |
static PyObject * |
| 110 |
pattern_get_matrix (PycairoPattern *o, PyObject *ignored) { |
| 111 |
cairo_matrix_t matrix; |
| 112 |
cairo_pattern_get_matrix (o->pattern, &matrix); |
| 113 |
return PycairoMatrix_FromMatrix (&matrix); |
| 114 |
} |
| 115 |
|
| 116 |
static PyObject * |
| 117 |
pattern_set_extend (PycairoPattern *o, PyObject *args) { |
| 118 |
cairo_extend_t extend; |
| 119 |
int extend_arg; |
| 120 |
|
| 121 |
if (!PyArg_ParseTuple (args, "i:Pattern.set_extend", &extend_arg)) |
| 122 |
return NULL; |
| 123 |
|
| 124 |
extend = (cairo_extend_t)extend_arg; |
| 125 |
|
| 126 |
cairo_pattern_set_extend (o->pattern, extend); |
| 127 |
Py_RETURN_NONE; |
| 128 |
} |
| 129 |
|
| 130 |
static PyObject * |
| 131 |
pattern_set_matrix (PycairoPattern *o, PyObject *args) { |
| 132 |
PycairoMatrix *m; |
| 133 |
|
| 134 |
if (!PyArg_ParseTuple (args, "O!:Pattern.set_matrix", |
| 135 |
&PycairoMatrix_Type, &m)) |
| 136 |
return NULL; |
| 137 |
|
| 138 |
cairo_pattern_set_matrix (o->pattern, &m->matrix); |
| 139 |
Py_RETURN_NONE; |
| 140 |
} |
| 141 |
|
| 142 |
static PyObject * |
| 143 |
pattern_get_filter (PycairoPattern *o, PyObject *ignored) { |
| 144 |
cairo_filter_t filter; |
| 145 |
|
| 146 |
Py_BEGIN_ALLOW_THREADS; |
| 147 |
filter = cairo_pattern_get_filter (o->pattern); |
| 148 |
Py_END_ALLOW_THREADS; |
| 149 |
|
| 150 |
RETURN_INT_ENUM (Filter, filter); |
| 151 |
} |
| 152 |
|
| 153 |
static PyObject * |
| 154 |
pattern_set_filter (PycairoPattern *o, PyObject *args) { |
| 155 |
cairo_filter_t filter; |
| 156 |
int filter_arg; |
| 157 |
|
| 158 |
if (!PyArg_ParseTuple (args, "i:Pattern.set_filter", &filter_arg)) |
| 159 |
return NULL; |
| 160 |
|
| 161 |
filter = (cairo_filter_t)filter_arg; |
| 162 |
|
| 163 |
Py_BEGIN_ALLOW_THREADS; |
| 164 |
cairo_pattern_set_filter (o->pattern, filter); |
| 165 |
Py_END_ALLOW_THREADS; |
| 166 |
|
| 167 |
Py_RETURN_NONE; |
| 168 |
} |
| 169 |
|
| 170 |
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 18, 0) |
| 171 |
static PyObject * |
| 172 |
pattern_get_dither (PycairoPattern *o, PyObject *ignored) { |
| 173 |
cairo_dither_t dither; |
| 174 |
|
| 175 |
Py_BEGIN_ALLOW_THREADS; |
| 176 |
dither = cairo_pattern_get_dither (o->pattern); |
| 177 |
Py_END_ALLOW_THREADS; |
| 178 |
|
| 179 |
RETURN_INT_ENUM (Dither, dither); |
| 180 |
} |
| 181 |
|
| 182 |
static PyObject * |
| 183 |
pattern_set_dither (PycairoPattern *o, PyObject *args) { |
| 184 |
cairo_dither_t dither; |
| 185 |
int dither_arg; |
| 186 |
|
| 187 |
if (!PyArg_ParseTuple (args, "i:Pattern.set_dither", &dither_arg)) |
| 188 |
return NULL; |
| 189 |
|
| 190 |
dither = (cairo_dither_t)dither_arg; |
| 191 |
|
| 192 |
Py_BEGIN_ALLOW_THREADS; |
| 193 |
cairo_pattern_set_dither (o->pattern, dither); |
| 194 |
Py_END_ALLOW_THREADS; |
| 195 |
|
| 196 |
Py_RETURN_NONE; |
| 197 |
} |
| 198 |
#endif |
| 199 |
|
| 200 |
static PyMethodDef pattern_methods[] = { |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
{"get_extend", (PyCFunction)pattern_get_extend, METH_NOARGS }, |
| 210 |
{"get_matrix", (PyCFunction)pattern_get_matrix, METH_NOARGS }, |
| 211 |
{"set_extend", (PyCFunction)pattern_set_extend, METH_VARARGS }, |
| 212 |
{"set_matrix", (PyCFunction)pattern_set_matrix, METH_VARARGS }, |
| 213 |
{"get_filter", (PyCFunction)pattern_get_filter, METH_NOARGS }, |
| 214 |
{"set_filter", (PyCFunction)pattern_set_filter, METH_VARARGS }, |
| 215 |
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 18, 0) |
| 216 |
{"get_dither", (PyCFunction)pattern_get_dither, METH_NOARGS }, |
| 217 |
{"set_dither", (PyCFunction)pattern_set_dither, METH_VARARGS }, |
| 218 |
#endif |
| 219 |
{NULL, NULL, 0, NULL}, |
| 220 |
}; |
| 221 |
|
| 222 |
static PyObject* |
| 223 |
pattern_richcompare (PyObject *self, PyObject *other, int op) |
| 224 |
{ |
| 225 |
if (Py_TYPE(self) == Py_TYPE(other)) |
| 226 |
return Pycairo_richcompare ( |
| 227 |
((PycairoPattern *)self)->pattern, |
| 228 |
((PycairoPattern *)other)->pattern, |
| 229 |
op); |
| 230 |
else { |
| 231 |
Py_INCREF(Py_NotImplemented); |
| 232 |
return Py_NotImplemented; |
| 233 |
} |
| 234 |
} |
| 235 |
|
| 236 |
static Py_hash_t |
| 237 |
pattern_hash (PyObject *self) |
| 238 |
{ |
| 239 |
return PYCAIRO_Py_hash_t_FromVoidPtr (((PycairoPattern *)self)->pattern); |
| 240 |
} |
| 241 |
|
| 242 |
PyTypeObject PycairoPattern_Type = { |
| 243 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 244 |
"cairo.Pattern", |
| 245 |
sizeof(PycairoPattern), |
| 246 |
0, |
| 247 |
(destructor)pattern_dealloc, |
| 248 |
0, |
| 249 |
0, |
| 250 |
0, |
| 251 |
0, |
| 252 |
0, |
| 253 |
0, |
| 254 |
0, |
| 255 |
0, |
| 256 |
pattern_hash, |
| 257 |
0, |
| 258 |
0, |
| 259 |
0, |
| 260 |
0, |
| 261 |
0, |
| 262 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, |
| 263 |
0, |
| 264 |
0, |
| 265 |
0, |
| 266 |
pattern_richcompare, |
| 267 |
0, |
| 268 |
0, |
| 269 |
0, |
| 270 |
pattern_methods, |
| 271 |
0, |
| 272 |
0, |
| 273 |
0, |
| 274 |
0, |
| 275 |
0, |
| 276 |
0, |
| 277 |
0, |
| 278 |
0, |
| 279 |
0, |
| 280 |
(newfunc)pattern_new, |
| 281 |
0, |
| 282 |
0, |
| 283 |
0, |
| 284 |
}; |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
static PyObject * |
| 290 |
solid_pattern_new (PyTypeObject *type, PyObject *args, PyObject *kwds) { |
| 291 |
double r, g, b, a = 1.0; |
| 292 |
if (!PyArg_ParseTuple (args, "ddd|d:SolidPattern.__new__", &r, &g, &b, &a)) |
| 293 |
return NULL; |
| 294 |
return PycairoPattern_FromPattern (cairo_pattern_create_rgba (r, g, b, a), |
| 295 |
NULL); |
| 296 |
} |
| 297 |
|
| 298 |
static PyObject * |
| 299 |
solid_pattern_get_rgba (PycairoSolidPattern *o, PyObject *ignored) { |
| 300 |
double red, green, blue, alpha; |
| 301 |
cairo_pattern_get_rgba (o->pattern, &red, &green, &blue, &alpha); |
| 302 |
return Py_BuildValue("(dddd)", red, green, blue, alpha); |
| 303 |
} |
| 304 |
|
| 305 |
static PyMethodDef solid_pattern_methods[] = { |
| 306 |
{"get_rgba", (PyCFunction)solid_pattern_get_rgba, METH_NOARGS }, |
| 307 |
{NULL, NULL, 0, NULL}, |
| 308 |
}; |
| 309 |
|
| 310 |
PyTypeObject PycairoSolidPattern_Type = { |
| 311 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 312 |
"cairo.SolidPattern", |
| 313 |
sizeof(PycairoSolidPattern), |
| 314 |
0, |
| 315 |
0, |
| 316 |
0, |
| 317 |
0, |
| 318 |
0, |
| 319 |
0, |
| 320 |
0, |
| 321 |
0, |
| 322 |
0, |
| 323 |
0, |
| 324 |
0, |
| 325 |
0, |
| 326 |
0, |
| 327 |
0, |
| 328 |
0, |
| 329 |
0, |
| 330 |
Py_TPFLAGS_DEFAULT, |
| 331 |
0, |
| 332 |
0, |
| 333 |
0, |
| 334 |
0, |
| 335 |
0, |
| 336 |
0, |
| 337 |
0, |
| 338 |
solid_pattern_methods, |
| 339 |
0, |
| 340 |
0, |
| 341 |
&PycairoPattern_Type, |
| 342 |
0, |
| 343 |
0, |
| 344 |
0, |
| 345 |
0, |
| 346 |
0, |
| 347 |
0, |
| 348 |
(newfunc)solid_pattern_new, |
| 349 |
0, |
| 350 |
0, |
| 351 |
0, |
| 352 |
}; |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
static PyObject * |
| 357 |
surface_pattern_new (PyTypeObject *type, PyObject *args, PyObject *kwds) { |
| 358 |
PycairoSurface *s; |
| 359 |
if (!PyArg_ParseTuple (args, "O!:SurfacePattern.__new__", |
| 360 |
&PycairoSurface_Type, &s)) |
| 361 |
return NULL; |
| 362 |
return PycairoPattern_FromPattern ( |
| 363 |
cairo_pattern_create_for_surface (s->surface), NULL); |
| 364 |
} |
| 365 |
|
| 366 |
static PyObject * |
| 367 |
surface_pattern_get_surface (PycairoSurfacePattern *o, PyObject *ignored) { |
| 368 |
cairo_surface_t *surface; |
| 369 |
RETURN_NULL_IF_CAIRO_ERROR(cairo_pattern_get_surface (o->pattern, &surface)); |
| 370 |
return PycairoSurface_FromSurface(cairo_surface_reference (surface), NULL); |
| 371 |
} |
| 372 |
|
| 373 |
static PyMethodDef surface_pattern_methods[] = { |
| 374 |
{"get_surface", (PyCFunction)surface_pattern_get_surface, METH_NOARGS }, |
| 375 |
{NULL, NULL, 0, NULL}, |
| 376 |
}; |
| 377 |
|
| 378 |
PyTypeObject PycairoSurfacePattern_Type = { |
| 379 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 380 |
"cairo.SurfacePattern", |
| 381 |
sizeof(PycairoSurfacePattern), |
| 382 |
0, |
| 383 |
0, |
| 384 |
0, |
| 385 |
0, |
| 386 |
0, |
| 387 |
0, |
| 388 |
0, |
| 389 |
0, |
| 390 |
0, |
| 391 |
0, |
| 392 |
0, |
| 393 |
0, |
| 394 |
0, |
| 395 |
0, |
| 396 |
0, |
| 397 |
0, |
| 398 |
Py_TPFLAGS_DEFAULT, |
| 399 |
0, |
| 400 |
0, |
| 401 |
0, |
| 402 |
0, |
| 403 |
0, |
| 404 |
0, |
| 405 |
0, |
| 406 |
surface_pattern_methods, |
| 407 |
0, |
| 408 |
0, |
| 409 |
&PycairoPattern_Type, |
| 410 |
0, |
| 411 |
0, |
| 412 |
0, |
| 413 |
0, |
| 414 |
0, |
| 415 |
0, |
| 416 |
(newfunc)surface_pattern_new, |
| 417 |
0, |
| 418 |
0, |
| 419 |
0, |
| 420 |
}; |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
static PyObject * |
| 425 |
gradient_new (PyTypeObject *type, PyObject *args, PyObject *kwds) { |
| 426 |
PyErr_SetString(PyExc_TypeError, |
| 427 |
"The Gradient type cannot be instantiated"); |
| 428 |
return NULL; |
| 429 |
} |
| 430 |
|
| 431 |
static PyObject * |
| 432 |
gradient_add_color_stop_rgb (PycairoGradient *o, PyObject *args) { |
| 433 |
double offset, red, green, blue; |
| 434 |
if (!PyArg_ParseTuple(args, "dddd:Gradient.add_color_stop_rgb", |
| 435 |
&offset, &red, &green, &blue)) |
| 436 |
return NULL; |
| 437 |
cairo_pattern_add_color_stop_rgb (o->pattern, offset, red, green, blue); |
| 438 |
RETURN_NULL_IF_CAIRO_PATTERN_ERROR(o->pattern); |
| 439 |
Py_RETURN_NONE; |
| 440 |
} |
| 441 |
|
| 442 |
static PyObject * |
| 443 |
gradient_add_color_stop_rgba (PycairoGradient *o, PyObject *args) { |
| 444 |
double offset, red, green, blue, alpha; |
| 445 |
if (!PyArg_ParseTuple(args, "ddddd:Gradient.add_color_stop_rgba", |
| 446 |
&offset, &red, &green, &blue, &alpha)) |
| 447 |
return NULL; |
| 448 |
cairo_pattern_add_color_stop_rgba (o->pattern, offset, red, |
| 449 |
green, blue, alpha); |
| 450 |
RETURN_NULL_IF_CAIRO_PATTERN_ERROR(o->pattern); |
| 451 |
Py_RETURN_NONE; |
| 452 |
} |
| 453 |
|
| 454 |
static PyObject * |
| 455 |
gradient_get_color_stops_rgba (PycairoGradient *obj, PyObject *ignored) { |
| 456 |
cairo_status_t status; |
| 457 |
double offset, red, green, blue, alpha; |
| 458 |
int count; |
| 459 |
PyObject *list, *tuple; |
| 460 |
int result, i; |
| 461 |
|
| 462 |
status = cairo_pattern_get_color_stop_count (obj->pattern, &count); |
| 463 |
RETURN_NULL_IF_CAIRO_ERROR (status); |
| 464 |
|
| 465 |
list = PyList_New (0); |
| 466 |
if (list == NULL) |
| 467 |
return NULL; |
| 468 |
|
| 469 |
for (i = 0; i < count; i++) { |
| 470 |
status = cairo_pattern_get_color_stop_rgba ( |
| 471 |
obj->pattern, i, &offset, &red, &green, &blue, &alpha); |
| 472 |
if (status != CAIRO_STATUS_SUCCESS) |
| 473 |
goto error; |
| 474 |
|
| 475 |
tuple = Py_BuildValue("(ddddd)", offset, red, green, blue, alpha); |
| 476 |
if (tuple == NULL) |
| 477 |
goto error; |
| 478 |
|
| 479 |
result = PyList_Append (list, tuple); |
| 480 |
Py_DECREF (tuple); |
| 481 |
if (result == -1) |
| 482 |
goto error; |
| 483 |
} |
| 484 |
|
| 485 |
return list; |
| 486 |
error: |
| 487 |
Py_DECREF (list); |
| 488 |
if (status != CAIRO_STATUS_SUCCESS) |
| 489 |
Pycairo_Check_Status (status); |
| 490 |
return NULL; |
| 491 |
} |
| 492 |
|
| 493 |
static PyMethodDef gradient_methods[] = { |
| 494 |
{"add_color_stop_rgb",(PyCFunction)gradient_add_color_stop_rgb, |
| 495 |
METH_VARARGS }, |
| 496 |
{"add_color_stop_rgba",(PyCFunction)gradient_add_color_stop_rgba, |
| 497 |
METH_VARARGS }, |
| 498 |
{"get_color_stops_rgba",(PyCFunction)gradient_get_color_stops_rgba, |
| 499 |
METH_NOARGS }, |
| 500 |
{NULL, NULL, 0, NULL}, |
| 501 |
}; |
| 502 |
|
| 503 |
PyTypeObject PycairoGradient_Type = { |
| 504 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 505 |
"cairo.Gradient", |
| 506 |
sizeof(PycairoGradient), |
| 507 |
0, |
| 508 |
0, |
| 509 |
0, |
| 510 |
0, |
| 511 |
0, |
| 512 |
0, |
| 513 |
0, |
| 514 |
0, |
| 515 |
0, |
| 516 |
0, |
| 517 |
0, |
| 518 |
0, |
| 519 |
0, |
| 520 |
0, |
| 521 |
0, |
| 522 |
0, |
| 523 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, |
| 524 |
0, |
| 525 |
0, |
| 526 |
0, |
| 527 |
0, |
| 528 |
0, |
| 529 |
0, |
| 530 |
0, |
| 531 |
gradient_methods, |
| 532 |
0, |
| 533 |
0, |
| 534 |
&PycairoPattern_Type, |
| 535 |
0, |
| 536 |
0, |
| 537 |
0, |
| 538 |
0, |
| 539 |
0, |
| 540 |
0, |
| 541 |
(newfunc)gradient_new, |
| 542 |
0, |
| 543 |
0, |
| 544 |
0, |
| 545 |
}; |
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
static PyObject * |
| 550 |
linear_gradient_new (PyTypeObject *type, PyObject *args, PyObject *kwds) { |
| 551 |
double x0, y0, x1, y1; |
| 552 |
if (!PyArg_ParseTuple(args, "dddd:LinearGradient.__new__", |
| 553 |
&x0, &y0, &x1, &y1)) |
| 554 |
return NULL; |
| 555 |
return PycairoPattern_FromPattern ( |
| 556 |
cairo_pattern_create_linear (x0, y0, x1, y1), NULL); |
| 557 |
} |
| 558 |
|
| 559 |
static PyObject * |
| 560 |
linear_gradient_get_linear_points (PycairoLinearGradient *o, PyObject *ignored) { |
| 561 |
double x0, y0, x1, y1; |
| 562 |
cairo_pattern_get_linear_points (o->pattern, &x0, &y0, &x1, &y1); |
| 563 |
return Py_BuildValue("(dddd)", x0, y0, x1, y1); |
| 564 |
} |
| 565 |
|
| 566 |
static PyMethodDef linear_gradient_methods[] = { |
| 567 |
{"get_linear_points", (PyCFunction)linear_gradient_get_linear_points, |
| 568 |
METH_NOARGS }, |
| 569 |
{NULL, NULL, 0, NULL}, |
| 570 |
}; |
| 571 |
|
| 572 |
PyTypeObject PycairoLinearGradient_Type = { |
| 573 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 574 |
"cairo.LinearGradient", |
| 575 |
sizeof(PycairoLinearGradient), |
| 576 |
0, |
| 577 |
0, |
| 578 |
0, |
| 579 |
0, |
| 580 |
0, |
| 581 |
0, |
| 582 |
0, |
| 583 |
0, |
| 584 |
0, |
| 585 |
0, |
| 586 |
0, |
| 587 |
0, |
| 588 |
0, |
| 589 |
0, |
| 590 |
0, |
| 591 |
0, |
| 592 |
Py_TPFLAGS_DEFAULT, |
| 593 |
0, |
| 594 |
0, |
| 595 |
0, |
| 596 |
0, |
| 597 |
0, |
| 598 |
0, |
| 599 |
0, |
| 600 |
linear_gradient_methods, |
| 601 |
0, |
| 602 |
0, |
| 603 |
&PycairoGradient_Type, |
| 604 |
0, |
| 605 |
0, |
| 606 |
0, |
| 607 |
0, |
| 608 |
0, |
| 609 |
0, |
| 610 |
(newfunc)linear_gradient_new, |
| 611 |
0, |
| 612 |
0, |
| 613 |
0, |
| 614 |
}; |
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
static PyObject * |
| 619 |
radial_gradient_new (PyTypeObject *type, PyObject *args, PyObject *kwds) { |
| 620 |
double cx0, cy0, radius0, cx1, cy1, radius1; |
| 621 |
if (!PyArg_ParseTuple(args, "dddddd:RadialGradient.__new__", |
| 622 |
&cx0, &cy0, &radius0, &cx1, &cy1, &radius1)) |
| 623 |
return NULL; |
| 624 |
return PycairoPattern_FromPattern ( |
| 625 |
cairo_pattern_create_radial (cx0, cy0, radius0, cx1, cy1, radius1), |
| 626 |
NULL); |
| 627 |
} |
| 628 |
|
| 629 |
static PyObject * |
| 630 |
radial_gradient_get_radial_circles (PycairoRadialGradient *o, PyObject *ignored) { |
| 631 |
double x0, y0, r0, x1, y1, r1; |
| 632 |
cairo_pattern_get_radial_circles (o->pattern, &x0, &y0, &r0, |
| 633 |
&x1, &y1, &r1); |
| 634 |
return Py_BuildValue("(dddddd)", x0, y0, r0, x1, y1, r1); |
| 635 |
} |
| 636 |
|
| 637 |
static PyMethodDef radial_gradient_methods[] = { |
| 638 |
{"get_radial_circles", (PyCFunction)radial_gradient_get_radial_circles, |
| 639 |
METH_NOARGS }, |
| 640 |
{NULL, NULL, 0, NULL}, |
| 641 |
}; |
| 642 |
|
| 643 |
PyTypeObject PycairoRadialGradient_Type = { |
| 644 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 645 |
"cairo.RadialGradient", |
| 646 |
sizeof(PycairoRadialGradient), |
| 647 |
0, |
| 648 |
0, |
| 649 |
0, |
| 650 |
0, |
| 651 |
0, |
| 652 |
0, |
| 653 |
0, |
| 654 |
0, |
| 655 |
0, |
| 656 |
0, |
| 657 |
0, |
| 658 |
0, |
| 659 |
0, |
| 660 |
0, |
| 661 |
0, |
| 662 |
0, |
| 663 |
Py_TPFLAGS_DEFAULT, |
| 664 |
0, |
| 665 |
0, |
| 666 |
0, |
| 667 |
0, |
| 668 |
0, |
| 669 |
0, |
| 670 |
0, |
| 671 |
radial_gradient_methods, |
| 672 |
0, |
| 673 |
0, |
| 674 |
&PycairoGradient_Type, |
| 675 |
0, |
| 676 |
0, |
| 677 |
0, |
| 678 |
0, |
| 679 |
0, |
| 680 |
0, |
| 681 |
(newfunc)radial_gradient_new, |
| 682 |
0, |
| 683 |
0, |
| 684 |
0, |
| 685 |
}; |
| 686 |
|
| 687 |
static PyObject * |
| 688 |
mesh_pattern_new (PyTypeObject *type, PyObject *args, PyObject *kwds) { |
| 689 |
if (!PyArg_ParseTuple (args, ":Mesh.__new__")) |
| 690 |
return NULL; |
| 691 |
|
| 692 |
return PycairoPattern_FromPattern (cairo_pattern_create_mesh (), NULL); |
| 693 |
} |
| 694 |
|
| 695 |
static PyObject * |
| 696 |
mesh_pattern_begin_patch (PycairoMeshPattern *obj, PyObject *ignored) { |
| 697 |
Py_BEGIN_ALLOW_THREADS; |
| 698 |
cairo_mesh_pattern_begin_patch (obj->pattern); |
| 699 |
Py_END_ALLOW_THREADS; |
| 700 |
|
| 701 |
RETURN_NULL_IF_CAIRO_PATTERN_ERROR (obj->pattern); |
| 702 |
|
| 703 |
Py_RETURN_NONE; |
| 704 |
} |
| 705 |
|
| 706 |
static PyObject * |
| 707 |
mesh_pattern_end_patch (PycairoMeshPattern *obj, PyObject *ignored) { |
| 708 |
Py_BEGIN_ALLOW_THREADS; |
| 709 |
cairo_mesh_pattern_end_patch (obj->pattern); |
| 710 |
Py_END_ALLOW_THREADS; |
| 711 |
|
| 712 |
RETURN_NULL_IF_CAIRO_PATTERN_ERROR (obj->pattern); |
| 713 |
|
| 714 |
Py_RETURN_NONE; |
| 715 |
} |
| 716 |
|
| 717 |
static PyObject * |
| 718 |
mesh_pattern_curve_to (PycairoMeshPattern *obj, PyObject *args) { |
| 719 |
double x1, y1, x2, y2, x3, y3; |
| 720 |
|
| 721 |
if (!PyArg_ParseTuple(args, "dddddd:MeshPattern.curve_to", |
| 722 |
&x1, &y1, &x2, &y2, &x3, &y3)) |
| 723 |
return NULL; |
| 724 |
|
| 725 |
Py_BEGIN_ALLOW_THREADS; |
| 726 |
cairo_mesh_pattern_curve_to (obj->pattern, x1, y1, x2, y2, x3, y3); |
| 727 |
Py_END_ALLOW_THREADS; |
| 728 |
|
| 729 |
RETURN_NULL_IF_CAIRO_PATTERN_ERROR (obj->pattern); |
| 730 |
|
| 731 |
Py_RETURN_NONE; |
| 732 |
} |
| 733 |
|
| 734 |
static PyObject * |
| 735 |
mesh_pattern_get_control_point (PycairoMeshPattern *obj, PyObject *args) { |
| 736 |
double x, y; |
| 737 |
unsigned int patch_num, point_num; |
| 738 |
cairo_status_t status; |
| 739 |
|
| 740 |
if (!PyArg_ParseTuple(args, "II:MeshPattern.get_control_point", |
| 741 |
&patch_num, &point_num)) |
| 742 |
return NULL; |
| 743 |
|
| 744 |
Py_BEGIN_ALLOW_THREADS; |
| 745 |
status = cairo_mesh_pattern_get_control_point ( |
| 746 |
obj->pattern, patch_num, point_num, &x, &y); |
| 747 |
Py_END_ALLOW_THREADS; |
| 748 |
|
| 749 |
RETURN_NULL_IF_CAIRO_ERROR (status); |
| 750 |
|
| 751 |
return Py_BuildValue("(dd)", x, y); |
| 752 |
} |
| 753 |
|
| 754 |
static PyObject * |
| 755 |
mesh_pattern_get_corner_color_rgba (PycairoMeshPattern *obj, PyObject *args) { |
| 756 |
double red, green, blue, alpha; |
| 757 |
unsigned int patch_num, corner_num; |
| 758 |
cairo_status_t status; |
| 759 |
|
| 760 |
if (!PyArg_ParseTuple(args, "II:MeshPattern.get_corner_color_rgba", |
| 761 |
&patch_num, &corner_num)) |
| 762 |
return NULL; |
| 763 |
|
| 764 |
Py_BEGIN_ALLOW_THREADS; |
| 765 |
status = cairo_mesh_pattern_get_corner_color_rgba ( |
| 766 |
obj->pattern, patch_num, corner_num, &red, &green, &blue, &alpha); |
| 767 |
Py_END_ALLOW_THREADS; |
| 768 |
|
| 769 |
RETURN_NULL_IF_CAIRO_ERROR (status); |
| 770 |
|
| 771 |
return Py_BuildValue("(dddd)", red, green, blue, alpha); |
| 772 |
} |
| 773 |
|
| 774 |
static PyObject * |
| 775 |
mesh_pattern_get_patch_count (PycairoMeshPattern *obj, PyObject *ignored) { |
| 776 |
unsigned int count; |
| 777 |
cairo_status_t status; |
| 778 |
|
| 779 |
Py_BEGIN_ALLOW_THREADS; |
| 780 |
status = cairo_mesh_pattern_get_patch_count (obj->pattern, &count); |
| 781 |
Py_END_ALLOW_THREADS; |
| 782 |
|
| 783 |
RETURN_NULL_IF_CAIRO_ERROR (status); |
| 784 |
|
| 785 |
return PyLong_FromLong ((long)count); |
| 786 |
} |
| 787 |
|
| 788 |
static PyObject * |
| 789 |
mesh_pattern_get_path (PycairoMeshPattern *obj, PyObject *args) { |
| 790 |
unsigned int patch_num; |
| 791 |
cairo_path_t *path; |
| 792 |
|
| 793 |
if (!PyArg_ParseTuple(args, "I:MeshPattern.get_path", &patch_num)) |
| 794 |
return NULL; |
| 795 |
|
| 796 |
Py_BEGIN_ALLOW_THREADS; |
| 797 |
path = cairo_mesh_pattern_get_path (obj->pattern, patch_num); |
| 798 |
Py_END_ALLOW_THREADS; |
| 799 |
|
| 800 |
return PycairoPath_FromPath (path); |
| 801 |
} |
| 802 |
|
| 803 |
static PyObject * |
| 804 |
mesh_pattern_line_to (PycairoMeshPattern *obj, PyObject *args) { |
| 805 |
double x, y; |
| 806 |
|
| 807 |
if (!PyArg_ParseTuple(args, "dd:MeshPattern.line_to", &x, &y)) |
| 808 |
return NULL; |
| 809 |
|
| 810 |
Py_BEGIN_ALLOW_THREADS; |
| 811 |
cairo_mesh_pattern_line_to (obj->pattern, x, y); |
| 812 |
Py_END_ALLOW_THREADS; |
| 813 |
|
| 814 |
RETURN_NULL_IF_CAIRO_PATTERN_ERROR (obj->pattern); |
| 815 |
|
| 816 |
Py_RETURN_NONE; |
| 817 |
} |
| 818 |
|
| 819 |
static PyObject * |
| 820 |
mesh_pattern_move_to (PycairoMeshPattern *obj, PyObject *args) { |
| 821 |
double x, y; |
| 822 |
|
| 823 |
if (!PyArg_ParseTuple(args, "dd:MeshPattern.move_to", &x, &y)) |
| 824 |
return NULL; |
| 825 |
|
| 826 |
Py_BEGIN_ALLOW_THREADS; |
| 827 |
cairo_mesh_pattern_move_to (obj->pattern, x, y); |
| 828 |
Py_END_ALLOW_THREADS; |
| 829 |
|
| 830 |
RETURN_NULL_IF_CAIRO_PATTERN_ERROR (obj->pattern); |
| 831 |
|
| 832 |
Py_RETURN_NONE; |
| 833 |
} |
| 834 |
|
| 835 |
static PyObject * |
| 836 |
mesh_pattern_set_control_point (PycairoMeshPattern *obj, PyObject *args) { |
| 837 |
double x, y; |
| 838 |
unsigned int point_num; |
| 839 |
|
| 840 |
if (!PyArg_ParseTuple(args, "Idd:MeshPattern.set_control_point", |
| 841 |
&point_num, &x, &y)) |
| 842 |
return NULL; |
| 843 |
|
| 844 |
Py_BEGIN_ALLOW_THREADS; |
| 845 |
cairo_mesh_pattern_set_control_point (obj->pattern, point_num, x, y); |
| 846 |
Py_END_ALLOW_THREADS; |
| 847 |
|
| 848 |
RETURN_NULL_IF_CAIRO_PATTERN_ERROR (obj->pattern); |
| 849 |
|
| 850 |
Py_RETURN_NONE; |
| 851 |
} |
| 852 |
|
| 853 |
static PyObject * |
| 854 |
mesh_pattern_set_corner_color_rgb (PycairoMeshPattern *obj, PyObject *args) { |
| 855 |
double red, green, blue; |
| 856 |
unsigned int corner_num; |
| 857 |
|
| 858 |
if (!PyArg_ParseTuple(args, "Iddd:MeshPattern.set_corner_color_rgb", |
| 859 |
&corner_num, &red, &green, &blue)) |
| 860 |
return NULL; |
| 861 |
|
| 862 |
Py_BEGIN_ALLOW_THREADS; |
| 863 |
cairo_mesh_pattern_set_corner_color_rgb ( |
| 864 |
obj->pattern, corner_num, red, green, blue); |
| 865 |
Py_END_ALLOW_THREADS; |
| 866 |
|
| 867 |
RETURN_NULL_IF_CAIRO_PATTERN_ERROR (obj->pattern); |
| 868 |
|
| 869 |
Py_RETURN_NONE; |
| 870 |
} |
| 871 |
|
| 872 |
static PyObject * |
| 873 |
mesh_pattern_set_corner_color_rgba (PycairoMeshPattern *obj, PyObject *args) { |
| 874 |
double red, green, blue, alpha; |
| 875 |
unsigned int corner_num; |
| 876 |
|
| 877 |
if (!PyArg_ParseTuple(args, "Idddd:MeshPattern.set_corner_color_rgba", |
| 878 |
&corner_num, &red, &green, &blue, &alpha)) |
| 879 |
return NULL; |
| 880 |
|
| 881 |
Py_BEGIN_ALLOW_THREADS; |
| 882 |
cairo_mesh_pattern_set_corner_color_rgba ( |
| 883 |
obj->pattern, corner_num, red, green, blue, alpha); |
| 884 |
Py_END_ALLOW_THREADS; |
| 885 |
|
| 886 |
RETURN_NULL_IF_CAIRO_PATTERN_ERROR (obj->pattern); |
| 887 |
|
| 888 |
Py_RETURN_NONE; |
| 889 |
} |
| 890 |
|
| 891 |
static PyMethodDef mesh_pattern_methods[] = { |
| 892 |
{"begin_patch", (PyCFunction)mesh_pattern_begin_patch, METH_NOARGS}, |
| 893 |
{"end_patch", (PyCFunction)mesh_pattern_end_patch, METH_NOARGS}, |
| 894 |
{"curve_to", (PyCFunction)mesh_pattern_curve_to, METH_VARARGS}, |
| 895 |
{"get_control_point", |
| 896 |
(PyCFunction)mesh_pattern_get_control_point, METH_VARARGS}, |
| 897 |
{"get_corner_color_rgba", |
| 898 |
(PyCFunction)mesh_pattern_get_corner_color_rgba, METH_VARARGS}, |
| 899 |
{"get_patch_count", |
| 900 |
(PyCFunction)mesh_pattern_get_patch_count, METH_NOARGS}, |
| 901 |
{"get_path", (PyCFunction)mesh_pattern_get_path, METH_VARARGS}, |
| 902 |
{"line_to", (PyCFunction)mesh_pattern_line_to, METH_VARARGS}, |
| 903 |
{"move_to", (PyCFunction)mesh_pattern_move_to, METH_VARARGS}, |
| 904 |
{"set_control_point", |
| 905 |
(PyCFunction)mesh_pattern_set_control_point, METH_VARARGS}, |
| 906 |
{"set_corner_color_rgb", |
| 907 |
(PyCFunction)mesh_pattern_set_corner_color_rgb, METH_VARARGS}, |
| 908 |
{"set_corner_color_rgba", |
| 909 |
(PyCFunction)mesh_pattern_set_corner_color_rgba, METH_VARARGS}, |
| 910 |
{NULL, NULL, 0, NULL}, |
| 911 |
}; |
| 912 |
|
| 913 |
PyTypeObject PycairoMeshPattern_Type = { |
| 914 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 915 |
"cairo.MeshPattern", |
| 916 |
sizeof(PycairoMeshPattern), |
| 917 |
0, |
| 918 |
0, |
| 919 |
0, |
| 920 |
0, |
| 921 |
0, |
| 922 |
0, |
| 923 |
0, |
| 924 |
0, |
| 925 |
0, |
| 926 |
0, |
| 927 |
0, |
| 928 |
0, |
| 929 |
0, |
| 930 |
0, |
| 931 |
0, |
| 932 |
0, |
| 933 |
Py_TPFLAGS_DEFAULT, |
| 934 |
0, |
| 935 |
0, |
| 936 |
0, |
| 937 |
0, |
| 938 |
0, |
| 939 |
0, |
| 940 |
0, |
| 941 |
mesh_pattern_methods, |
| 942 |
0, |
| 943 |
0, |
| 944 |
&PycairoPattern_Type, |
| 945 |
0, |
| 946 |
0, |
| 947 |
0, |
| 948 |
0, |
| 949 |
0, |
| 950 |
0, |
| 951 |
(newfunc)mesh_pattern_new, |
| 952 |
0, |
| 953 |
0, |
| 954 |
0, |
| 955 |
}; |
| 956 |
|
| 957 |
|
| 958 |
static PyObject * |
| 959 |
raster_source_pattern_new (PyTypeObject *type, PyObject *args, PyObject *kwds) { |
| 960 |
cairo_content_t content; |
| 961 |
int width, height, content_arg; |
| 962 |
|
| 963 |
if (!PyArg_ParseTuple (args, "iii:RasterSourcePattern.__new__", |
| 964 |
&content_arg, &width, &height)) |
| 965 |
return NULL; |
| 966 |
|
| 967 |
content = (cairo_content_t)content_arg; |
| 968 |
|
| 969 |
return PycairoPattern_FromPattern ( |
| 970 |
cairo_pattern_create_raster_source (NULL, content, width, height), NULL); |
| 971 |
} |
| 972 |
|
| 973 |
static const cairo_user_data_key_t raster_source_acquire_key; |
| 974 |
static const cairo_user_data_key_t raster_source_release_key; |
| 975 |
|
| 976 |
static void |
| 977 |
_decref_destroy_func (void *user_data) { |
| 978 |
PyGILState_STATE gstate = PyGILState_Ensure (); |
| 979 |
Py_DECREF (user_data); |
| 980 |
PyGILState_Release (gstate); |
| 981 |
} |
| 982 |
|
| 983 |
static void |
| 984 |
_raster_source_release_func (cairo_pattern_t *pattern, |
| 985 |
void *callback_data, |
| 986 |
cairo_surface_t *surface) { |
| 987 |
void *user_data; |
| 988 |
PyObject *pysurface, *result; |
| 989 |
PyGILState_STATE gstate; |
| 990 |
|
| 991 |
pattern = (cairo_pattern_t *)callback_data; |
| 992 |
|
| 993 |
user_data = cairo_pattern_get_user_data ( |
| 994 |
pattern, &raster_source_release_key); |
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
if (user_data == NULL) { |
| 999 |
cairo_surface_destroy (surface); |
| 1000 |
return; |
| 1001 |
} |
| 1002 |
|
| 1003 |
gstate = PyGILState_Ensure (); |
| 1004 |
|
| 1005 |
pysurface = PycairoSurface_FromSurface ( |
| 1006 |
cairo_surface_reference (surface), NULL); |
| 1007 |
if (pysurface == NULL) |
| 1008 |
goto error; |
| 1009 |
|
| 1010 |
result = PyObject_CallFunction ((PyObject *)user_data, "(O)", pysurface); |
| 1011 |
if (result == NULL) |
| 1012 |
goto error; |
| 1013 |
|
| 1014 |
if (result != Py_None) { |
| 1015 |
Py_DECREF (result); |
| 1016 |
PyErr_SetString (PyExc_TypeError, |
| 1017 |
"Return value of release callback needs to be None"); |
| 1018 |
result = NULL; |
| 1019 |
goto error; |
| 1020 |
} |
| 1021 |
|
| 1022 |
Py_DECREF (pysurface); |
| 1023 |
PyGILState_Release (gstate); |
| 1024 |
cairo_surface_destroy (surface); |
| 1025 |
return; |
| 1026 |
error: |
| 1027 |
if (PyErr_Occurred ()) { |
| 1028 |
PyErr_Print (); |
| 1029 |
PyErr_Clear (); |
| 1030 |
} |
| 1031 |
Py_XDECREF (pysurface); |
| 1032 |
PyGILState_Release (gstate); |
| 1033 |
cairo_surface_destroy (surface); |
| 1034 |
return; |
| 1035 |
} |
| 1036 |
|
| 1037 |
static cairo_surface_t* |
| 1038 |
_raster_source_acquire_func (cairo_pattern_t *pattern, void *callback_data, |
| 1039 |
cairo_surface_t *target, |
| 1040 |
const cairo_rectangle_int_t *extents) { |
| 1041 |
void *user_data; |
| 1042 |
PyGILState_STATE gstate; |
| 1043 |
PyObject *result; |
| 1044 |
PyObject *pysurface = NULL, *pyrect = NULL; |
| 1045 |
cairo_surface_t *result_surface; |
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
pattern = (cairo_pattern_t *)callback_data; |
| 1052 |
|
| 1053 |
gstate = PyGILState_Ensure (); |
| 1054 |
|
| 1055 |
user_data = cairo_pattern_get_user_data ( |
| 1056 |
pattern, &raster_source_acquire_key); |
| 1057 |
if (user_data == NULL) |
| 1058 |
goto error; |
| 1059 |
|
| 1060 |
pysurface = PycairoSurface_FromSurface ( |
| 1061 |
cairo_surface_reference (target), NULL); |
| 1062 |
if (pysurface == NULL) |
| 1063 |
goto error; |
| 1064 |
|
| 1065 |
pyrect = PycairoRectangleInt_FromRectangleInt (extents); |
| 1066 |
if (pyrect == NULL) |
| 1067 |
goto error; |
| 1068 |
|
| 1069 |
result = PyObject_CallFunction ( |
| 1070 |
(PyObject *)user_data, "(OO)", pysurface, pyrect); |
| 1071 |
|
| 1072 |
if (result != NULL) { |
| 1073 |
if (!PyObject_TypeCheck (result, &PycairoSurface_Type)) { |
| 1074 |
Py_DECREF (result); |
| 1075 |
PyErr_SetString (PyExc_TypeError, |
| 1076 |
"Return value of acquire callback needs to be of type Surface"); |
| 1077 |
result = NULL; |
| 1078 |
} |
| 1079 |
} |
| 1080 |
|
| 1081 |
if (result == NULL) |
| 1082 |
goto error; |
| 1083 |
|
| 1084 |
Py_DECREF (pysurface); |
| 1085 |
Py_DECREF (pyrect); |
| 1086 |
result_surface = ((PycairoSurface *)result)->surface; |
| 1087 |
cairo_surface_reference (result_surface); |
| 1088 |
Py_DECREF (result); |
| 1089 |
PyGILState_Release (gstate); |
| 1090 |
return result_surface; |
| 1091 |
|
| 1092 |
error: |
| 1093 |
if (PyErr_Occurred ()) { |
| 1094 |
PyErr_Print (); |
| 1095 |
PyErr_Clear (); |
| 1096 |
} |
| 1097 |
Py_XDECREF (pysurface); |
| 1098 |
Py_XDECREF (pyrect); |
| 1099 |
PyGILState_Release (gstate); |
| 1100 |
return NULL; |
| 1101 |
} |
| 1102 |
|
| 1103 |
static PyObject * |
| 1104 |
raster_source_pattern_set_acquire (PycairoRasterSourcePattern *obj, |
| 1105 |
PyObject *args) { |
| 1106 |
PyObject *acquire_callable, *release_callable; |
| 1107 |
cairo_status_t status; |
| 1108 |
cairo_pattern_t *pattern; |
| 1109 |
void *callback_data; |
| 1110 |
cairo_raster_source_acquire_func_t acquire_func; |
| 1111 |
cairo_raster_source_release_func_t release_func; |
| 1112 |
void *acquire_user_data, *release_user_data; |
| 1113 |
|
| 1114 |
if (!PyArg_ParseTuple (args, "OO:RasterSourcePattern.set_acquire", |
| 1115 |
&acquire_callable, &release_callable)) |
| 1116 |
return NULL; |
| 1117 |
|
| 1118 |
pattern = obj->pattern; |
| 1119 |
|
| 1120 |
callback_data = cairo_raster_source_pattern_get_callback_data (pattern); |
| 1121 |
if (callback_data != NULL && callback_data != pattern) { |
| 1122 |
PyErr_SetString (PyExc_RuntimeError, |
| 1123 |
"Callback is set, but not through Pycairo. Replacing not supported."); |
| 1124 |
return NULL; |
| 1125 |
} |
| 1126 |
|
| 1127 |
if (!PyCallable_Check (acquire_callable) && acquire_callable != Py_None) { |
| 1128 |
PyErr_SetString ( |
| 1129 |
PyExc_TypeError, "argument needs to be a callable or None"); |
| 1130 |
return NULL; |
| 1131 |
} |
| 1132 |
|
| 1133 |
if (!PyCallable_Check (release_callable) && release_callable != Py_None) { |
| 1134 |
PyErr_SetString ( |
| 1135 |
PyExc_TypeError, "argument needs to be a callable or None"); |
| 1136 |
return NULL; |
| 1137 |
} |
| 1138 |
|
| 1139 |
if (acquire_callable == Py_None) { |
| 1140 |
acquire_func = NULL; |
| 1141 |
acquire_user_data = NULL; |
| 1142 |
} else { |
| 1143 |
acquire_func = _raster_source_acquire_func; |
| 1144 |
acquire_user_data = acquire_callable; |
| 1145 |
} |
| 1146 |
|
| 1147 |
if (release_callable == Py_None) { |
| 1148 |
release_func = NULL; |
| 1149 |
release_user_data = NULL; |
| 1150 |
} else { |
| 1151 |
release_func = _raster_source_release_func; |
| 1152 |
release_user_data = release_callable; |
| 1153 |
} |
| 1154 |
|
| 1155 |
|
| 1156 |
if (acquire_func != NULL && release_func == NULL) { |
| 1157 |
release_func = _raster_source_release_func; |
| 1158 |
} |
| 1159 |
|
| 1160 |
status = cairo_pattern_set_user_data ( |
| 1161 |
pattern, &raster_source_acquire_key, acquire_user_data, |
| 1162 |
(acquire_user_data) ? _decref_destroy_func : NULL); |
| 1163 |
RETURN_NULL_IF_CAIRO_ERROR (status); |
| 1164 |
if (acquire_user_data != NULL) |
| 1165 |
Py_INCREF (acquire_user_data); |
| 1166 |
|
| 1167 |
status = cairo_pattern_set_user_data ( |
| 1168 |
pattern, &raster_source_release_key, release_user_data, |
| 1169 |
(release_user_data) ? _decref_destroy_func : NULL); |
| 1170 |
if (status != CAIRO_STATUS_SUCCESS) { |
| 1171 |
cairo_pattern_set_user_data ( |
| 1172 |
pattern, &raster_source_acquire_key, NULL, NULL); |
| 1173 |
RETURN_NULL_IF_CAIRO_ERROR (status); |
| 1174 |
} |
| 1175 |
if (release_user_data != NULL) |
| 1176 |
Py_INCREF (release_user_data); |
| 1177 |
|
| 1178 |
cairo_raster_source_pattern_set_callback_data (pattern, pattern); |
| 1179 |
|
| 1180 |
Py_BEGIN_ALLOW_THREADS; |
| 1181 |
cairo_raster_source_pattern_set_acquire ( |
| 1182 |
pattern, acquire_func, release_func); |
| 1183 |
Py_END_ALLOW_THREADS; |
| 1184 |
|
| 1185 |
Py_RETURN_NONE; |
| 1186 |
} |
| 1187 |
|
| 1188 |
static PyObject * |
| 1189 |
raster_source_pattern_get_acquire (PycairoRasterSourcePattern *obj, PyObject *ignored) { |
| 1190 |
cairo_pattern_t *pattern; |
| 1191 |
void *user_data; |
| 1192 |
PyObject *acquire_callable, *release_callable; |
| 1193 |
|
| 1194 |
pattern = obj->pattern; |
| 1195 |
|
| 1196 |
user_data = cairo_pattern_get_user_data ( |
| 1197 |
pattern, &raster_source_acquire_key); |
| 1198 |
if (user_data == NULL) { |
| 1199 |
acquire_callable = Py_None; |
| 1200 |
} else { |
| 1201 |
acquire_callable = user_data; |
| 1202 |
} |
| 1203 |
|
| 1204 |
user_data = cairo_pattern_get_user_data ( |
| 1205 |
pattern, &raster_source_release_key); |
| 1206 |
if (user_data == NULL) { |
| 1207 |
release_callable = Py_None; |
| 1208 |
} else { |
| 1209 |
release_callable = user_data; |
| 1210 |
} |
| 1211 |
|
| 1212 |
return Py_BuildValue ("(OO)", acquire_callable, release_callable); |
| 1213 |
} |
| 1214 |
|
| 1215 |
static PyMethodDef raster_source_pattern_methods[] = { |
| 1216 |
{"set_acquire", |
| 1217 |
(PyCFunction)raster_source_pattern_set_acquire, METH_VARARGS}, |
| 1218 |
{"get_acquire", |
| 1219 |
(PyCFunction)raster_source_pattern_get_acquire, METH_NOARGS}, |
| 1220 |
{NULL, NULL, 0, NULL}, |
| 1221 |
}; |
| 1222 |
|
| 1223 |
PyTypeObject PycairoRasterSourcePattern_Type = { |
| 1224 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 1225 |
"cairo.RasterSourcePattern", |
| 1226 |
sizeof(PycairoRasterSourcePattern), |
| 1227 |
0, |
| 1228 |
0, |
| 1229 |
0, |
| 1230 |
0, |
| 1231 |
0, |
| 1232 |
0, |
| 1233 |
0, |
| 1234 |
0, |
| 1235 |
0, |
| 1236 |
0, |
| 1237 |
0, |
| 1238 |
0, |
| 1239 |
0, |
| 1240 |
0, |
| 1241 |
0, |
| 1242 |
0, |
| 1243 |
Py_TPFLAGS_DEFAULT, |
| 1244 |
0, |
| 1245 |
0, |
| 1246 |
0, |
| 1247 |
0, |
| 1248 |
0, |
| 1249 |
0, |
| 1250 |
0, |
| 1251 |
raster_source_pattern_methods, |
| 1252 |
0, |
| 1253 |
0, |
| 1254 |
&PycairoPattern_Type, |
| 1255 |
0, |
| 1256 |
0, |
| 1257 |
0, |
| 1258 |
0, |
| 1259 |
0, |
| 1260 |
0, |
| 1261 |
(newfunc)raster_source_pattern_new, |
| 1262 |
0, |
| 1263 |
0, |
| 1264 |
0, |
| 1265 |
}; |