[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
rsvg_handle_new_from_file<http://pupeno.com/blog/svgs-in-.net-using-cairo-and-gtk-and-c>in
C# for rendering SVG to a Cairo Context. Which is immensly useful to
me,
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);
   GLib.Marshaller.Free(nativeFileName);

   if(IntPtr.Zero != error){
      throw new
<http://www.google.com/search?q=new+msdn.microsoft.com>GLib.GException(error);
   }
   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?

Cheers,
Chris.
-------------- 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