[librsvg/rustification] Use a new rsvg_drawing_ctx_get_view_box_size() throughout



commit 2376ac2a826854b4c3645bc0976096b86cefb3b5
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Nov 16 14:35:32 2016 -0600

    Use a new rsvg_drawing_ctx_get_view_box_size() throughout
    
    Instead of accessing ctx->vb.rect.{width,height} directly, introduce an
    accesor function.

 rsvg-base.c    |    7 +++++++
 rsvg-css.c     |   11 +++++++----
 rsvg-filter.c  |   32 ++++++++++++++++++++------------
 rsvg-private.h |    3 +++
 4 files changed, 37 insertions(+), 16 deletions(-)
---
diff --git a/rsvg-base.c b/rsvg-base.c
index fc851b4..302c117 100644
--- a/rsvg-base.c
+++ b/rsvg-base.c
@@ -2379,6 +2379,13 @@ rsvg_drawing_ctx_pop_view_box (RsvgDrawingCtx * ctx)
 }
 
 void
+rsvg_drawing_ctx_get_view_box_size (RsvgDrawingCtx *ctx, double *out_width, double *out_height)
+{
+    *out_width = ctx->vb.rect.width;
+    *out_height = ctx->vb.rect.height;
+}
+
+void
 rsvg_return_if_fail_warning (const char *pretty_function, const char *expression, GError ** error)
 {
     g_set_error (error, RSVG_ERROR, 0, _("%s: assertion `%s' failed"), pretty_function, expression);
diff --git a/rsvg-css.c b/rsvg-css.c
index dae852f..12c721d 100644
--- a/rsvg-css.c
+++ b/rsvg-css.c
@@ -122,16 +122,19 @@ _rsvg_css_normalize_length (const RsvgLength * in, RsvgDrawingCtx * ctx)
     if (in->unit == LENGTH_UNIT_DEFAULT)
         return in->length;
     else if (in->unit == LENGTH_UNIT_PERCENT) {
+        double w, h;
+
+        rsvg_drawing_ctx_get_view_box_size (ctx, &w, &h);
+
         switch (in->dir) {
         case LENGTH_DIR_HORIZONTAL:
-            return in->length * ctx->vb.rect.width;
+            return in->length * w;
 
         case LENGTH_DIR_VERTICAL:
-            return in->length * ctx->vb.rect.height;
+            return in->length * h;
 
         case LENGTH_DIR_BOTH:
-            return in->length * rsvg_viewport_percentage (ctx->vb.rect.width,
-                                                          ctx->vb.rect.height);
+            return in->length * rsvg_viewport_percentage (w, h);
         }
     } else if (in->unit == LENGTH_UNIT_FONT_EM || in->unit == LENGTH_UNIT_FONT_EX) {
         double font = _rsvg_css_normalize_font_size (rsvg_current_state (ctx), ctx);
diff --git a/rsvg-filter.c b/rsvg-filter.c
index bc51061..ff588c0 100644
--- a/rsvg-filter.c
+++ b/rsvg-filter.c
@@ -170,10 +170,8 @@ rsvg_filter_primitive_get_bounds (RsvgFilterPrimitive * self, RsvgFilterContext
 
     rsvg_bbox_insert (&box, &otherbox);
 
-    if (self != NULL)
-        if (self->x_specified || self->y_specified ||
-            self->width_specified || self->height_specified) {
-
+    if (self != NULL) {
+        if (self->x_specified || self->y_specified || self->width_specified || self->height_specified) {
             rsvg_bbox_init (&otherbox, &ctx->paffine);
             otherbox.virgin = 0;
             if (ctx->filter->primitiveunits == objectBoundingBox)
@@ -186,18 +184,28 @@ rsvg_filter_primitive_get_bounds (RsvgFilterPrimitive * self, RsvgFilterContext
                 otherbox.rect.y = _rsvg_css_normalize_length (&self->y, ctx->ctx);
             else
                 otherbox.rect.y = 0;
-            if (self->width_specified)
-                otherbox.rect.width = _rsvg_css_normalize_length (&self->width, ctx->ctx);
-            else
-                otherbox.rect.width = ctx->ctx->vb.rect.width;
-            if (self->height_specified)
-                otherbox.rect.height = _rsvg_css_normalize_length (&self->height, ctx->ctx);
-            else
-                otherbox.rect.height = ctx->ctx->vb.rect.height;
+
+            if (self->width_specified || self->height_specified) {
+                double curr_vbox_w, curr_vbox_h;
+
+                rsvg_drawing_ctx_get_view_box_size (ctx->ctx, &curr_vbox_w, &curr_vbox_h);
+
+                if (self->width_specified)
+                    otherbox.rect.width = _rsvg_css_normalize_length (&self->width, ctx->ctx);
+                else
+                    otherbox.rect.width = curr_vbox_w;
+
+                if (self->height_specified)
+                    otherbox.rect.height = _rsvg_css_normalize_length (&self->height, ctx->ctx);
+                else
+                    otherbox.rect.height = curr_vbox_h;
+            }
+
             if (ctx->filter->primitiveunits == objectBoundingBox)
                 rsvg_drawing_ctx_pop_view_box (ctx->ctx);
             rsvg_bbox_clip (&box, &otherbox);
         }
+    }
 
     rsvg_bbox_init (&otherbox, &affine);
     otherbox.virgin = 0;
diff --git a/rsvg-private.h b/rsvg-private.h
index f0bac75..059ea23 100644
--- a/rsvg-private.h
+++ b/rsvg-private.h
@@ -444,6 +444,9 @@ void rsvg_drawing_ctx_push_view_box (RsvgDrawingCtx * ctx, double w, double h);
 G_GNUC_INTERNAL
 void rsvg_drawing_ctx_pop_view_box  (RsvgDrawingCtx * ctx);
 G_GNUC_INTERNAL
+void rsvg_drawing_ctx_get_view_box_size (RsvgDrawingCtx *ctx, double *out_width, double *out_height);
+
+G_GNUC_INTERNAL
 void rsvg_SAX_handler_struct_init (void);
 G_GNUC_INTERNAL
 char *rsvg_get_url_string (const char *str);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]