[librsvg] Add rsvg_get_surface_of_node
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Add rsvg_get_surface_of_node
- Date: Mon, 28 Nov 2011 12:46:49 +0000 (UTC)
commit 0b8f017df3fe4d1975efad610f9afcce8a94f8e3
Author: Christian Persch <chpe gnome org>
Date: Sat Nov 26 22:18:17 2011 +0100
Add rsvg_get_surface_of_node
Similar to rsvg_get_pixbuf_of_node except that it returns a cairo_surface_t.
rsvg-base.c | 6 ++++++
rsvg-cairo-clip.c | 1 +
rsvg-cairo-draw.c | 35 +++++++++++++++++++++++++++++++++++
rsvg-cairo-draw.h | 2 ++
rsvg-cairo-render.c | 2 ++
rsvg-private.h | 4 +++-
6 files changed, 49 insertions(+), 1 deletions(-)
---
diff --git a/rsvg-base.c b/rsvg-base.c
index d61789d..6618298 100644
--- a/rsvg-base.c
+++ b/rsvg-base.c
@@ -1974,6 +1974,12 @@ rsvg_get_image_of_node (RsvgDrawingCtx * ctx, RsvgNode * drawable, double w, dou
return ctx->render->get_image_of_node (ctx, drawable, w, h);
}
+cairo_surface_t *
+rsvg_get_surface_of_node (RsvgDrawingCtx * ctx, RsvgNode * drawable, double w, double h)
+{
+ return ctx->render->get_surface_of_node (ctx, drawable, w, h);
+}
+
void
rsvg_render_free (RsvgRender * render)
{
diff --git a/rsvg-cairo-clip.c b/rsvg-cairo-clip.c
index 5f078d9..f634574 100644
--- a/rsvg-cairo-clip.c
+++ b/rsvg-cairo-clip.c
@@ -127,6 +127,7 @@ rsvg_cairo_clip_render_new (cairo_t * cr, RsvgCairoRender *parent)
render->push_discrete_layer = rsvg_cairo_clip_push_discrete_layer;
render->add_clipping_rect = rsvg_cairo_clip_add_clipping_rect;
render->get_image_of_node = NULL;
+ render->get_surface_of_node = NULL;
cairo_render->initial_cr = parent->cr;
cairo_render->cr = cr;
clip_render->parent = parent;
diff --git a/rsvg-cairo-draw.c b/rsvg-cairo-draw.c
index a086bde..2611f88 100644
--- a/rsvg-cairo-draw.c
+++ b/rsvg-cairo-draw.c
@@ -995,6 +995,41 @@ rsvg_cairo_get_image_of_node (RsvgDrawingCtx * ctx,
return img;
}
+cairo_surface_t *
+rsvg_cairo_get_surface_of_node (RsvgDrawingCtx *ctx,
+ RsvgNode *drawable,
+ double width,
+ double height)
+{
+ cairo_surface_t *surface;
+ cairo_t *cr;
+
+ RsvgCairoRender *save_render = (RsvgCairoRender *) ctx->render;
+ RsvgCairoRender *render;
+
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
+ if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) {
+ cairo_surface_destroy (surface);
+ return NULL;
+ }
+
+ cr = cairo_create (surface);
+
+ render = rsvg_cairo_render_new (cr, width, height);
+ ctx->render = (RsvgRender *) render;
+
+ rsvg_state_push (ctx);
+ rsvg_node_draw (drawable, ctx, 0);
+ rsvg_state_pop (ctx);
+
+ cairo_destroy (cr);
+
+ rsvg_render_free (ctx->render);
+ ctx->render = (RsvgRender *) save_render;
+
+ return surface;
+}
+
void
rsvg_cairo_to_pixbuf (guint8 * pixels, int rowstride, int height)
{
diff --git a/rsvg-cairo-draw.h b/rsvg-cairo-draw.h
index c164498..1728d1c 100644
--- a/rsvg-cairo-draw.h
+++ b/rsvg-cairo-draw.h
@@ -46,6 +46,8 @@ void rsvg_cairo_add_clipping_rect (RsvgDrawingCtx *ctx,
GdkPixbuf *rsvg_cairo_get_image_of_node (RsvgDrawingCtx *ctx, RsvgNode *drawable,
double width, double height);
+cairo_surface_t*rsvg_cairo_get_surface_of_node (RsvgDrawingCtx *ctx, RsvgNode *drawable,
+ double width, double height);
void rsvg_cairo_to_pixbuf (guint8 * pixels, int rowstride, int height);
void rsvg_pixbuf_to_cairo (guint8 * pixels, int rowstride, int height);
diff --git a/rsvg-cairo-render.c b/rsvg-cairo-render.c
index 8edf768..afbfb5f 100644
--- a/rsvg-cairo-render.c
+++ b/rsvg-cairo-render.c
@@ -32,6 +32,7 @@
#include <string.h>
#include "rsvg.h"
+#include "rsvg-private.h"
#include "rsvg-cairo.h"
#include "rsvg-cairo-draw.h"
#include "rsvg-cairo-render.h"
@@ -63,6 +64,7 @@ rsvg_cairo_render_new (cairo_t * cr, double width, double height)
cairo_render->super.push_discrete_layer = rsvg_cairo_push_discrete_layer;
cairo_render->super.add_clipping_rect = rsvg_cairo_add_clipping_rect;
cairo_render->super.get_image_of_node = rsvg_cairo_get_image_of_node;
+ cairo_render->super.get_surface_of_node = rsvg_cairo_get_surface_of_node;
cairo_render->width = width;
cairo_render->height = height;
cairo_render->offset_x = 0;
diff --git a/rsvg-private.h b/rsvg-private.h
index c39d1e7..dee875f 100644
--- a/rsvg-private.h
+++ b/rsvg-private.h
@@ -224,6 +224,8 @@ struct RsvgRender {
double w, double h);
GdkPixbuf *(*get_image_of_node) (RsvgDrawingCtx * ctx, RsvgNode * drawable,
double w, double h);
+ cairo_surface_t *(*get_surface_of_node) (RsvgDrawingCtx * ctx, RsvgNode * drawable,
+ double w, double h);
};
static inline RsvgRender *
@@ -379,7 +381,7 @@ void rsvg_render_image (RsvgDrawingCtx * ctx, GdkPixbuf * pb,
void rsvg_render_free (RsvgRender * render);
void rsvg_add_clipping_rect (RsvgDrawingCtx * ctx, double x, double y, double w, double h);
GdkPixbuf *rsvg_get_image_of_node (RsvgDrawingCtx * ctx, RsvgNode * drawable, double w, double h);
-
+cairo_surface_t *rsvg_get_surface_of_node (RsvgDrawingCtx * ctx, RsvgNode * drawable, double w, double h);
void rsvg_node_set_atts (RsvgNode * node, RsvgHandle * ctx, RsvgPropertyBag * atts);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]