[pygobject] Add cairo_matrix_t converter to GValue.
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Add cairo_matrix_t converter to GValue.
- Date: Fri, 22 Feb 2019 16:41:30 +0000 (UTC)
commit d519d8c245a0ee0da964692149a3140d996dbc2a
Author: Renato Florentino Garcia <fgarcia renato gmail com>
Date: Tue Feb 19 14:14:23 2019 -0300
Add cairo_matrix_t converter to GValue.
gi/pygi-foreign-cairo.c | 34 ++++++++++++++++++++++++++++++++++
tests/test_cairo.py | 2 ++
2 files changed, 36 insertions(+)
---
diff --git a/gi/pygi-foreign-cairo.c b/gi/pygi-foreign-cairo.c
index efb62544..399fe75e 100644
--- a/gi/pygi-foreign-cairo.c
+++ b/gi/pygi-foreign-cairo.c
@@ -583,6 +583,36 @@ cairo_matrix_release (GIBaseInfo *base_info,
Py_RETURN_NONE;
}
+static int
+cairo_matrix_to_gvalue (GValue *value, PyObject *obj)
+{
+ cairo_matrix_t *matrix;
+
+ if (!PyObject_TypeCheck (obj, &PycairoMatrix_Type)) {
+ PyErr_SetString (PyExc_TypeError, "Expected cairo.Matrix");
+ return -1;
+ }
+
+ matrix = &(( (PycairoMatrix*) obj)->matrix);
+ if (!matrix) {
+ return -1;
+ }
+
+ g_value_set_boxed (value, matrix);
+ return 0;
+}
+
+static PyObject *
+cairo_matrix_from_gvalue (const GValue *value)
+{
+ cairo_matrix_t *matrix = g_value_get_boxed(value);
+ if (!matrix) {
+ Py_RETURN_NONE;
+ }
+
+ return PycairoMatrix_FromMatrix (matrix);
+}
+
static PyMethodDef _gi_cairo_functions[] = { {0,} };
PYGLIB_MODULE_START(_gi_cairo, "_gi_cairo")
{
@@ -644,6 +674,10 @@ PYGLIB_MODULE_START(_gi_cairo, "_gi_cairo")
cairo_region_from_arg,
cairo_region_release);
+ pyg_register_gtype_custom (CAIRO_GOBJECT_TYPE_MATRIX,
+ cairo_matrix_from_gvalue,
+ cairo_matrix_to_gvalue);
+
pyg_register_gtype_custom (CAIRO_GOBJECT_TYPE_CONTEXT,
cairo_context_from_gvalue,
cairo_context_to_gvalue);
diff --git a/tests/test_cairo.py b/tests/test_cairo.py
index d03e85df..37a6ac38 100644
--- a/tests/test_cairo.py
+++ b/tests/test_cairo.py
@@ -34,12 +34,14 @@ class Test(unittest.TestCase):
def test_gvalue_converters(self):
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 10, 10)
context = cairo.Context(surface)
+ matrix = cairo.Matrix()
objects = {
'CairoContext': context,
'CairoSurface': surface,
'CairoFontFace': context.get_font_face(),
'CairoScaledFont': context.get_scaled_font(),
'CairoPattern': context.get_source(),
+ 'CairoMatrix': matrix,
}
for type_name, cairo_obj in objects.items():
gtype = GObject.type_from_name(type_name)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]