Commit b58834b0 authored by Dominic Lachowicz's avatar Dominic Lachowicz Committed by Dom Lachowicz

Make cairo render functions return a gboolean. Returns TRUE if the image

2008-08-26  Dominic Lachowicz <domlachowicz@gmail.com>

        * rsvg-cairo.h: Make cairo render functions return a gboolean. Returns TRUE
        if the image can't be rendered
        * rsvg.c: Check && handle the return value
        * rsvg-cairo-render.c: Implement the above. Also, return FALSE if we're asked
        to render an ID that doesn't exist

        Collectively, fixes #540383 - rsvg_handle_render_cairo_sub - if ID not found,
        return an error and/or dont render whole SVG


svn path=/trunk/; revision=1175
parent 011bd059
2008-08-26 Dominic Lachowicz <domlachowicz@gmail.com>
* rsvg-cairo.h: Make cairo render functions return a gboolean. Returns TRUE
if the image can't be rendered
* rsvg.c: Check && handle the return value
* rsvg-cairo-render.c: Implement the above. Also, return FALSE if we're asked
to render an ID that doesn't exist
Collectively, fixes #540383 - rsvg_handle_render_cairo_sub - if ID not found,
return an error and/or dont render whole SVG
2008-08-26 Dominic Lachowicz <domlachowicz@gmail.com>
* rsvg-private.h: #539488 - migrate use of GMemChunk to GSlice, from Felix Riemann
......
......@@ -196,24 +196,29 @@ rsvg_cairo_new_drawing_ctx (cairo_t * cr, RsvgHandle * handle)
*
* Since: 2.14
*/
void
gboolean
rsvg_handle_render_cairo_sub (RsvgHandle * handle, cairo_t * cr, const char *id)
{
RsvgDrawingCtx *draw;
RsvgNode *drawsub = NULL;
g_return_if_fail (handle != NULL);
g_return_val_if_fail (handle != NULL, FALSE);
if (!handle->priv->finished)
return;
draw = rsvg_cairo_new_drawing_ctx (cr, handle);
if (!draw)
return;
return FALSE;
if (id && *id)
drawsub = rsvg_defs_lookup (handle->priv->defs, id);
if (drawsub == NULL && id != NULL) {
/* todo: there's no way to signal that @id doesn't exist */
return FALSE;
}
draw = rsvg_cairo_new_drawing_ctx (cr, handle);
if (!draw)
return FALSE;
while (drawsub != NULL) {
draw->drawsub_stack = g_slist_prepend (draw->drawsub_stack, drawsub);
drawsub = drawsub->parent;
......@@ -227,6 +232,8 @@ rsvg_handle_render_cairo_sub (RsvgHandle * handle, cairo_t * cr, const char *id)
cairo_restore (cr);
rsvg_state_pop (draw);
rsvg_drawing_ctx_free (draw);
return TRUE;
}
/**
......@@ -238,8 +245,8 @@ rsvg_handle_render_cairo_sub (RsvgHandle * handle, cairo_t * cr, const char *id)
*
* Since: 2.14
*/
void
gboolean
rsvg_handle_render_cairo (RsvgHandle * handle, cairo_t * cr)
{
rsvg_handle_render_cairo_sub (handle, cr, NULL);
return rsvg_handle_render_cairo_sub (handle, cr, NULL);
}
......@@ -29,8 +29,8 @@
G_BEGIN_DECLS
void rsvg_handle_render_cairo (RsvgHandle * handle, cairo_t * cr);
void rsvg_handle_render_cairo_sub (RsvgHandle * handle, cairo_t * cr, const char *id);
gboolean rsvg_handle_render_cairo (RsvgHandle * handle, cairo_t * cr);
gboolean rsvg_handle_render_cairo_sub (RsvgHandle * handle, cairo_t * cr, const char *id);
G_END_DECLS
......
......@@ -94,23 +94,26 @@ rsvg_handle_get_pixbuf_sub (RsvgHandle * handle, const char *id)
surface = cairo_image_surface_create_for_data (pixels,
CAIRO_FORMAT_ARGB32,
dimensions.width, dimensions.height, rowstride);
cr = cairo_create (surface);
cairo_surface_destroy (surface);
rsvg_handle_render_cairo_sub (handle, cr, id);
rsvg_cairo_to_pixbuf (pixels, rowstride, dimensions.height);
output = gdk_pixbuf_new_from_data (pixels,
GDK_COLORSPACE_RGB,
TRUE,
8,
dimensions.width,
dimensions.height,
rowstride,
(GdkPixbufDestroyNotify) rsvg_pixmap_destroy, NULL);
if (rsvg_handle_render_cairo_sub (handle, cr, id)) {
rsvg_cairo_to_pixbuf (pixels, rowstride, dimensions.height);
output = gdk_pixbuf_new_from_data (pixels,
GDK_COLORSPACE_RGB,
TRUE,
8,
dimensions.width,
dimensions.height,
rowstride,
(GdkPixbufDestroyNotify) rsvg_pixmap_destroy, NULL);
} else {
g_free (pixels);
output = NULL;
}
cairo_destroy (cr);
cairo_surface_destroy (surface);
return output;
}
......
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