[librsvg: 6/12] state: move fill opacity to rust



commit ba0f4a592f4aec0010fc871281a1c64d50a0f542
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Apr 21 17:46:55 2018 +0200

    state: move fill opacity to rust

 librsvg/rsvg-styles.c       | 26 --------------------------
 librsvg/rsvg-styles.h       |  5 -----
 rsvg_internals/src/state.rs | 24 +++++++++++++++++++++---
 3 files changed, 21 insertions(+), 34 deletions(-)
---
diff --git a/librsvg/rsvg-styles.c b/librsvg/rsvg-styles.c
index 00850c1d..7c6802c6 100644
--- a/librsvg/rsvg-styles.c
+++ b/librsvg/rsvg-styles.c
@@ -101,7 +101,6 @@ rsvg_state_init (RsvgState * state)
                                         * opaque black instead of transparent.
                                         */
     state->fill = rsvg_paint_server_parse (NULL, "#000");
-    state->fill_opacity = 0xff;
     state->stroke_opacity = 0xff;
 
     /* The following two start as INHERIT, even though has_stop_color and
@@ -119,7 +118,6 @@ rsvg_state_init (RsvgState * state)
     state->has_current_color = FALSE;
     state->has_flood_color = FALSE;
     state->has_fill_server = FALSE;
-    state->has_fill_opacity = FALSE;
     state->has_stroke_server = FALSE;
     state->has_stroke_opacity = FALSE;
     state->has_stop_color = FALSE;
@@ -221,8 +219,6 @@ rsvg_state_inherit_run (RsvgState * dst, const RsvgState * src,
             rsvg_paint_server_unref (dst->fill);
         dst->fill = src->fill;
     }
-    if (function (dst->has_fill_opacity, src->has_fill_opacity))
-        dst->fill_opacity = src->fill_opacity;
     if (function (dst->has_stroke_server, src->has_stroke_server)) {
         rsvg_paint_server_ref (src->stroke);
         if (dst->stroke)
@@ -444,22 +440,6 @@ rsvg_parse_style_pair (RsvgState *state,
     }
     break;
 
-    case RSVG_ATTRIBUTE_FILL_OPACITY:
-    {
-        RsvgOpacitySpec spec;
-
-        spec = rsvg_css_parse_opacity (value);
-        if (spec.kind == RSVG_OPACITY_SPECIFIED) {
-            state->fill_opacity = spec.opacity;
-        } else {
-            state->fill_opacity = 0;
-            /* FIXME: handle INHERIT and PARSE_ERROR */
-        }
-
-        state->has_fill_opacity = TRUE;
-    }
-    break;
-
     case RSVG_ATTRIBUTE_STROKE:
     {
         RsvgPaintServer *stroke = state->stroke;
@@ -1121,12 +1101,6 @@ rsvg_state_get_fill (RsvgState *state)
     return state->fill;
 }
 
-guint8
-rsvg_state_get_fill_opacity (RsvgState *state)
-{
-    return state->fill_opacity;
-}
-
 guint32
 rsvg_state_get_flood_color (RsvgState *state)
 {
diff --git a/librsvg/rsvg-styles.h b/librsvg/rsvg-styles.h
index 895d2638..18a1d069 100644
--- a/librsvg/rsvg-styles.h
+++ b/librsvg/rsvg-styles.h
@@ -52,8 +52,6 @@ struct _RsvgState {
 
     RsvgPaintServer *fill;
     gboolean has_fill_server;
-    guint8 fill_opacity;        /* 0..255 */
-    gboolean has_fill_opacity;
 
     RsvgPaintServer *stroke;
     gboolean has_stroke_server;
@@ -154,9 +152,6 @@ guint32 rsvg_state_get_current_color (RsvgState *state);
 G_GNUC_INTERNAL
 RsvgPaintServer *rsvg_state_get_fill (RsvgState *state);
 
-G_GNUC_INTERNAL
-guint8 rsvg_state_get_fill_opacity (RsvgState *state);
-
 G_GNUC_INTERNAL
 guint32 rsvg_state_get_flood_color (RsvgState *state);
 
diff --git a/rsvg_internals/src/state.rs b/rsvg_internals/src/state.rs
index ccc52498..7f40b0f0 100644
--- a/rsvg_internals/src/state.rs
+++ b/rsvg_internals/src/state.rs
@@ -14,7 +14,7 @@ use error::*;
 use iri::IRI;
 use length::{Dasharray, LengthDir, RsvgLength};
 use node::RsvgNode;
-use opacity::{Opacity, OpacitySpec};
+use opacity::{Opacity, OpacitySpec, opacity_to_u8};
 use paint_server::PaintServer;
 use parsers::Parse;
 use property_bag::PropertyBag;
@@ -47,6 +47,7 @@ pub struct State {
     pub direction: Option<Direction>,
     pub display: Option<Display>,
     pub enable_background: Option<EnableBackground>,
+    pub fill_opacity: Option<FillOpacity>,
     pub fill_rule: Option<FillRule>,
     pub filter: Option<Filter>,
     pub flood_opacity: Option<FloodOpacity>,
@@ -95,6 +96,7 @@ impl State {
             direction: Default::default(),
             display: Default::default(),
             enable_background: Default::default(),
+            fill_opacity: Default::default(),
             fill_rule: Default::default(),
             filter: Default::default(),
             flood_opacity: Default::default(),
@@ -167,6 +169,10 @@ impl State {
                 self.enable_background = parse_property(value, ())?;
             }
 
+            Attribute::FillOpacity => {
+                self.fill_opacity = parse_property(value, ())?;
+            }
+
             Attribute::FillRule => {
                 self.fill_rule = parse_property(value, ())?;
             }
@@ -374,7 +380,6 @@ extern "C" {
     fn rsvg_state_get_stroke(state: *const RsvgState) -> *const PaintServer;
     fn rsvg_state_get_stroke_opacity(state: *const RsvgState) -> u8;
     fn rsvg_state_get_fill(state: *const RsvgState) -> *const PaintServer;
-    fn rsvg_state_get_fill_opacity(state: *const RsvgState) -> u8;
 
     fn rsvg_state_dominate(state: *mut RsvgState, src: *const RsvgState);
     fn rsvg_state_force(state: *mut RsvgState, src: *const RsvgState);
@@ -516,7 +521,12 @@ pub fn get_fill<'a>(state: *const RsvgState) -> Option<&'a PaintServer> {
 }
 
 pub fn get_fill_opacity(state: *const RsvgState) -> u8 {
-    unsafe { rsvg_state_get_fill_opacity(state) }
+    let rstate = get_state_rust(state);
+
+    match rstate.fill_opacity {
+        Some(FillOpacity(Opacity::Specified(opacity))) => opacity_to_u8(opacity),
+        _ => 255,
+    }
 }
 
 pub fn dominate(state: *mut RsvgState, src: *const RsvgState) {
@@ -672,6 +682,13 @@ make_property!(
     "new" => New,
 );
 
+make_property!(
+    FillOpacity,
+    default: Opacity::Specified(1.0),
+    inherits_automatically: true,
+    newtype_from_str: Opacity
+);
+
 make_property!(
     FillRule,
     default: NonZero,
@@ -1124,6 +1141,7 @@ pub extern "C" fn rsvg_state_rust_inherit_run(
     inherit(inherit_fn, &mut dst.clip_rule, &src.clip_rule);
     inherit(inherit_fn, &mut dst.direction, &src.direction);
     inherit(inherit_fn, &mut dst.display, &src.display);
+    inherit(inherit_fn, &mut dst.fill_opacity, &src.fill_opacity);
     inherit(inherit_fn, &mut dst.fill_rule, &src.fill_rule);
     inherit(inherit_fn, &mut dst.flood_opacity, &src.flood_opacity);
     inherit(inherit_fn, &mut dst.font_family, &src.font_family);


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