[librsvg: 10/22] Make FontFamily not a newtype
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 10/22] Make FontFamily not a newtype
- Date: Wed, 1 Jul 2020 00:03:54 +0000 (UTC)
commit 5a7fdb3158223ecaaa99dc643fb63c286c4ec806
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Jun 25 19:03:46 2020 -0500
Make FontFamily not a newtype
Also, rename MultiFontFamily to just FontFamily while we are at it.
rsvg_internals/src/font_props.rs | 38 +++++++++++++++++------------------
rsvg_internals/src/property_defs.rs | 5 ++---
rsvg_internals/src/property_macros.rs | 9 +++++++++
rsvg_internals/src/text.rs | 2 +-
4 files changed, 31 insertions(+), 23 deletions(-)
---
diff --git a/rsvg_internals/src/font_props.rs b/rsvg_internals/src/font_props.rs
index 3caab0a7..4f5e73cd 100644
--- a/rsvg_internals/src/font_props.rs
+++ b/rsvg_internals/src/font_props.rs
@@ -306,10 +306,10 @@ impl Parse for LineHeightSpec {
/// https://www.w3.org/TR/2008/REC-CSS2-20080411/fonts.html#propdef-font-family
#[derive(Debug, Clone, PartialEq)]
-pub struct MultiFontFamily(pub String);
+pub struct FontFamily(pub String);
-impl Parse for MultiFontFamily {
- fn parse<'i>(parser: &mut Parser<'i, '_>) -> Result<MultiFontFamily, ParseError<'i>> {
+impl Parse for FontFamily {
+ fn parse<'i>(parser: &mut Parser<'i, '_>) -> Result<FontFamily, ParseError<'i>> {
let loc = parser.current_source_location();
let fonts = parser.parse_comma_separated(|parser| {
@@ -333,7 +333,7 @@ impl Parse for MultiFontFamily {
Ok(cssparser::CowRcStr::from(value))
})?;
- Ok(MultiFontFamily(fonts.join(",")))
+ Ok(FontFamily(fonts.join(",")))
}
}
@@ -457,36 +457,36 @@ mod tests {
#[test]
fn parses_font_family() {
assert_eq!(
- <MultiFontFamily as Parse>::parse_str("'Hello world'"),
- Ok(MultiFontFamily("Hello world".to_owned()))
+ <FontFamily as Parse>::parse_str("'Hello world'"),
+ Ok(FontFamily("Hello world".to_owned()))
);
assert_eq!(
- <MultiFontFamily as Parse>::parse_str("\"Hello world\""),
- Ok(MultiFontFamily("Hello world".to_owned()))
+ <FontFamily as Parse>::parse_str("\"Hello world\""),
+ Ok(FontFamily("Hello world".to_owned()))
);
assert_eq!(
- <MultiFontFamily as Parse>::parse_str("\"Hello world with spaces\""),
- Ok(MultiFontFamily("Hello world with spaces".to_owned()))
+ <FontFamily as Parse>::parse_str("\"Hello world with spaces\""),
+ Ok(FontFamily("Hello world with spaces".to_owned()))
);
assert_eq!(
- <MultiFontFamily as Parse>::parse_str(" Hello world "),
- Ok(MultiFontFamily("Hello world".to_owned()))
+ <FontFamily as Parse>::parse_str(" Hello world "),
+ Ok(FontFamily("Hello world".to_owned()))
);
assert_eq!(
- <MultiFontFamily as Parse>::parse_str("Plonk"),
- Ok(MultiFontFamily("Plonk".to_owned()))
+ <FontFamily as Parse>::parse_str("Plonk"),
+ Ok(FontFamily("Plonk".to_owned()))
);
}
#[test]
fn parses_multiple_font_family() {
assert_eq!(
- <MultiFontFamily as Parse>::parse_str("serif,monospace,\"Hello world\", with spaces "),
- Ok(MultiFontFamily(
+ <FontFamily as Parse>::parse_str("serif,monospace,\"Hello world\", with spaces "),
+ Ok(FontFamily(
"serif,monospace,Hello world,with spaces".to_owned()
))
);
@@ -494,9 +494,9 @@ mod tests {
#[test]
fn detects_invalid_font_family() {
- assert!(<MultiFontFamily as Parse>::parse_str("").is_err());
- assert!(<MultiFontFamily as Parse>::parse_str("''").is_err());
- assert!(<MultiFontFamily as Parse>::parse_str("42").is_err());
+ assert!(<FontFamily as Parse>::parse_str("").is_err());
+ assert!(<FontFamily as Parse>::parse_str("''").is_err());
+ assert!(<FontFamily as Parse>::parse_str("42").is_err());
}
#[test]
diff --git a/rsvg_internals/src/property_defs.rs b/rsvg_internals/src/property_defs.rs
index 3fcc6b7b..d3389e11 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, LetterSpacing, LineHeightSpec, MultiFontFamily};
+use crate::font_props::{FontFamily, FontSize, FontWeight, LetterSpacing, LineHeightSpec};
use crate::iri::IRI;
use crate::length::*;
use crate::paint_server::PaintServer;
@@ -234,9 +234,8 @@ make_property!(
make_property!(
ComputedValues,
FontFamily,
- default: MultiFontFamily("Times New Roman".to_string()),
+ default: FontFamily("Times New Roman".to_string()),
inherits_automatically: true,
- newtype_parse: MultiFontFamily,
);
// https://www.w3.org/TR/SVG/text.html#FontSizeProperty
diff --git a/rsvg_internals/src/property_macros.rs b/rsvg_internals/src/property_macros.rs
index eb7f581d..97e652cd 100644
--- a/rsvg_internals/src/property_macros.rs
+++ b/rsvg_internals/src/property_macros.rs
@@ -136,6 +136,15 @@ macro_rules! make_property {
$prop
};
+ ($computed_values_type: ty,
+ $name: ident,
+ default: $default: expr,
+ inherits_automatically: $inherits_automatically: expr,
+ ) => {
+ impl_default!($name, $default);
+ impl_property!($computed_values_type, $name, $inherits_automatically);
+ };
+
// pending - only BaselineShift
($computed_values_type: ty,
$name: ident,
diff --git a/rsvg_internals/src/text.rs b/rsvg_internals/src/text.rs
index 50a3c7db..a6f3a8e0 100644
--- a/rsvg_internals/src/text.rs
+++ b/rsvg_internals/src/text.rs
@@ -958,7 +958,7 @@ fn create_pango_layout(
}
let mut font_desc = pango_context.get_font_description().unwrap();
- font_desc.set_family(&(values.font_family().0).0);
+ font_desc.set_family(&(values.font_family()).0);
font_desc.set_style(pango::Style::from(values.font_style()));
font_desc.set_variant(pango::Variant::from(values.font_variant()));
font_desc.set_weight(pango::Weight::from(values.font_weight()));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]