[librsvg: 9/15] state: move clip rule to rust
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 9/15] state: move clip rule to rust
- Date: Sun, 8 Apr 2018 00:01:17 +0000 (UTC)
commit 6d8ee26f7dae27560d848783899dcc68d67eebf9
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Apr 7 12:43:22 2018 +0200
state: move clip rule to rust
librsvg/rsvg-styles.c | 22 ----------------------
librsvg/rsvg-styles.h | 5 -----
rsvg_internals/src/draw.rs | 16 ++++++++++++----
rsvg_internals/src/state.rs | 22 +++++++++++++++++-----
4 files changed, 29 insertions(+), 36 deletions(-)
---
diff --git a/librsvg/rsvg-styles.c b/librsvg/rsvg-styles.c
index bc031d2d..3d7814d2 100644
--- a/librsvg/rsvg-styles.c
+++ b/librsvg/rsvg-styles.c
@@ -114,7 +114,6 @@ rsvg_state_init (RsvgState * state)
state->stop_color.kind = RSVG_CSS_COLOR_SPEC_INHERIT;
state->stop_opacity.kind = RSVG_OPACITY_INHERIT;
- state->clip_rule = CAIRO_FILL_RULE_WINDING;
state->flood_color = 0;
state->flood_opacity = 255;
@@ -135,7 +134,6 @@ rsvg_state_init (RsvgState * state)
state->has_flood_opacity = FALSE;
state->has_fill_server = FALSE;
state->has_fill_opacity = FALSE;
- state->has_clip_rule = FALSE;
state->has_stroke_server = FALSE;
state->has_stroke_opacity = FALSE;
state->has_dash = FALSE;
@@ -295,8 +293,6 @@ rsvg_state_inherit_run (RsvgState * dst, const RsvgState * src,
}
if (function (dst->has_fill_opacity, src->has_fill_opacity))
dst->fill_opacity = src->fill_opacity;
- if (function (dst->has_clip_rule, src->has_clip_rule))
- dst->clip_rule = src->clip_rule;
if (function (dst->has_stroke_server, src->has_stroke_server)) {
rsvg_paint_server_ref (src->stroke);
if (dst->stroke)
@@ -643,18 +639,6 @@ rsvg_parse_style_pair (RsvgState *state,
}
break;
- case RSVG_ATTRIBUTE_CLIP_RULE:
- {
- state->has_clip_rule = TRUE;
- if (g_str_equal (value, "nonzero"))
- state->clip_rule = CAIRO_FILL_RULE_WINDING;
- else if (g_str_equal (value, "evenodd"))
- state->clip_rule = CAIRO_FILL_RULE_EVEN_ODD;
- else
- state->has_clip_rule = FALSE;
- }
- break;
-
case RSVG_ATTRIBUTE_STROKE:
{
RsvgPaintServer *stroke = state->stroke;
@@ -1537,12 +1521,6 @@ rsvg_state_get_font_stretch (RsvgState *state)
return state->font_stretch;
}
-cairo_fill_rule_t
-rsvg_state_get_clip_rule (RsvgState *state)
-{
- return state->clip_rule;
-}
-
RsvgPaintServer *
rsvg_state_get_fill (RsvgState *state)
{
diff --git a/librsvg/rsvg-styles.h b/librsvg/rsvg-styles.h
index 8e70136a..49333d7b 100644
--- a/librsvg/rsvg-styles.h
+++ b/librsvg/rsvg-styles.h
@@ -60,8 +60,6 @@ struct _RsvgState {
gboolean has_fill_server;
guint8 fill_opacity; /* 0..255 */
gboolean has_fill_opacity;
- cairo_fill_rule_t clip_rule;
- gboolean has_clip_rule;
RsvgPaintServer *stroke;
gboolean has_stroke_server;
@@ -212,9 +210,6 @@ PangoWeight rsvg_state_get_font_weight (RsvgState *state);
G_GNUC_INTERNAL
PangoStretch rsvg_state_get_font_stretch (RsvgState *state);
-G_GNUC_INTERNAL
-cairo_fill_rule_t rsvg_state_get_clip_rule (RsvgState *state);
-
G_GNUC_INTERNAL
RsvgPaintServer *rsvg_state_get_fill (RsvgState *state);
diff --git a/rsvg_internals/src/draw.rs b/rsvg_internals/src/draw.rs
index b148b7fd..88c8da83 100644
--- a/rsvg_internals/src/draw.rs
+++ b/rsvg_internals/src/draw.rs
@@ -12,6 +12,7 @@ use paint_server;
use path_builder::PathBuilder;
use state::{
self,
+ ClipRule,
CompOp,
FillRule,
RsvgState,
@@ -38,11 +39,9 @@ pub fn draw_path_builder(draw_ctx: *mut RsvgDrawingCtx, builder: &PathBuilder, c
builder.to_cairo(&cr);
if clipping {
- cr.set_fill_rule(state::get_clip_rule(state));
+ cr.set_fill_rule(cairo::FillRule::from(rstate.clip_rule.unwrap_or_default()));
} else {
- cr.set_fill_rule(cairo::FillRule::from(
- state::get_state_rust(state).fill_rule.unwrap_or_default(),
- ));
+ cr.set_fill_rule(cairo::FillRule::from(rstate.fill_rule.unwrap_or_default()));
stroke_and_fill(&cr, draw_ctx);
@@ -154,6 +153,15 @@ impl From<CompOp> for cairo::Operator {
}
}
+impl From<ClipRule> for cairo::FillRule {
+ fn from(c: ClipRule) -> cairo::FillRule {
+ match c {
+ ClipRule::NonZero => cairo::FillRule::Winding,
+ ClipRule::EvenOdd => cairo::FillRule::EvenOdd,
+ }
+ }
+}
+
impl From<FillRule> for cairo::FillRule {
fn from(f: FillRule) -> cairo::FillRule {
match f {
diff --git a/rsvg_internals/src/state.rs b/rsvg_internals/src/state.rs
index 39c78a97..ae99a4af 100644
--- a/rsvg_internals/src/state.rs
+++ b/rsvg_internals/src/state.rs
@@ -36,6 +36,7 @@ pub struct State {
pub affine: cairo::Matrix,
pub baseline_shift: Option<BaselineShift>,
+ pub clip_rule: Option<ClipRule>,
pub comp_op: Option<CompOp>,
pub fill_rule: Option<FillRule>,
pub font_family: Option<FontFamily>,
@@ -65,6 +66,7 @@ impl State {
// please keep these sorted
baseline_shift: Default::default(),
+ clip_rule: Default::default(),
comp_op: Default::default(),
fill_rule: Default::default(),
font_family: Default::default(),
@@ -95,6 +97,10 @@ impl State {
self.baseline_shift = parse_property(value, ())?;
}
+ Attribute::ClipRule => {
+ self.clip_rule = parse_property(value, ())?;
+ }
+
Attribute::CompOp => {
self.comp_op = parse_property(value, ())?;
}
@@ -227,7 +233,6 @@ extern "C" {
fn rsvg_state_get_text_gravity(state: *const RsvgState) -> pango_sys::PangoGravity;
fn rsvg_state_get_font_weight(state: *const RsvgState) -> pango_sys::PangoWeight;
fn rsvg_state_get_font_stretch(state: *const RsvgState) -> pango_sys::PangoStretch;
- fn rsvg_state_get_clip_rule(state: *const RsvgState) -> cairo::FillRule;
fn rsvg_state_get_fill(state: *const RsvgState) -> *const PaintServer;
fn rsvg_state_get_fill_opacity(state: *const RsvgState) -> u8;
@@ -379,10 +384,6 @@ pub fn get_font_stretch(state: *const RsvgState) -> pango::Stretch {
unsafe { from_glib(rsvg_state_get_font_stretch(state)) }
}
-pub fn get_clip_rule(state: *const RsvgState) -> cairo::FillRule {
- unsafe { rsvg_state_get_clip_rule(state) }
-}
-
pub fn get_fill<'a>(state: *const RsvgState) -> Option<&'a PaintServer> {
unsafe {
let ps = rsvg_state_get_fill(state);
@@ -447,6 +448,16 @@ impl Parse for BaselineShift {
}
}
+make_property!(
+ ClipRule,
+ default: NonZero,
+ inherits_automatically: true,
+
+ identifiers:
+ "nonzero" => NonZero,
+ "evenodd" => EvenOdd,
+);
+
make_property!(
CompOp,
default: SrcOver,
@@ -788,6 +799,7 @@ pub extern "C" fn rsvg_state_rust_inherit_run(
// please keep these sorted
inherit(inherit_fn, &mut dst.baseline_shift, &src.baseline_shift);
+ inherit(inherit_fn, &mut dst.clip_rule, &src.clip_rule);
inherit(inherit_fn, &mut dst.fill_rule, &src.fill_rule);
inherit(inherit_fn, &mut dst.font_family, &src.font_family);
inherit(inherit_fn, &mut dst.font_size, &src.font_size);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]