Add Cairo Pattern foreign struct.

parent 7518a04b
......@@ -409,6 +409,53 @@ cairo_scaled_font_from_gvalue (const GValue *value)
* cairo_pattern_t marshaling
*/
static PyObject *
cairo_pattern_to_arg (PyObject *value,
GIInterfaceInfo *interface_info,
GITransfer transfer,
GIArgument *arg)
{
cairo_pattern_t *pattern;
if (!PyObject_TypeCheck (value, &PycairoPattern_Type)) {
PyErr_SetString (PyExc_TypeError, "Expected cairo.Pattern");
return NULL;
}
pattern = ((PycairoPattern*) value)->pattern;
if (!pattern) {
PyErr_SetString (PyExc_ValueError, "Pattern instance wrapping a NULL pattern");
return NULL;
}
if (transfer != GI_TRANSFER_NOTHING)
pattern = cairo_pattern_reference (pattern);
arg->v_pointer = pattern;
Py_RETURN_NONE;
}
static PyObject *
cairo_pattern_from_arg (GIInterfaceInfo *interface_info,
GITransfer transfer,
gpointer data)
{
cairo_pattern_t *pattern = (cairo_pattern_t*) data;
if (transfer == GI_TRANSFER_NOTHING)
pattern = cairo_pattern_reference (pattern);
return PycairoPattern_FromPattern (pattern, NULL);
}
static PyObject *
cairo_pattern_release (GIBaseInfo *base_info,
gpointer struct_)
{
cairo_pattern_destroy ( (cairo_pattern_t*) struct_);
Py_RETURN_NONE;
}
static int
cairo_pattern_to_gvalue (GValue *value, PyObject *obj)
{
......@@ -585,6 +632,12 @@ PYGLIB_MODULE_START(_gi_cairo, "_gi_cairo")
cairo_font_options_from_arg,
cairo_font_options_release);
pygi_register_foreign_struct ("cairo",
"Pattern",
cairo_pattern_to_arg,
cairo_pattern_from_arg,
cairo_pattern_release);
pygi_register_foreign_struct ("cairo",
"Region",
cairo_region_to_arg,
......
......@@ -173,6 +173,58 @@ regress_test_cairo_path_full_in_full_return (cairo_path_t *path)
return path;
}
/**
* regress_test_cairo_pattern_full_in:
* @pattern: (transfer full):
*/
void
regress_test_cairo_pattern_full_in (cairo_pattern_t *pattern)
{
cairo_pattern_destroy (pattern);
}
/**
* regress_test_cairo_pattern_none_in:
* @pattern: (transfer none):
*/
void
regress_test_cairo_pattern_none_in (cairo_pattern_t *pattern)
{
cairo_t *cr = regress_test_cairo_context_full_return ();
cairo_set_source (cr, pattern);
g_assert (cairo_status (cr) == CAIRO_STATUS_SUCCESS);
cairo_destroy (cr);
}
/**
* regress_test_cairo_pattern_none_return:
*
* Returns: (transfer none):
*/
cairo_pattern_t*
regress_test_cairo_pattern_none_return (void)
{
static cairo_pattern_t *pattern;
if (pattern == NULL) {
pattern = cairo_pattern_create_rgb(0.1, 0.2, 0.3);
}
return pattern;
}
/**
* regress_test_cairo_pattern_full_return:
*
* Returns: (transfer full):
*/
cairo_pattern_t *
regress_test_cairo_pattern_full_return (void)
{
cairo_pattern_t *pattern = cairo_pattern_create_rgb(0.5, 0.6, 0.7);
return pattern;
}
/**
* regress_test_cairo_region_full_in:
* @region: (transfer full):
......
......@@ -34,6 +34,14 @@ void regress_test_cairo_path_none_in (cairo_path_t *path);
_GI_TEST_EXTERN
cairo_path_t * regress_test_cairo_path_full_in_full_return (cairo_path_t *path);
_GI_TEST_EXTERN
void regress_test_cairo_pattern_full_in (cairo_pattern_t *pattern);
_GI_TEST_EXTERN
void regress_test_cairo_pattern_none_in (cairo_pattern_t *pattern);
_GI_TEST_EXTERN
cairo_pattern_t* regress_test_cairo_pattern_none_return (void);
_GI_TEST_EXTERN
cairo_pattern_t * regress_test_cairo_pattern_full_return (void);
_GI_TEST_EXTERN
cairo_font_options_t *regress_test_cairo_font_options_full_return (void);
_GI_TEST_EXTERN
cairo_font_options_t *regress_test_cairo_font_options_none_return (void);
......
......@@ -115,6 +115,27 @@ class Test(unittest.TestCase):
options = cairo.FontOptions()
Regress.test_cairo_font_options_none_in(options)
def test_cairo_pattern_full_in(self):
pattern = cairo.SolidPattern(1, 1, 1, 1)
Regress.test_cairo_pattern_full_in(pattern)
with pytest.raises(TypeError):
Regress.test_cairo_pattern_full_in(object())
def test_cairo_pattern_none_in(self):
pattern = cairo.SolidPattern(1, 1, 1, 1)
Regress.test_cairo_pattern_none_in(pattern)
def test_cairo_pattern_full_return(self):
pattern = Regress.test_cairo_pattern_full_return()
self.assertTrue(isinstance(pattern, cairo.Pattern))
self.assertTrue(isinstance(pattern, cairo.SolidPattern))
def test_cairo_pattern_none_return(self):
pattern = Regress.test_cairo_pattern_none_return()
self.assertTrue(isinstance(pattern, cairo.Pattern))
self.assertTrue(isinstance(pattern, cairo.SolidPattern))
def test_cairo_region_full_in(self):
region = cairo.Region()
Regress.test_cairo_region_full_in(region)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment