[librsvg: 7/12] state: move stroke opacity to rust
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 7/12] state: move stroke opacity to rust
- Date: Tue, 24 Apr 2018 23:15:39 +0000 (UTC)
commit 53ddc75730559d736bb8c79b3ad98c6b8a748278
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Apr 21 17:53:32 2018 +0200
state: move stroke opacity to rust
librsvg/rsvg-styles.c | 26 --------------------------
librsvg/rsvg-styles.h | 5 -----
rsvg_internals/src/state.rs | 22 ++++++++++++++++++++--
3 files changed, 20 insertions(+), 33 deletions(-)
---
diff --git a/librsvg/rsvg-styles.c b/librsvg/rsvg-styles.c
index 7c6802c6..e0a17b53 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->stroke_opacity = 0xff;
/* 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
@@ -119,7 +118,6 @@ rsvg_state_init (RsvgState * state)
state->has_flood_color = FALSE;
state->has_fill_server = FALSE;
state->has_stroke_server = FALSE;
- state->has_stroke_opacity = FALSE;
state->has_stop_color = FALSE;
state->has_stop_opacity = FALSE;
@@ -225,8 +223,6 @@ rsvg_state_inherit_run (RsvgState * dst, const RsvgState * src,
rsvg_paint_server_unref (dst->stroke);
dst->stroke = src->stroke;
}
- if (function (dst->has_stroke_opacity, src->has_stroke_opacity))
- dst->stroke_opacity = src->stroke_opacity;
if (function (dst->has_stop_color, src->has_stop_color)) {
if (dst->stop_color.kind == RSVG_CSS_COLOR_SPEC_INHERIT) {
dst->has_stop_color = TRUE;
@@ -451,22 +447,6 @@ rsvg_parse_style_pair (RsvgState *state,
}
break;
- case RSVG_ATTRIBUTE_STROKE_OPACITY:
- {
- RsvgOpacitySpec spec;
-
- spec = rsvg_css_parse_opacity (value);
- if (spec.kind == RSVG_OPACITY_SPECIFIED) {
- state->stroke_opacity = spec.opacity;
- } else {
- state->stroke_opacity = 0;
- /* FIXME: handle INHERIT and PARSE_ERROR */
- }
-
- state->has_stroke_opacity = TRUE;
- }
- break;
-
case RSVG_ATTRIBUTE_STOP_COLOR:
{
state->has_stop_color = TRUE;
@@ -1063,12 +1043,6 @@ rsvg_state_get_stroke (RsvgState *state)
return state->stroke;
}
-guint8
-rsvg_state_get_stroke_opacity (RsvgState *state)
-{
- return state->stroke_opacity;
-}
-
RsvgCssColorSpec *
rsvg_state_get_stop_color (RsvgState *state)
{
diff --git a/librsvg/rsvg-styles.h b/librsvg/rsvg-styles.h
index 18a1d069..81e89eb2 100644
--- a/librsvg/rsvg-styles.h
+++ b/librsvg/rsvg-styles.h
@@ -55,8 +55,6 @@ struct _RsvgState {
RsvgPaintServer *stroke;
gboolean has_stroke_server;
- guint8 stroke_opacity; /* 0..255 */
- gboolean has_stroke_opacity;
RsvgCssColorSpec stop_color;
gboolean has_stop_color;
@@ -137,9 +135,6 @@ guint8 rsvg_state_get_opacity (RsvgState *state);
G_GNUC_INTERNAL
RsvgPaintServer *rsvg_state_get_stroke (RsvgState *state);
-G_GNUC_INTERNAL
-guint8 rsvg_state_get_stroke_opacity (RsvgState *state);
-
G_GNUC_INTERNAL
RsvgCssColorSpec *rsvg_state_get_stop_color (RsvgState *state);
diff --git a/rsvg_internals/src/state.rs b/rsvg_internals/src/state.rs
index 7f40b0f0..f2c9d475 100644
--- a/rsvg_internals/src/state.rs
+++ b/rsvg_internals/src/state.rs
@@ -68,6 +68,7 @@ pub struct State {
pub stroke_dashoffset: Option<StrokeDashoffset>,
pub stroke_line_cap: Option<StrokeLinecap>,
pub stroke_line_join: Option<StrokeLinejoin>,
+ pub stroke_opacity: Option<StrokeOpacity>,
pub stroke_miterlimit: Option<StrokeMiterlimit>,
pub stroke_width: Option<StrokeWidth>,
pub text_anchor: Option<TextAnchor>,
@@ -117,6 +118,7 @@ impl State {
stroke_dashoffset: Default::default(),
stroke_line_cap: Default::default(),
stroke_line_join: Default::default(),
+ stroke_opacity: Default::default(),
stroke_miterlimit: Default::default(),
stroke_width: Default::default(),
text_anchor: Default::default(),
@@ -267,6 +269,10 @@ impl State {
self.stroke_line_join = parse_property(value, ())?;
}
+ Attribute::StrokeOpacity => {
+ self.stroke_opacity = parse_property(value, ())?;
+ }
+
Attribute::StrokeMiterlimit => {
self.stroke_miterlimit = parse_property(value, ())?;
}
@@ -378,7 +384,6 @@ extern "C" {
fn rsvg_state_get_stop_opacity(state: *const RsvgState) -> *const OpacitySpec;
fn rsvg_state_get_current_color(state: *const RsvgState) -> u32;
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_dominate(state: *mut RsvgState, src: *const RsvgState);
@@ -505,7 +510,12 @@ pub fn get_stroke<'a>(state: *const RsvgState) -> Option<&'a PaintServer> {
}
pub fn get_stroke_opacity(state: *const RsvgState) -> u8 {
- unsafe { rsvg_state_get_stroke_opacity(state) }
+ let rstate = get_state_rust(state);
+
+ match rstate.stroke_opacity {
+ Some(StrokeOpacity(Opacity::Specified(opacity))) => opacity_to_u8(opacity),
+ _ => 255,
+ }
}
pub fn get_fill<'a>(state: *const RsvgState) -> Option<&'a PaintServer> {
@@ -892,6 +902,13 @@ make_property!(
"bevel" => Bevel,
);
+make_property!(
+ StrokeOpacity,
+ default: Opacity::Specified(1.0),
+ inherits_automatically: true,
+ newtype_from_str: Opacity
+);
+
make_property!(
StrokeMiterlimit,
default: 4f64,
@@ -1164,6 +1181,7 @@ pub extern "C" fn rsvg_state_rust_inherit_run(
);
inherit(inherit_fn, &mut dst.stroke_line_cap, &src.stroke_line_cap);
inherit(inherit_fn, &mut dst.stroke_line_join, &src.stroke_line_join);
+ inherit(inherit_fn, &mut dst.stroke_opacity, &src.stroke_opacity);
inherit(
inherit_fn,
&mut dst.stroke_miterlimit,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]