[librsvg: 1/10] drawing_ctx: add a getter for the offset
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 1/10] drawing_ctx: add a getter for the offset
- Date: Mon, 14 May 2018 01:38:04 +0000 (UTC)
commit a2acb3077e9610215979cef0e5bb36852c8588bb
Author: Paolo Borelli <pborelli gnome org>
Date: Sun May 13 12:07:49 2018 +0200
drawing_ctx: add a getter for the offset
librsvg/filters/common.c | 7 +++++--
librsvg/rsvg-base.c | 12 ++++++++++++
librsvg/rsvg-cairo-draw.c | 22 +++++++++++++---------
librsvg/rsvg-private.h | 9 ++++++---
4 files changed, 36 insertions(+), 14 deletions(-)
---
diff --git a/librsvg/filters/common.c b/librsvg/filters/common.c
index 6892adb4..bb760e59 100644
--- a/librsvg/filters/common.c
+++ b/librsvg/filters/common.c
@@ -582,6 +582,7 @@ rsvg_compile_bg (RsvgDrawingCtx * ctx)
RsvgCairoRender *render = ctx->render;
cairo_surface_t *surface;
cairo_t *cr;
+ double x, y;
GList *i;
surface = _rsvg_image_surface_new (render->width, render->height);
@@ -590,12 +591,14 @@ rsvg_compile_bg (RsvgDrawingCtx * ctx)
cr = cairo_create (surface);
+ rsvg_drawing_ctx_get_offset (ctx, &x, &y);
+
for (i = g_list_last (render->cr_stack); i != NULL; i = g_list_previous (i)) {
cairo_t *draw = i->data;
gboolean nest = draw != render->initial_cr;
cairo_set_source_surface (cr, cairo_get_target (draw),
- nest ? 0 : -render->offset_x,
- nest ? 0 : -render->offset_y);
+ nest ? 0 : -x,
+ nest ? 0 : -y);
cairo_paint (cr);
}
diff --git a/librsvg/rsvg-base.c b/librsvg/rsvg-base.c
index 35793c5a..64e2b3e6 100644
--- a/librsvg/rsvg-base.c
+++ b/librsvg/rsvg-base.c
@@ -657,6 +657,18 @@ rsvg_drawing_ctx_set_affine_on_cr (RsvgDrawingCtx *draw_ctx, cairo_t *cr, cairo_
cairo_set_matrix (cr, &matrix);
}
+void
+rsvg_drawing_ctx_get_offset (RsvgDrawingCtx *draw_ctx, double *x, double *y)
+{
+ if (x != NULL) {
+ *x = draw_ctx->render->offset_x;
+ }
+
+ if (y != NULL) {
+ *y = draw_ctx->render->offset_y;
+ }
+}
+
void
rsvg_drawing_ctx_insert_bbox (RsvgDrawingCtx *draw_ctx, RsvgBbox *bbox)
{
diff --git a/librsvg/rsvg-cairo-draw.c b/librsvg/rsvg-cairo-draw.c
index 58e4dae9..974b68fd 100644
--- a/librsvg/rsvg-cairo-draw.c
+++ b/librsvg/rsvg-cairo-draw.c
@@ -192,10 +192,10 @@ rsvg_cairo_generate_mask (cairo_t * cr, RsvgNode *mask, RsvgDrawingCtx *ctx)
cairo_matrix_t affinesave;
RsvgLength mask_x, mask_y, mask_w, mask_h;
double sx, sy, sw, sh;
- gboolean nest = cr != render->initial_cr;
RsvgCoordUnits mask_units;
RsvgCoordUnits content_units;
cairo_matrix_t affine;
+ double offset_x = 0, offset_y = 0;
g_assert (rsvg_node_get_type (mask) == RSVG_NODE_TYPE_MASK);
@@ -313,10 +313,12 @@ rsvg_cairo_generate_mask (cairo_t * cr, RsvgNode *mask, RsvgDrawingCtx *ctx)
cairo_destroy (mask_cr);
+ if (cr == render->initial_cr) {
+ rsvg_drawing_ctx_get_offset (ctx, &offset_x, &offset_y);
+ }
+
cairo_identity_matrix (cr);
- cairo_mask_surface (cr, surface,
- nest ? 0 : render->offset_x,
- nest ? 0 : render->offset_y);
+ cairo_mask_surface (cr, surface, offset_x, offset_y);
cairo_surface_destroy (surface);
}
@@ -527,7 +529,8 @@ rsvg_cairo_pop_render_stack (RsvgDrawingCtx * ctx)
cairo_t *child_cr = render->cr;
RsvgNode *lateclip = NULL;
cairo_surface_t *surface = NULL;
- gboolean nest, needs_destroy = FALSE;
+ gboolean needs_destroy = FALSE;
+ double offset_x = 0, offset_y = 0;
state = rsvg_drawing_ctx_get_current_state (ctx);
clip_path = rsvg_state_get_clip_path (state);
@@ -581,11 +584,12 @@ rsvg_cairo_pop_render_stack (RsvgDrawingCtx * ctx)
render->cr = (cairo_t *) render->cr_stack->data;
render->cr_stack = g_list_delete_link (render->cr_stack, render->cr_stack);
- nest = render->cr != render->initial_cr;
+ if (render->cr == render->initial_cr) {
+ rsvg_drawing_ctx_get_offset (ctx, &offset_x, &offset_y);
+ }
+
cairo_identity_matrix (render->cr);
- cairo_set_source_surface (render->cr, surface,
- nest ? 0 : render->offset_x,
- nest ? 0 : render->offset_y);
+ cairo_set_source_surface (render->cr, surface, offset_x, offset_y);
if (lateclip) {
rsvg_cairo_clip (ctx, lateclip, &ctx->bbox);
diff --git a/librsvg/rsvg-private.h b/librsvg/rsvg-private.h
index 0b43514c..f0cfb2da 100644
--- a/librsvg/rsvg-private.h
+++ b/librsvg/rsvg-private.h
@@ -467,9 +467,7 @@ void rsvg_drawing_ctx_draw_node_from_stack (RsvgDrawingCtx *ctx,
gboolean clipping);
G_GNUC_INTERNAL
-cairo_surface_t *rsvg_cairo_surface_from_pixbuf (const GdkPixbuf *pixbuf);
-G_GNUC_INTERNAL
-GdkPixbuf *rsvg_cairo_surface_to_pixbuf (cairo_surface_t *surface);
+void rsvg_drawing_ctx_get_offset (RsvgDrawingCtx *draw_ctx, double *x, double *y);
G_GNUC_INTERNAL
void rsvg_drawing_ctx_insert_bbox (RsvgDrawingCtx *draw_ctx, RsvgBbox *bbox);
@@ -477,6 +475,11 @@ void rsvg_drawing_ctx_insert_bbox (RsvgDrawingCtx *draw_ctx, RsvgBbox *bbox);
G_GNUC_INTERNAL
void rsvg_drawing_ctx_insert_ink_bbox (RsvgDrawingCtx *draw_ctx, RsvgBbox *ink_bbox);
+G_GNUC_INTERNAL
+cairo_surface_t *rsvg_cairo_surface_from_pixbuf (const GdkPixbuf *pixbuf);
+G_GNUC_INTERNAL
+GdkPixbuf *rsvg_cairo_surface_to_pixbuf (cairo_surface_t *surface);
+
G_GNUC_INTERNAL
cairo_surface_t *rsvg_cairo_surface_new_from_href (RsvgHandle *handle, const char *href, GError ** error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]