[librsvg: 7/22] Make LetterSpacing not a newtype



commit 00dcc1de5b3f5f2a7c58a325035d2cc6121ac12c
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Jun 25 18:06:04 2020 -0500

    Make LetterSpacing not a newtype

 rsvg_internals/src/font_props.rs    | 38 ++++++++++++++++++-------------------
 rsvg_internals/src/property_defs.rs |  7 +++----
 rsvg_internals/src/text.rs          |  2 +-
 3 files changed, 23 insertions(+), 24 deletions(-)
---
diff --git a/rsvg_internals/src/font_props.rs b/rsvg_internals/src/font_props.rs
index b6b90fa7..3caab0a7 100644
--- a/rsvg_internals/src/font_props.rs
+++ b/rsvg_internals/src/font_props.rs
@@ -196,26 +196,26 @@ impl FontWeight {
 
 // https://www.w3.org/TR/css-text-3/#letter-spacing-property
 #[derive(Debug, Copy, Clone, PartialEq)]
-pub enum LetterSpacingSpec {
+pub enum LetterSpacing {
     Normal,
     Value(Length<Horizontal>),
 }
 
-impl LetterSpacingSpec {
+impl LetterSpacing {
     pub fn value(&self) -> Length<Horizontal> {
         match self {
-            LetterSpacingSpec::Value(s) => *s,
+            LetterSpacing::Value(s) => *s,
             _ => unreachable!(),
         }
     }
 
     pub fn compute(&self) -> Self {
         let spacing = match self {
-            LetterSpacingSpec::Normal => Length::<Horizontal>::new(0.0, LengthUnit::Px),
-            LetterSpacingSpec::Value(s) => *s,
+            LetterSpacing::Normal => Length::<Horizontal>::new(0.0, LengthUnit::Px),
+            LetterSpacing::Value(s) => *s,
         };
 
-        LetterSpacingSpec::Value(spacing)
+        LetterSpacing::Value(spacing)
     }
 
     pub fn normalize(&self, values: &ComputedValues, params: &ViewParams) -> f64 {
@@ -223,15 +223,15 @@ impl LetterSpacingSpec {
     }
 }
 
-impl Parse for LetterSpacingSpec {
-    fn parse<'i>(parser: &mut Parser<'i, '_>) -> Result<LetterSpacingSpec, ParseError<'i>> {
+impl Parse for LetterSpacing {
+    fn parse<'i>(parser: &mut Parser<'i, '_>) -> Result<LetterSpacing, ParseError<'i>> {
         parser
             .try_parse(|p| Length::<Horizontal>::parse(p))
-            .and_then(|l| Ok(LetterSpacingSpec::Value(l)))
+            .and_then(|l| Ok(LetterSpacing::Value(l)))
             .or_else(|_| {
                 Ok(parse_identifiers!(
                     parser,
-                    "normal" => LetterSpacingSpec::Normal,
+                    "normal" => LetterSpacing::Normal,
                 )?)
             })
     }
@@ -419,12 +419,12 @@ mod tests {
     #[test]
     fn parses_letter_spacing() {
         assert_eq!(
-            <LetterSpacingSpec as Parse>::parse_str("normal"),
-            Ok(LetterSpacingSpec::Normal)
+            <LetterSpacing as Parse>::parse_str("normal"),
+            Ok(LetterSpacing::Normal)
         );
         assert_eq!(
-            <LetterSpacingSpec as Parse>::parse_str("10em"),
-            Ok(LetterSpacingSpec::Value(Length::<Horizontal>::new(
+            <LetterSpacing as Parse>::parse_str("10em"),
+            Ok(LetterSpacing::Value(Length::<Horizontal>::new(
                 10.0,
                 LengthUnit::Em,
             )))
@@ -434,15 +434,15 @@ mod tests {
     #[test]
     fn computes_letter_spacing() {
         assert_eq!(
-            <LetterSpacingSpec as Parse>::parse_str("normal").map(|s| s.compute()),
-            Ok(LetterSpacingSpec::Value(Length::<Horizontal>::new(
+            <LetterSpacing as Parse>::parse_str("normal").map(|s| s.compute()),
+            Ok(LetterSpacing::Value(Length::<Horizontal>::new(
                 0.0,
                 LengthUnit::Px,
             )))
         );
         assert_eq!(
-            <LetterSpacingSpec as Parse>::parse_str("10em").map(|s| s.compute()),
-            Ok(LetterSpacingSpec::Value(Length::<Horizontal>::new(
+            <LetterSpacing as Parse>::parse_str("10em").map(|s| s.compute()),
+            Ok(LetterSpacing::Value(Length::<Horizontal>::new(
                 10.0,
                 LengthUnit::Em,
             )))
@@ -451,7 +451,7 @@ mod tests {
 
     #[test]
     fn detects_invalid_invalid_letter_spacing() {
-        assert!(LetterSpacingSpec::parse_str("furlong").is_err());
+        assert!(LetterSpacing::parse_str("furlong").is_err());
     }
 
     #[test]
diff --git a/rsvg_internals/src/property_defs.rs b/rsvg_internals/src/property_defs.rs
index 387dc4aa..3fcc6b7b 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::{FontSize, FontWeight, LetterSpacingSpec, LineHeightSpec, MultiFontFamily};
+use crate::font_props::{FontSize, FontWeight, LetterSpacing, LineHeightSpec, MultiFontFamily};
 use crate::iri::IRI;
 use crate::length::*;
 use crate::paint_server::PaintServer;
@@ -325,8 +325,7 @@ make_property!(
 make_property!(
     ComputedValues,
     LetterSpacing,
-    default: LetterSpacingSpec::Normal,
-    newtype_parse: LetterSpacingSpec,
+    default: LetterSpacing::Normal,
     property_impl: {
         impl Property<ComputedValues> for LetterSpacing {
             fn inherits_automatically() -> bool {
@@ -334,7 +333,7 @@ make_property!(
             }
 
             fn compute(&self, _v: &ComputedValues) -> Self {
-                LetterSpacing(self.0.compute())
+                self.compute()
             }
         }
     }
diff --git a/rsvg_internals/src/text.rs b/rsvg_internals/src/text.rs
index 42124c58..50a3c7db 100644
--- a/rsvg_internals/src/text.rs
+++ b/rsvg_internals/src/text.rs
@@ -990,7 +990,7 @@ fn create_pango_layout(
 
     attr_list.insert(
         pango::Attribute::new_letter_spacing(to_pango_units(
-            values.letter_spacing().0.normalize(values, &params),
+            values.letter_spacing().normalize(values, &params),
         ))
         .unwrap(),
     );


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]