rsvg_handle_set_stylesheet() isn't GObject Introspection ready
rsvg_handle_set_stylesheet()
requires UTF-8 CSS data with data length but the current GObject Introspection annotation requires an array of UTF-8 strings. Because GObject Introspection doesn't support a UTF-8 string with (array length)
annotation.
For example, PyGObject can't convert a Python string correctly:
import gi
gi.require_version("Rsvg", "2.0")
from gi.repository import Rsvg
svg = b'''
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
<rect id="rectangle" x="0" y="10" width="100" height="100"/>
</svg>
'''
handle = Rsvg.Handle.new_from_data(svg)
handle.set_stylesheet('rect {}')
$ gdb --args python3 a.py
...
(gdb) b rsvg_handle_set_stylesheet
...
(gdb) r
...
Breakpoint 1, rsvg_handle_set_stylesheet (handle=0xb002e0,
css=0xb05f70 "\200t\263", css_len=7, error=0x7fffffffde38)
at librsvg/rsvg-handle.c:807
807 librsvg/rsvg-handle.c: No such file or directory.
(gdb) p css
$1 = 0xb05f70 "\200t\263" # <- not "rect {}"
Workaround:
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index 13787bd9..97e4711a 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -733,7 +733,7 @@ rsvg_handle_get_base_uri (RsvgHandle *handle)
/**
* rsvg_handle_set_stylesheet:
* @handle: A #RsvgHandle.
- * @css: (array length=css_len): String with CSS data; must be valid UTF-8.
+ * @css: (array length=css_len) (element-type guchar): String with CSS data; must be valid UTF-8.
* @css_len: Length of the @css string in bytes.
* @error: (optional): return location for errors.
*
But this requires changing "rect {}"
to b"rect {}"
in Python.