[librsvg: 12/22] Make LineHeight not a newtype
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 12/22] Make LineHeight not a newtype
- Date: Wed, 1 Jul 2020 00:04:05 +0000 (UTC)
commit 075bc2d9c3403db474de9fb288aa4cff8cf94425
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Jun 30 12:55:35 2020 -0500
Make LineHeight not a newtype
rsvg_internals/src/font_props.rs | 64 ++++++++++++++++++-------------------
rsvg_internals/src/property_defs.rs | 5 ++-
2 files changed, 34 insertions(+), 35 deletions(-)
---
diff --git a/rsvg_internals/src/font_props.rs b/rsvg_internals/src/font_props.rs
index 1ea52f90..3e232908 100644
--- a/rsvg_internals/src/font_props.rs
+++ b/rsvg_internals/src/font_props.rs
@@ -239,17 +239,17 @@ impl Parse for LetterSpacing {
// https://www.w3.org/TR/CSS2/visudet.html#propdef-line-height
#[derive(Debug, Copy, Clone, PartialEq)]
-pub enum LineHeightSpec {
+pub enum LineHeight {
Normal,
Number(f32),
Length(Length<Both>),
Percentage(f32),
}
-impl LineHeightSpec {
+impl LineHeight {
pub fn value(&self) -> Length<Both> {
match self {
- LineHeightSpec::Length(l) => *l,
+ LineHeight::Length(l) => *l,
_ => unreachable!(),
}
}
@@ -258,12 +258,12 @@ impl LineHeightSpec {
let font_size = values.font_size().value();
match *self {
- LineHeightSpec::Normal => LineHeightSpec::Length(font_size),
+ LineHeight::Normal => LineHeight::Length(font_size),
- LineHeightSpec::Number(f) |
- LineHeightSpec::Percentage(f) => LineHeightSpec::Length(Length::new(font_size.length * f64(f),
font_size.unit)),
+ LineHeight::Number(f) |
+ LineHeight::Percentage(f) => LineHeight::Length(Length::new(font_size.length * f64(f),
font_size.unit)),
- LineHeightSpec::Length(l) => LineHeightSpec::Length(l),
+ LineHeight::Length(l) => LineHeight::Length(l),
}
}
@@ -272,8 +272,8 @@ impl LineHeightSpec {
}
}
-impl Parse for LineHeightSpec {
- fn parse<'i>(parser: &mut Parser<'i, '_>) -> Result<LineHeightSpec, ParseError<'i>> {
+impl Parse for LineHeight {
+ fn parse<'i>(parser: &mut Parser<'i, '_>) -> Result<LineHeight, ParseError<'i>> {
let state = parser.state();
let loc = parser.current_source_location();
@@ -282,19 +282,19 @@ impl Parse for LineHeightSpec {
match token {
Token::Ident(ref cow) => {
if cow.eq_ignore_ascii_case("normal") {
- Ok(LineHeightSpec::Normal)
+ Ok(LineHeight::Normal)
} else {
Err(parser.new_basic_unexpected_token_error(token.clone()))?
}
}
- Token::Number { value, .. } => Ok(LineHeightSpec::Number(finite_f32(value).map_err(|e|
loc.new_custom_error(e))?)),
+ Token::Number { value, .. } => Ok(LineHeight::Number(finite_f32(value).map_err(|e|
loc.new_custom_error(e))?)),
- Token::Percentage { unit_value, .. } => Ok(LineHeightSpec::Percentage(unit_value)),
+ Token::Percentage { unit_value, .. } => Ok(LineHeight::Percentage(unit_value)),
Token::Dimension { .. } => {
parser.reset(&state);
- Ok(LineHeightSpec::Length(Length::<Both>::parse(parser)?))
+ Ok(LineHeight::Length(Length::<Both>::parse(parser)?))
}
_ => {
@@ -508,31 +508,31 @@ mod tests {
#[test]
fn parses_line_height() {
assert_eq!(
- <LineHeightSpec as Parse>::parse_str("normal"),
- Ok(LineHeightSpec::Normal),
+ <LineHeight as Parse>::parse_str("normal"),
+ Ok(LineHeight::Normal),
);
assert_eq!(
- <LineHeightSpec as Parse>::parse_str("2"),
- Ok(LineHeightSpec::Number(2.0)),
+ <LineHeight as Parse>::parse_str("2"),
+ Ok(LineHeight::Number(2.0)),
);
assert_eq!(
- <LineHeightSpec as Parse>::parse_str("2cm"),
- Ok(LineHeightSpec::Length(Length::new(2.0, LengthUnit::Cm))),
+ <LineHeight as Parse>::parse_str("2cm"),
+ Ok(LineHeight::Length(Length::new(2.0, LengthUnit::Cm))),
);
assert_eq!(
- <LineHeightSpec as Parse>::parse_str("150%"),
- Ok(LineHeightSpec::Percentage(1.5)),
+ <LineHeight as Parse>::parse_str("150%"),
+ Ok(LineHeight::Percentage(1.5)),
);
}
#[test]
fn detects_invalid_line_height() {
- assert!(<LineHeightSpec as Parse>::parse_str("").is_err());
- assert!(<LineHeightSpec as Parse>::parse_str("florp").is_err());
- assert!(<LineHeightSpec as Parse>::parse_str("3florp").is_err());
+ assert!(<LineHeight as Parse>::parse_str("").is_err());
+ assert!(<LineHeight as Parse>::parse_str("florp").is_err());
+ assert!(<LineHeight as Parse>::parse_str("3florp").is_err());
}
#[test]
@@ -546,23 +546,23 @@ mod tests {
specified.to_computed_values(&mut values);
assert_eq!(
- LineHeightSpec::Normal.compute(&values),
- LineHeightSpec::Length(Length::new(10.0, LengthUnit::Px)),
+ LineHeight::Normal.compute(&values),
+ LineHeight::Length(Length::new(10.0, LengthUnit::Px)),
);
assert_eq!(
- LineHeightSpec::Number(2.0).compute(&values),
- LineHeightSpec::Length(Length::new(20.0, LengthUnit::Px)),
+ LineHeight::Number(2.0).compute(&values),
+ LineHeight::Length(Length::new(20.0, LengthUnit::Px)),
);
assert_eq!(
- LineHeightSpec::Length(Length::new(3.0, LengthUnit::Cm)).compute(&values),
- LineHeightSpec::Length(Length::new(3.0, LengthUnit::Cm)),
+ LineHeight::Length(Length::new(3.0, LengthUnit::Cm)).compute(&values),
+ LineHeight::Length(Length::new(3.0, LengthUnit::Cm)),
);
assert_eq!(
- LineHeightSpec::parse_str("150%").unwrap().compute(&values),
- LineHeightSpec::Length(Length::new(15.0, LengthUnit::Px)),
+ LineHeight::parse_str("150%").unwrap().compute(&values),
+ LineHeight::Length(Length::new(15.0, LengthUnit::Px)),
);
}
}
diff --git a/rsvg_internals/src/property_defs.rs b/rsvg_internals/src/property_defs.rs
index d3389e11..4ca31a28 100644
--- a/rsvg_internals/src/property_defs.rs
+++ b/rsvg_internals/src/property_defs.rs
@@ -4,7 +4,7 @@ use cssparser::{Parser, Token};
use crate::dasharray::Dasharray;
use crate::error::*;
-use crate::font_props::{FontFamily, FontSize, FontWeight, LetterSpacing, LineHeightSpec};
+use crate::font_props::{FontFamily, FontSize, FontWeight, LetterSpacing, LineHeight};
use crate::iri::IRI;
use crate::length::*;
use crate::paint_server::PaintServer;
@@ -342,9 +342,8 @@ make_property!(
make_property!(
ComputedValues,
LineHeight,
- default: LineHeightSpec::Normal,
+ default: LineHeight::Normal,
inherits_automatically: true,
- newtype_parse: LineHeightSpec,
);
// https://www.w3.org/TR/SVG/filters.html#LightingColorProperty
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]