[librsvg: 10/15] state: move display and visibility to rust
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 10/15] state: move display and visibility to rust
- Date: Sun, 8 Apr 2018 00:01:22 +0000 (UTC)
commit 299c75f6c5419ee8a975e28fe8a200d232429a55
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Apr 7 14:12:10 2018 +0200
state: move display and visibility to rust
librsvg/rsvg-base.c | 2 +-
librsvg/rsvg-styles.c | 29 -------------------
librsvg/rsvg-styles.h | 6 ++--
rsvg_internals/src/lib.rs | 1 +
rsvg_internals/src/state.rs | 68 ++++++++++++++++++++++++++++++++++++++++++++-
5 files changed, 72 insertions(+), 34 deletions(-)
---
diff --git a/librsvg/rsvg-base.c b/librsvg/rsvg-base.c
index 0d460280..6081c67a 100644
--- a/librsvg/rsvg-base.c
+++ b/librsvg/rsvg-base.c
@@ -510,7 +510,7 @@ rsvg_drawing_ctx_draw_node_from_stack (RsvgDrawingCtx *ctx,
state = rsvg_node_get_state (node);
- if (state->visible) {
+ if (rsvg_state_is_visible (state)) {
rsvg_drawing_ctx_state_push (ctx);
rsvg_node_draw (node, ctx, dominate, clipping);
rsvg_drawing_ctx_state_pop (ctx);
diff --git a/librsvg/rsvg-styles.c b/librsvg/rsvg-styles.c
index 3d7814d2..2fc5efa0 100644
--- a/librsvg/rsvg-styles.c
+++ b/librsvg/rsvg-styles.c
@@ -121,7 +121,6 @@ rsvg_state_init (RsvgState * state)
state->font_stretch = PANGO_STRETCH_NORMAL;
state->text_dir = PANGO_DIRECTION_LTR;
state->text_gravity = PANGO_GRAVITY_SOUTH;
- state->visible = TRUE;
state->cond_true = TRUE;
state->filter = NULL;
state->clip_path = NULL;
@@ -138,7 +137,6 @@ rsvg_state_init (RsvgState * state)
state->has_stroke_opacity = FALSE;
state->has_dash = FALSE;
state->has_dashoffset = FALSE;
- state->has_visible = FALSE;
state->has_cond = FALSE;
state->has_stop_color = FALSE;
state->has_stop_opacity = FALSE;
@@ -336,9 +334,6 @@ rsvg_state_inherit_run (RsvgState * dst, const RsvgState * src,
dst->endMarker = g_strdup (src->endMarker);
}
- if (function (dst->has_visible, src->has_visible))
- dst->visible = src->visible;
-
if (function (dst->has_dash, src->has_dash)) {
if (dst->dash) {
rsvg_stroke_dasharray_free (dst->dash);
@@ -590,30 +585,6 @@ rsvg_parse_style_pair (RsvgState *state,
}
break;
- case RSVG_ATTRIBUTE_DISPLAY:
- {
- state->has_visible = TRUE;
- if (g_str_equal (value, "none"))
- state->visible = FALSE;
- else if (!g_str_equal (value, "inherit"))
- state->visible = TRUE;
- else
- state->has_visible = FALSE;
- }
- break;
-
- case RSVG_ATTRIBUTE_VISIBILITY:
- {
- state->has_visible = TRUE;
- if (g_str_equal (value, "visible"))
- state->visible = TRUE;
- else if (!g_str_equal (value, "inherit"))
- state->visible = FALSE; /* collapse or hidden */
- else
- state->has_visible = FALSE;
- }
- break;
-
case RSVG_ATTRIBUTE_FILL:
{
RsvgPaintServer *fill = state->fill;
diff --git a/librsvg/rsvg-styles.h b/librsvg/rsvg-styles.h
index 49333d7b..07e15ff8 100644
--- a/librsvg/rsvg-styles.h
+++ b/librsvg/rsvg-styles.h
@@ -83,9 +83,6 @@ struct _RsvgState {
RsvgOpacitySpec stop_opacity;
gboolean has_stop_opacity;
- gboolean visible;
- gboolean has_visible;
-
gboolean has_cond;
gboolean cond_true;
@@ -159,6 +156,9 @@ cairo_matrix_t rsvg_state_get_affine (const RsvgState *state);
G_GNUC_INTERNAL
void rsvg_state_set_affine (RsvgState *state, cairo_matrix_t affine);
+G_GNUC_INTERNAL
+gboolean rsvg_state_is_visible (RsvgState *state);
+
G_GNUC_INTERNAL
const char *rsvg_state_get_clip_path (RsvgState *state);
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index 7fcbe8c0..764b4596 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -125,6 +125,7 @@ pub use shapes::{
};
pub use state::{
+ rsvg_state_is_visible,
rsvg_state_reconstruct,
rsvg_state_rust_clone,
rsvg_state_rust_free,
diff --git a/rsvg_internals/src/state.rs b/rsvg_internals/src/state.rs
index ae99a4af..c67d5ce3 100644
--- a/rsvg_internals/src/state.rs
+++ b/rsvg_internals/src/state.rs
@@ -43,6 +43,7 @@ pub struct State {
pub font_size: Option<FontSize>,
pub font_style: Option<FontStyle>,
pub font_variant: Option<FontVariant>,
+ pub display: Option<Display>,
pub enable_background: Option<EnableBackground>,
pub letter_spacing: Option<LetterSpacing>,
pub overflow: Option<Overflow>,
@@ -55,6 +56,7 @@ pub struct State {
pub text_decoration: Option<TextDecoration>,
pub text_rendering: Option<TextRendering>,
pub unicode_bidi: Option<UnicodeBidi>,
+ pub visibility: Option<Visibility>,
pub xml_lang: Option<XmlLang>,
pub xml_space: Option<XmlSpace>,
}
@@ -73,6 +75,7 @@ impl State {
font_size: Default::default(),
font_style: Default::default(),
font_variant: Default::default(),
+ display: Default::default(),
enable_background: Default::default(),
letter_spacing: Default::default(),
overflow: Default::default(),
@@ -84,8 +87,9 @@ impl State {
text_anchor: Default::default(),
text_decoration: Default::default(),
text_rendering: Default::default(),
- xml_lang: Default::default(),
unicode_bidi: Default::default(),
+ visibility: Default::default(),
+ xml_lang: Default::default(),
xml_space: Default::default(),
}
}
@@ -125,6 +129,10 @@ impl State {
self.font_variant = parse_property(value, ())?;
}
+ Attribute::Display => {
+ self.display = parse_property(value, ())?;
+ }
+
Attribute::EnableBackground => {
self.enable_background = parse_property(value, ())?;
}
@@ -173,6 +181,10 @@ impl State {
self.unicode_bidi = parse_property(value, ())?;
}
+ Attribute::Visibility => {
+ self.visibility = parse_property(value, ())?;
+ }
+
Attribute::XmlLang => {
// xml:lang is not a property; it is a non-presentation attribute and as such
// cannot have the "inherit" value. So, we don't call parse_property() for it,
@@ -298,6 +310,17 @@ pub fn is_overflow(state: *const RsvgState) -> bool {
}
}
+pub fn is_visible(state: *const RsvgState) -> bool {
+ let rstate = get_state_rust(state);
+
+ match (rstate.display, rstate.visibility) {
+ (None, None) => true,
+ (Some(Display::None), _) => false,
+ (_, Some(Visibility::Visible)) => true,
+ _ => false,
+ }
+}
+
pub fn get_cond_true(state: *const RsvgState) -> bool {
unsafe { from_glib(rsvg_state_get_cond_true(state)) }
}
@@ -544,6 +567,31 @@ make_property!(
"small-caps" => SmallCaps,
);
+make_property!(
+ Display,
+ default: Inline,
+ inherits_automatically: true,
+
+ identifiers:
+ "inline" => Inline,
+ "block" => Block,
+ "list-item" => ListItem,
+ "run-in" => RunIn,
+ "compact" => Compact,
+ "marker" => Marker,
+ "table" => Table,
+ "inline-table" => InlineTable,
+ "table-row-group" => TableRowGroup,
+ "table-header-group" => TableHeaderGroup,
+ "table-footer-group" => TableFooterGroup,
+ "table-row" => TableRow,
+ "table-column-group" => TableColumnGroup,
+ "table-column" => TableColumn,
+ "table-cell" => TableCell,
+ "table-caption" => TableCaption,
+ "none" => None,
+);
+
make_property!(
EnableBackground,
default: Accumulate,
@@ -696,6 +744,17 @@ make_property!(
"bidi-override" => Override,
);
+make_property!(
+ Visibility,
+ default: Visible,
+ inherits_automatically: true,
+
+ identifiers:
+ "visible" => Visible,
+ "hidden" => Hidden,
+ "collapse" => Collapse,
+);
+
make_property!(
XmlLang,
default: "C".to_string(),
@@ -723,6 +782,11 @@ pub extern "C" fn rsvg_state_reconstruct(state: *mut RsvgState, raw_node: *const
reconstruct(state, node);
}
+#[no_mangle]
+pub extern "C" fn rsvg_state_is_visible(state: *const RsvgState) -> glib_sys::gboolean {
+ is_visible(state).to_glib()
+}
+
// Rust State API for consumption from C ----------------------------------------
#[no_mangle]
@@ -805,6 +869,7 @@ pub extern "C" fn rsvg_state_rust_inherit_run(
inherit(inherit_fn, &mut dst.font_size, &src.font_size);
inherit(inherit_fn, &mut dst.font_style, &src.font_style);
inherit(inherit_fn, &mut dst.font_variant, &src.font_variant);
+ inherit(inherit_fn, &mut dst.display, &src.display);
inherit(inherit_fn, &mut dst.letter_spacing, &src.letter_spacing);
inherit(inherit_fn, &mut dst.overflow, &src.overflow);
inherit(inherit_fn, &mut dst.shape_rendering, &src.shape_rendering);
@@ -820,6 +885,7 @@ pub extern "C" fn rsvg_state_rust_inherit_run(
inherit(inherit_fn, &mut dst.text_decoration, &src.text_decoration);
inherit(inherit_fn, &mut dst.text_rendering, &src.text_rendering);
inherit(inherit_fn, &mut dst.unicode_bidi, &src.unicode_bidi);
+ inherit(inherit_fn, &mut dst.visibility, &src.visibility);
inherit(inherit_fn, &mut dst.xml_lang, &src.xml_lang);
inherit(inherit_fn, &mut dst.xml_space, &src.xml_space);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]