[Gtk-sharp-list] Wrapping rsvg_handle_new_from_data...

Chris Simpson chris at victoryonemedia.com
Mon Jan 12 23:00:06 EST 2009

Can't remember whether it was on the planet-gnome feed or monologue feed,
but there was a great blog post on wrapping
C# for rendering SVG to a Cairo Context. Which is immensly useful to
but I also have a desire to do this with SVG that's been generated on the
fly, and it's not really optimal to write this generated SVG to disc then
open it again, when the C function "rsvg_handle_new_from_data" exists..

specifically, the "from file" variant works as such:

protected static IntPtr NewFromFile(string fileName) {
   IntPtr error = IntPtr.Zero;
   IntPtr nativeFileName = GLib.Marshaller.StringToPtrGStrdup(fileName);
   IntPtr handlePtr = rsvg_handle_new_from_file(nativeFileName, out error);

   if(IntPtr.Zero != error){
      throw new
   return handlePtr;

my first attempt was a pretty obvious fail:
protected static IntPtr NewFromData( string Data )
    IntPtr error = IntPtr.Zero;
    IntPtr nativeData = GLib.Marshaller.StringToPtrGStrdup( Data );

    IntPtr handlePtr = rsvg_handle_new_from_data( nativeData, Data.Length,
out error );

    GLib.Marshaller.Free( nativeData );

    if ( IntPtr.Zero != error )
        throw new GLib.GException( error );
    return handlePtr;

Any thoughts on how to succesfully do this?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20090113/c0027a34/attachment-0001.html 

More information about the Gtk-sharp-list mailing list