[librsvg: 5/12] state: move flood opacity to rust
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 5/12] state: move flood opacity to rust
- Date: Tue, 24 Apr 2018 23:15:29 +0000 (UTC)
commit ce07268cd05e105de92eb69a3a968c023f3c6db3
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Apr 21 17:22:37 2018 +0200
state: move flood opacity to rust
librsvg/rsvg-styles.c | 23 ++---------------------
librsvg/rsvg-styles.h | 3 ---
rsvg_internals/src/lib.rs | 1 +
rsvg_internals/src/state.rs | 25 +++++++++++++++++++++++++
4 files changed, 28 insertions(+), 24 deletions(-)
---
diff --git a/librsvg/rsvg-styles.c b/librsvg/rsvg-styles.c
index d5bbe083..00850c1d 100644
--- a/librsvg/rsvg-styles.c
+++ b/librsvg/rsvg-styles.c
@@ -45,6 +45,7 @@ extern State *rsvg_state_rust_clone(State *state);
extern cairo_matrix_t rsvg_state_rust_get_affine(const State *state);
extern void rsvg_state_rust_set_affine(State *state, cairo_matrix_t affine);
extern cairo_operator_t rsvg_state_rust_get_comp_op(const State *state);
+extern guint8 rsvg_state_rust_get_flood_opacity(const State *state);
extern RsvgEnableBackgroundType rsvg_state_rust_get_enable_background(const State *state);
extern char *rsvg_state_rust_get_clip_path(const State *state);
extern char *rsvg_state_rust_get_filter(const State *state);
@@ -114,11 +115,9 @@ rsvg_state_init (RsvgState * state)
state->stop_opacity.kind = RSVG_OPACITY_INHERIT;
state->flood_color = 0;
- state->flood_opacity = 255;
state->has_current_color = FALSE;
state->has_flood_color = FALSE;
- state->has_flood_opacity = FALSE;
state->has_fill_server = FALSE;
state->has_fill_opacity = FALSE;
state->has_stroke_server = FALSE;
@@ -216,8 +215,6 @@ rsvg_state_inherit_run (RsvgState * dst, const RsvgState * src,
dst->current_color = src->current_color;
if (function (dst->has_flood_color, src->has_flood_color))
dst->flood_color = src->flood_color;
- if (function (dst->has_flood_opacity, src->has_flood_opacity))
- dst->flood_opacity = src->flood_opacity;
if (function (dst->has_fill_server, src->has_fill_server)) {
rsvg_paint_server_ref (src->fill);
if (dst->fill)
@@ -438,22 +435,6 @@ rsvg_parse_style_pair (RsvgState *state,
}
break;
- case RSVG_ATTRIBUTE_FLOOD_OPACITY:
- {
- RsvgOpacitySpec spec;
-
- spec = rsvg_css_parse_opacity (value);
- if (spec.kind == RSVG_OPACITY_SPECIFIED) {
- state->flood_opacity = spec.opacity;
- } else {
- state->flood_opacity = 0;
- /* FIXME: handle INHERIT and PARSE_ERROR */
- }
-
- state->has_flood_opacity = TRUE;
- }
- break;
-
case RSVG_ATTRIBUTE_FILL:
{
RsvgPaintServer *fill = state->fill;
@@ -1155,7 +1136,7 @@ rsvg_state_get_flood_color (RsvgState *state)
guint8
rsvg_state_get_flood_opacity (RsvgState *state)
{
- return state->flood_opacity;
+ return rsvg_state_rust_get_flood_opacity (state->state_rust);
}
cairo_operator_t
diff --git a/librsvg/rsvg-styles.h b/librsvg/rsvg-styles.h
index 003f3425..895d2638 100644
--- a/librsvg/rsvg-styles.h
+++ b/librsvg/rsvg-styles.h
@@ -72,9 +72,6 @@ struct _RsvgState {
guint32 flood_color;
gboolean has_flood_color;
- guchar flood_opacity;
- gboolean has_flood_opacity;
-
GHashTable *styles;
State *state_rust;
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index 0c3035ff..d3feab2f 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -121,6 +121,7 @@ pub use state::{
rsvg_state_rust_get_affine,
rsvg_state_rust_get_clip_path,
rsvg_state_rust_get_comp_op,
+ rsvg_state_rust_get_flood_opacity,
rsvg_state_rust_get_enable_background,
rsvg_state_rust_get_filter,
rsvg_state_rust_get_mask,
diff --git a/rsvg_internals/src/state.rs b/rsvg_internals/src/state.rs
index 7b977420..ccc52498 100644
--- a/rsvg_internals/src/state.rs
+++ b/rsvg_internals/src/state.rs
@@ -49,6 +49,7 @@ pub struct State {
pub enable_background: Option<EnableBackground>,
pub fill_rule: Option<FillRule>,
pub filter: Option<Filter>,
+ pub flood_opacity: Option<FloodOpacity>,
pub font_family: Option<FontFamily>,
pub font_size: Option<FontSize>,
pub font_stretch: Option<FontStretch>,
@@ -96,6 +97,7 @@ impl State {
enable_background: Default::default(),
fill_rule: Default::default(),
filter: Default::default(),
+ flood_opacity: Default::default(),
font_family: Default::default(),
font_size: Default::default(),
font_stretch: Default::default(),
@@ -173,6 +175,10 @@ impl State {
self.filter = parse_property(value, ())?;
}
+ Attribute::FloodOpacity => {
+ self.flood_opacity = parse_property(value, ())?;
+ }
+
Attribute::FontFamily => {
self.font_family = parse_property(value, ())?;
}
@@ -684,6 +690,13 @@ make_property!(
parse_data_type: ()
);
+make_property!(
+ FloodOpacity,
+ default: Opacity::Specified(1.0),
+ inherits_automatically: true,
+ newtype_from_str: Opacity
+);
+
make_property!(
FontFamily,
default: "Times New Roman".to_string(),
@@ -1112,6 +1125,7 @@ pub extern "C" fn rsvg_state_rust_inherit_run(
inherit(inherit_fn, &mut dst.direction, &src.direction);
inherit(inherit_fn, &mut dst.display, &src.display);
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);
inherit(inherit_fn, &mut dst.font_size, &src.font_size);
inherit(inherit_fn, &mut dst.font_stretch, &src.font_stretch);
@@ -1181,6 +1195,17 @@ pub extern "C" fn rsvg_state_rust_get_comp_op(state: *const State) -> cairo::Ope
}
}
+#[no_mangle]
+pub extern "C" fn rsvg_state_rust_get_flood_opacity(state: *const State) -> u8 {
+ unsafe {
+ let state = &*state;
+ match state.flood_opacity {
+ Some(FloodOpacity(Opacity::Specified(opacity))) => opacity_to_u8(opacity),
+ _ => 255,
+ }
+ }
+}
+
// Keep in sync with rsvg-styles.h:RsvgEnableBackgroundType
#[allow(dead_code)]
#[repr(C)]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]