[cairo] Loading SVG from memory using RSVG

Dominic Lachowicz domlachowicz at gmail.com
Sun Dec 3 18:58:19 PST 2006


This would be better on the librsvg-devel list. I'm sorry that I
haven't responded to your email.

rsvg_handle_new_from_file() calls rsvg_handle_write(), so if you see
the error in one place, you should see it in both.

Best,
Dom

On 12/3/06, Simon Flannery <simon_flannery at yahoo.com.au> wrote:
> Nope, sorry no joy. I tried:
>
>    rsvg_init();
>  //  g_my_svg = rsvg_handle_new_from_data(data, sizeof(data), &pError);
>    g_my_svg = rsvg_handle_new();
>    gboolean b = rsvg_handle_write(g_my_svg, data, sizeof(data), &pError);
>
> The variable is set to 1, is that good or bad? And there does not seem to be a error. But nothing is drawn using:
>
>    static float rotate = 0.0f;
>                 rotate = rotate + 1.0f;
>    cairo_surface_t* surface = cairo_win32_surface_create(hdc);
>    cairo_t* cr = cairo_create(surface);
> /* Push the matrix stack. */
>    cairo_save(cr);
>    cairo_translate(cr, (double) width * 0.5, (double) height * 0.5);
>    cairo_rotate(cr, (3.14f / 180.0f) * rotate);
> /* Undo the translation and center the decal. */
>    cairo_translate(cr, (double) width * -0.5 * g_zoom, (double) height * -0.5 * g_zoom);
> /* Scale up to full-window size. */
>   // cairo_scale(cr, ((double) width / (double) g_dimension.width) * g_zoom, ((double) height / (double) g_dimension.height) * g_zoom);
> /* Paint the background context colort white. */
>    cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f);
>    cairo_paint(cr);
> /* Apply our decal. */
>    rsvg_handle_render_cairo(g_my_svg, cr);
> /* Pop the matrix stack. */
>    cairo_restore(cr);
> /* Force pipeline out. */
>    cairo_surface_flush(surface);
> /* Clean up. */
>    cairo_destroy(cr);
>    cairo_surface_destroy(surface);
>    return;
>
> Any other ideas?
>
> TIA,
>
> Simon
>
> ----- Original Message ----
> From: Daniel Amelang <daniel.amelang at gmail.com>
> To: Simon Flannery <simon_flannery at yahoo.com.au>
> Cc: cairo at cairographics.org
> Sent: Monday, 4 December, 2006 10:55:15 AM
> Subject: Re: [cairo] Loading SVG from memory using RSVG
>
>
> On 12/3/06, Simon Flannery <simon_flannery at yahoo.com.au> wrote:
> > Hi,
> >
> > Loading and rendering a SVG from a file was error free, but how do you load and render a SVG from a chunk of memory?
> >
> > For example:
> >
> > ..
> > const unsigned char* data = (const unsigned char*) "<svg xmlns=\"http://www.w3.org/2000/svg\"; version=\"1.1\"><desc>Simple Polygon Test</desc><polygon fill=\"#69c2d4\" stroke=\"#facd2d\" stroke-width=\"7\" points=\"119,0 148,86 238,86 166,140 192,226 119,175 46,226 72,140 0,86 90,86\" /></svg>"; // should render a star.
> > ..
> > g_my_svg = rsvg_handle_new_from_data(data, sizeof(data), &pError);
> > MessageBox(NULL, pError->message, "Error", 0); // Always says "Error parsing XML data"
> > ..
> >
> > I can load the exact same XML / SVG from a file and get cario to render it, but no luck from memory. Any Ideas, Help?
>
> The rsvg list is here:
>
> http://lists.sourceforge.net/lists/listinfo/librsvg-devel
>
> But, for what it's worth, I think what you're looking for is rsvg_handle_write.
>
> Dan
>
> Send instant messages to your online friends http://au.messenger.yahoo.com
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://cairographics.org/cgi-bin/mailman/listinfo/cairo
>


-- 
Counting bodies like sheep to the rhythm of the war drums.


More information about the cairo mailing list