[librsvg: 11/15] state: move font stretch to rust
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 11/15] state: move font stretch to rust
- Date: Sun, 8 Apr 2018 00:01:27 +0000 (UTC)
commit 5c166352d4ca7fea33d50d4714a5e43253d60ec0
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Apr 7 19:07:05 2018 +0200
state: move font stretch to rust
librsvg/rsvg-css.c | 31 -------------------------------
librsvg/rsvg-css.h | 2 --
librsvg/rsvg-styles.c | 16 ----------------
librsvg/rsvg-styles.h | 5 -----
rsvg_internals/src/state.rs | 31 ++++++++++++++++++++++++++-----
rsvg_internals/src/text.rs | 24 +++++++++++++++++++++++-
6 files changed, 49 insertions(+), 60 deletions(-)
---
diff --git a/librsvg/rsvg-css.c b/librsvg/rsvg-css.c
index 476c5a54..21d59c47 100644
--- a/librsvg/rsvg-css.c
+++ b/librsvg/rsvg-css.c
@@ -100,37 +100,6 @@ rsvg_css_parse_font_weight (const char *str, gboolean * inherit)
return PANGO_WEIGHT_NORMAL;
}
-PangoStretch
-rsvg_css_parse_font_stretch (const char *str, gboolean * inherit)
-{
- SETINHERIT ();
-
- if (str) {
- if (!strcmp (str, "ultra-condensed"))
- return PANGO_STRETCH_ULTRA_CONDENSED;
- else if (!strcmp (str, "extra-condensed"))
- return PANGO_STRETCH_EXTRA_CONDENSED;
- else if (!strcmp (str, "condensed") || !strcmp (str, "narrower")) /* narrower not quite
correct */
- return PANGO_STRETCH_CONDENSED;
- else if (!strcmp (str, "semi-condensed"))
- return PANGO_STRETCH_SEMI_CONDENSED;
- else if (!strcmp (str, "semi-expanded"))
- return PANGO_STRETCH_SEMI_EXPANDED;
- else if (!strcmp (str, "expanded") || !strcmp (str, "wider")) /* wider not quite correct */
- return PANGO_STRETCH_EXPANDED;
- else if (!strcmp (str, "extra-expanded"))
- return PANGO_STRETCH_EXTRA_EXPANDED;
- else if (!strcmp (str, "ultra-expanded"))
- return PANGO_STRETCH_ULTRA_EXPANDED;
- else if (!strcmp (str, "inherit")) {
- UNSETINHERIT ();
- return PANGO_STRETCH_NORMAL;
- }
- }
- UNSETINHERIT ();
- return PANGO_STRETCH_NORMAL;
-}
-
static void
rsvg_xml_noerror (void *data, xmlErrorPtr error)
{
diff --git a/librsvg/rsvg-css.h b/librsvg/rsvg-css.h
index e7502889..1913f718 100644
--- a/librsvg/rsvg-css.h
+++ b/librsvg/rsvg-css.h
@@ -91,8 +91,6 @@ RsvgOpacitySpec rsvg_css_parse_opacity (const char *str);
G_GNUC_INTERNAL
PangoWeight rsvg_css_parse_font_weight (const char *str, gboolean * inherit);
-G_GNUC_INTERNAL
-PangoStretch rsvg_css_parse_font_stretch (const char *str, gboolean * inherit);
/* Implemented in rust/src/parsers.rs */
G_GNUC_INTERNAL
diff --git a/librsvg/rsvg-styles.c b/librsvg/rsvg-styles.c
index 2fc5efa0..57b68a48 100644
--- a/librsvg/rsvg-styles.c
+++ b/librsvg/rsvg-styles.c
@@ -118,7 +118,6 @@ rsvg_state_init (RsvgState * state)
state->flood_opacity = 255;
state->font_weight = PANGO_WEIGHT_NORMAL;
- state->font_stretch = PANGO_STRETCH_NORMAL;
state->text_dir = PANGO_DIRECTION_LTR;
state->text_gravity = PANGO_GRAVITY_SOUTH;
state->cond_true = TRUE;
@@ -141,7 +140,6 @@ rsvg_state_init (RsvgState * state)
state->has_stop_color = FALSE;
state->has_stop_opacity = FALSE;
state->has_font_weight = FALSE;
- state->has_font_stretch = FALSE;
state->has_text_dir = FALSE;
state->has_text_gravity = FALSE;
state->has_startMarker = FALSE;
@@ -315,8 +313,6 @@ rsvg_state_inherit_run (RsvgState * dst, const RsvgState * src,
dst->cond_true = src->cond_true;
if (function (dst->has_font_weight, src->has_font_weight))
dst->font_weight = src->font_weight;
- if (function (dst->has_font_stretch, src->has_font_stretch))
- dst->font_stretch = src->font_stretch;
if (function (dst->has_text_dir, src->has_text_dir))
dst->text_dir = src->text_dir;
if (function (dst->has_text_gravity, src->has_text_gravity))
@@ -643,12 +639,6 @@ rsvg_parse_style_pair (RsvgState *state,
}
break;
- case RSVG_ATTRIBUTE_FONT_STRETCH:
- {
- state->font_stretch = rsvg_css_parse_font_stretch (value, &state->has_font_stretch);
- }
- break;
-
case RSVG_ATTRIBUTE_DIRECTION:
{
state->has_text_dir = TRUE;
@@ -1486,12 +1476,6 @@ rsvg_state_get_font_weight (RsvgState *state)
return state->font_weight;
}
-PangoStretch
-rsvg_state_get_font_stretch (RsvgState *state)
-{
- return state->font_stretch;
-}
-
RsvgPaintServer *
rsvg_state_get_fill (RsvgState *state)
{
diff --git a/librsvg/rsvg-styles.h b/librsvg/rsvg-styles.h
index 07e15ff8..664640fc 100644
--- a/librsvg/rsvg-styles.h
+++ b/librsvg/rsvg-styles.h
@@ -68,8 +68,6 @@ struct _RsvgState {
PangoWeight font_weight;
gboolean has_font_weight;
- PangoStretch font_stretch;
- gboolean has_font_stretch;
PangoDirection text_dir;
gboolean has_text_dir;
PangoGravity text_gravity;
@@ -207,9 +205,6 @@ PangoGravity rsvg_state_get_text_gravity (RsvgState *state);
G_GNUC_INTERNAL
PangoWeight rsvg_state_get_font_weight (RsvgState *state);
-G_GNUC_INTERNAL
-PangoStretch rsvg_state_get_font_stretch (RsvgState *state);
-
G_GNUC_INTERNAL
RsvgPaintServer *rsvg_state_get_fill (RsvgState *state);
diff --git a/rsvg_internals/src/state.rs b/rsvg_internals/src/state.rs
index c67d5ce3..950d7a96 100644
--- a/rsvg_internals/src/state.rs
+++ b/rsvg_internals/src/state.rs
@@ -41,6 +41,7 @@ pub struct State {
pub fill_rule: Option<FillRule>,
pub font_family: Option<FontFamily>,
pub font_size: Option<FontSize>,
+ pub font_stretch: Option<FontStretch>,
pub font_style: Option<FontStyle>,
pub font_variant: Option<FontVariant>,
pub display: Option<Display>,
@@ -73,6 +74,7 @@ impl State {
fill_rule: Default::default(),
font_family: Default::default(),
font_size: Default::default(),
+ font_stretch: Default::default(),
font_style: Default::default(),
font_variant: Default::default(),
display: Default::default(),
@@ -121,6 +123,10 @@ impl State {
self.font_size = parse_property(value, LengthDir::Both)?;
}
+ Attribute::FontStretch => {
+ self.font_stretch = parse_property(value, ())?;
+ }
+
Attribute::FontStyle => {
self.font_style = parse_property(value, ())?;
}
@@ -244,7 +250,6 @@ extern "C" {
fn rsvg_state_get_text_dir(state: *const RsvgState) -> pango_sys::PangoDirection;
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_fill(state: *const RsvgState) -> *const PaintServer;
fn rsvg_state_get_fill_opacity(state: *const RsvgState) -> u8;
@@ -403,10 +408,6 @@ pub fn get_font_weight(state: *const RsvgState) -> pango::Weight {
unsafe { from_glib(rsvg_state_get_font_weight(state)) }
}
-pub fn get_font_stretch(state: *const RsvgState) -> pango::Stretch {
- unsafe { from_glib(rsvg_state_get_font_stretch(state)) }
-}
-
pub fn get_fill<'a>(state: *const RsvgState) -> Option<&'a PaintServer> {
unsafe {
let ps = rsvg_state_get_fill(state);
@@ -546,6 +547,25 @@ impl Parse for FontSize {
}
}
+make_property!(
+ FontStretch,
+ default: Normal,
+ inherits_automatically: true,
+
+ identifiers:
+ "normal" => Normal,
+ "wider" => Wider,
+ "narrower" => Narrower,
+ "ultra-condensed" => UltraCondensed,
+ "extra-condensed" => ExtraCondensed,
+ "condensed" => Condensed,
+ "semi-condensed" => SemiCondensed,
+ "semi-expanded" => SemiExpanded,
+ "expanded" => Expanded,
+ "extra-expanded" => ExtraExpanded,
+ "ultra-expanded" => UltraExpanded,
+);
+
make_property!(
FontStyle,
default: Normal,
@@ -867,6 +887,7 @@ pub extern "C" fn rsvg_state_rust_inherit_run(
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);
+ inherit(inherit_fn, &mut dst.font_stretch, &src.font_stretch);
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);
diff --git a/rsvg_internals/src/text.rs b/rsvg_internals/src/text.rs
index b117dadd..89ce2a46 100644
--- a/rsvg_internals/src/text.rs
+++ b/rsvg_internals/src/text.rs
@@ -24,6 +24,7 @@ use space::xml_space_normalize;
use state::{
self,
FontFamily,
+ FontStretch,
FontStyle,
FontVariant,
LetterSpacing,
@@ -411,6 +412,24 @@ impl From<FontVariant> for pango::Variant {
}
}
+impl From<FontStretch> for pango::Stretch {
+ fn from(s: FontStretch) -> pango::Stretch {
+ match s {
+ FontStretch::Normal => pango::Stretch::Normal,
+ FontStretch::Wider => pango::Stretch::Expanded, // not quite correct
+ FontStretch::Narrower => pango::Stretch::Condensed, // not quite correct
+ FontStretch::UltraCondensed => pango::Stretch::UltraCondensed,
+ FontStretch::ExtraCondensed => pango::Stretch::ExtraCondensed,
+ FontStretch::Condensed => pango::Stretch::Condensed,
+ FontStretch::SemiCondensed => pango::Stretch::SemiCondensed,
+ FontStretch::SemiExpanded => pango::Stretch::SemiExpanded,
+ FontStretch::Expanded => pango::Stretch::Expanded,
+ FontStretch::ExtraExpanded => pango::Stretch::ExtraExpanded,
+ FontStretch::UltraExpanded => pango::Stretch::UltraExpanded,
+ }
+ }
+}
+
fn create_pango_layout(draw_ctx: *const RsvgDrawingCtx, text: &str) -> pango::Layout {
let state = drawing_ctx::get_current_state(draw_ctx);
let rstate = state::get_state_rust(state);
@@ -447,7 +466,10 @@ fn create_pango_layout(draw_ctx: *const RsvgDrawingCtx, text: &str) -> pango::La
));
font_desc.set_weight(state::get_font_weight(state));
- font_desc.set_stretch(state::get_font_stretch(state));
+
+ font_desc.set_stretch(pango::Stretch::from(
+ rstate.font_stretch.unwrap_or_default(),
+ ));
let (_, dpi_y) = drawing_ctx::get_dpi(draw_ctx);
font_desc.set_size(to_pango_units(
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]