[librsvg] Remove redundant STOP_OPACITY_UNSPECIFIED



commit 2f469fe4e3d262fff766aa0e6c73d57e8d1e09bb
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue May 30 10:26:13 2017 -0500

    Remove redundant STOP_OPACITY_UNSPECIFIED
    
    We use state->has_stop_opacity for that.
    
    I am really not liking the way rsvg_state_inherit_run() has the logic
    for whether a particular attribute is inherited or not.  This should be
    at the "stop" element level --- the attributes *are* cascaded as
    expected for other elements.

 rsvg-paint-server.c |   38 +++++++++++++++++++++++++-------------
 rsvg-styles.c       |   20 +++++++++++++++-----
 rsvg-styles.h       |    1 -
 3 files changed, 40 insertions(+), 19 deletions(-)
---
diff --git a/rsvg-paint-server.c b/rsvg-paint-server.c
index 8570866..3609c77 100644
--- a/rsvg-paint-server.c
+++ b/rsvg-paint-server.c
@@ -296,22 +296,34 @@ rsvg_stop_set_atts (RsvgNode *node, gpointer impl, RsvgHandle *handle, RsvgPrope
         color = 0;
     }
 
-    switch (state->stop_opacity_mode) {
-    case STOP_OPACITY_UNSPECIFIED:
-        opacity = 0xff;
-        break;
+    if (state->has_stop_opacity) {
+        switch (state->stop_opacity_mode) {
+        case STOP_OPACITY_SPECIFIED:
+            opacity = state->stop_opacity;
+            break;
+
+        case STOP_OPACITY_INHERIT:
+            switch (inherited_state->stop_opacity_mode) {
+            case STOP_OPACITY_SPECIFIED:
+                opacity = inherited_state->stop_opacity;
+                break;
 
-    case STOP_OPACITY_SPECIFIED:
-        opacity = state->stop_opacity;
-        break;
+            case STOP_OPACITY_INHERIT:
+                opacity = 0xff;
+                break;
 
-    case STOP_OPACITY_INHERIT:
-        opacity = inherited_state->stop_opacity;
-        break;
+            default:
+                g_assert_not_reached ();
+                return;
+            }
+            break;
 
-    default:
-        g_assert_not_reached ();
-        opacity = 0;
+        default:
+            g_assert_not_reached ();
+            return;
+        }
+    } else {
+        opacity = 0xff;
     }
 
     stop->rgba = (color << 8) | opacity;
diff --git a/rsvg-styles.c b/rsvg-styles.c
index 8aef422..5469e8a 100644
--- a/rsvg-styles.c
+++ b/rsvg-styles.c
@@ -104,8 +104,17 @@ rsvg_state_init (RsvgState * state)
     state->miter_limit = 4;
     state->cap = CAIRO_LINE_CAP_BUTT;
     state->join = CAIRO_LINE_JOIN_MITER;
-    state->stop_opacity = 0xff;
-    state->stop_opacity_mode = STOP_OPACITY_UNSPECIFIED;
+
+    /* The following two start as INHERIT, even though has_stop_color and
+     * has_stop_opacity get initialized to FALSE below.  This is so that the
+     * first pass of rsvg_state_inherit_run(), called from
+     * rsvg_state_reconstruct() from the "stop" element code, will correctly
+     * initialize the destination state from the toplevel element.
+     *
+     */
+    state->stop_color.kind = RSVG_CSS_COLOR_SPEC_INHERIT;
+    state->stop_opacity_mode = STOP_OPACITY_INHERIT;
+
     state->fill_rule = CAIRO_FILL_RULE_WINDING;
     state->clip_rule = CAIRO_FILL_RULE_WINDING;
     state->enable_background = RSVG_ENABLE_BACKGROUND_ACCUMULATE;
@@ -343,8 +352,10 @@ rsvg_state_inherit_run (RsvgState * dst, const RsvgState * src,
         }
     }
     if (function (dst->has_stop_opacity, src->has_stop_opacity)) {
-        dst->stop_opacity = src->stop_opacity;
-        dst->stop_opacity_mode = src->stop_opacity_mode;
+        if (dst->stop_opacity_mode == STOP_OPACITY_INHERIT) {
+            dst->stop_opacity = src->stop_opacity;
+            dst->stop_opacity_mode = src->stop_opacity_mode;
+        }
     }
     if (function (dst->has_cond, src->has_cond))
         dst->cond_true = src->cond_true;
@@ -844,7 +855,6 @@ rsvg_parse_style_pair (RsvgState * state,
     } else if (g_str_equal (name, "stop-opacity")) {
         state->has_stop_opacity = TRUE;
         if (g_str_equal (value, "inherit")) {
-            state->has_stop_opacity = FALSE;
             state->stop_opacity_mode = STOP_OPACITY_INHERIT;
         } else {
             state->stop_opacity = rsvg_css_parse_opacity (value);
diff --git a/rsvg-styles.h b/rsvg-styles.h
index 9cea381..b2b792e 100644
--- a/rsvg-styles.h
+++ b/rsvg-styles.h
@@ -73,7 +73,6 @@ struct _RsvgVpathDash {
 };
 
 typedef enum {
-    STOP_OPACITY_UNSPECIFIED,
     STOP_OPACITY_SPECIFIED,
     STOP_OPACITY_INHERIT
 } StopOpacity;


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