[librsvg: 18/22] Extract separate FontSpec struct from the Font::Spec variant
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 18/22] Extract separate FontSpec struct from the Font::Spec variant
- Date: Wed, 1 Jul 2020 00:04:42 +0000 (UTC)
commit 24cfc8832e693386d3d18cb5225b4ff5752e9746
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Jun 30 17:11:00 2020 -0500
Extract separate FontSpec struct from the Font::Spec variant
We'll use this to reduce system fonts to a concrete font.
rsvg_internals/src/font_props.rs | 33 ++++++++++++++++++---------------
rsvg_internals/src/property_defs.rs | 10 +---------
2 files changed, 19 insertions(+), 24 deletions(-)
---
diff --git a/rsvg_internals/src/font_props.rs b/rsvg_internals/src/font_props.rs
index 61d9835a..d3a44f09 100644
--- a/rsvg_internals/src/font_props.rs
+++ b/rsvg_internals/src/font_props.rs
@@ -21,15 +21,18 @@ pub enum Font {
MessageBox,
SmallCaption,
StatusBar,
- Spec {
- style: FontStyle,
- variant: FontVariant,
- weight: FontWeight,
- stretch: FontStretch,
- size: FontSize,
- line_height: LineHeight,
- family: FontFamily,
- }
+ Spec(FontSpec),
+}
+
+#[derive(Debug, Default, Clone, PartialEq)]
+pub struct FontSpec {
+ pub style: FontStyle,
+ pub variant: FontVariant,
+ pub weight: FontWeight,
+ pub stretch: FontStretch,
+ pub size: FontSize,
+ pub line_height: LineHeight,
+ pub family: FontFamily,
}
impl Parse for Font {
@@ -102,7 +105,7 @@ impl Parse for Font {
let family = FontFamily::parse(parser)?;
- Ok(Font::Spec {
+ Ok(Font::Spec(FontSpec {
style: style.unwrap_or_default(),
variant: variant_caps.unwrap_or_default(),
weight: weight.unwrap_or_default(),
@@ -110,7 +113,7 @@ impl Parse for Font {
size,
line_height: line_height.unwrap_or_default(),
family,
- })
+ }))
}
}
@@ -478,7 +481,7 @@ mod tests {
assert_eq!(
Font::parse_str("italic bold 12px sans").unwrap(),
- Font::Spec {
+ Font::Spec(FontSpec {
style: FontStyle::Italic,
variant: Default::default(),
weight: FontWeight::Bold,
@@ -486,12 +489,12 @@ mod tests {
size: FontSize::Value(Length::new(12.0, LengthUnit::Px)),
line_height: Default::default(),
family: FontFamily("sans".to_string()),
- },
+ }),
);
assert_eq!(
Font::parse_str("bold 14cm/2 serif").unwrap(),
- Font::Spec {
+ Font::Spec(FontSpec {
style: Default::default(),
variant: Default::default(),
weight: FontWeight::Bold,
@@ -499,7 +502,7 @@ mod tests {
size: FontSize::Value(Length::new(14.0, LengthUnit::Cm)),
line_height: LineHeight::Number(2.0),
family: FontFamily("serif".to_string()),
- },
+ }),
);
}
diff --git a/rsvg_internals/src/property_defs.rs b/rsvg_internals/src/property_defs.rs
index 8ea2e338..1dda3063 100644
--- a/rsvg_internals/src/property_defs.rs
+++ b/rsvg_internals/src/property_defs.rs
@@ -234,15 +234,7 @@ make_property!(
make_property!(
ComputedValues,
Font,
- default: Font::Spec {
- style: Default::default(),
- variant: Default::default(),
- weight: Default::default(),
- stretch: Default::default(),
- size: Default::default(),
- line_height: Default::default(),
- family: Default::default(),
- },
+ default: Font::Spec(Default::default()),
inherits_automatically: true,
);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]