[librsvg: 19/22] Declare the 'font' shorthand for SpecifiedValues and expand it into longhands
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 19/22] Declare the 'font' shorthand for SpecifiedValues and expand it into longhands
- Date: Wed, 1 Jul 2020 00:04:47 +0000 (UTC)
commit 38bc401f40111519cade7a6ff6ef430b6dd01d87
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Jun 30 17:27:51 2020 -0500
Declare the 'font' shorthand for SpecifiedValues and expand it into longhands
rsvg_internals/src/font_props.rs | 18 +++++++++++++++
rsvg_internals/src/properties.rs | 50 ++++++++++++++++++++++++++++++++++++++--
2 files changed, 66 insertions(+), 2 deletions(-)
---
diff --git a/rsvg_internals/src/font_props.rs b/rsvg_internals/src/font_props.rs
index d3a44f09..baee2230 100644
--- a/rsvg_internals/src/font_props.rs
+++ b/rsvg_internals/src/font_props.rs
@@ -117,6 +117,24 @@ impl Parse for Font {
}
}
+impl Font {
+ pub fn to_font_spec(&self) -> FontSpec {
+ match *self {
+ Font::Caption
+ | Font::Icon
+ | Font::Menu
+ | Font::MessageBox
+ | Font::SmallCaption
+ | Font::StatusBar => {
+ // We don't actually pick up the systme fonts, so reduce them to a default.
+ FontSpec::default()
+ }
+
+ Font::Spec(ref spec) => spec.clone(),
+ }
+ }
+}
+
#[rustfmt::skip]
fn parse_font_spec_identifiers<'i>(parser: &mut Parser<'i, '_>) -> Result<Font, ParseError<'i>> {
Ok(parser.try_parse(|p| {
diff --git a/rsvg_internals/src/properties.rs b/rsvg_internals/src/properties.rs
index 20e5d27e..857623f8 100644
--- a/rsvg_internals/src/properties.rs
+++ b/rsvg_internals/src/properties.rs
@@ -326,7 +326,8 @@ macro_rules! make_properties {
#[rustfmt::skip]
make_properties! {
shorthands: {
- "marker" => marker: Marker,
+ "font" => font : Font,
+ "marker" => marker : Marker,
}
longhands: {
@@ -428,12 +429,57 @@ impl SpecifiedValues {
fn set_property_expanding_shorthands(&mut self, prop: &ParsedProperty, replace: bool) {
match *prop {
- ParsedProperty::Marker(SpecifiedValue::Specified(ref m)) => self.expand_marker_shorthand(m,
replace),
+ ParsedProperty::Font(SpecifiedValue::Specified(ref f)) => {
+ self.expand_font_shorthand(f, replace)
+ }
+ ParsedProperty::Marker(SpecifiedValue::Specified(ref m)) => {
+ self.expand_marker_shorthand(m, replace)
+ }
_ => self.set_property(prop, replace),
}
}
+ fn expand_font_shorthand(&mut self, font: &Font, replace: bool) {
+ let FontSpec {
+ style,
+ variant,
+ weight,
+ stretch,
+ size,
+ line_height,
+ family,
+ } = font.to_font_spec();
+
+ self.set_property(
+ &ParsedProperty::FontStyle(SpecifiedValue::Specified(style)),
+ replace,
+ );
+ self.set_property(
+ &ParsedProperty::FontVariant(SpecifiedValue::Specified(variant)),
+ replace,
+ );
+ self.set_property(
+ &ParsedProperty::FontWeight(SpecifiedValue::Specified(weight)),
+ replace,
+ );
+ self.set_property(
+ &ParsedProperty::FontStretch(SpecifiedValue::Specified(stretch)),
+ replace,
+ );
+ self.set_property(
+ &ParsedProperty::FontSize(SpecifiedValue::Specified(size)),
+ replace,
+ );
+ self.set_property(
+ &ParsedProperty::LineHeight(SpecifiedValue::Specified(line_height)),
+ replace,
+ );
+ self.set_property(
+ &ParsedProperty::FontFamily(SpecifiedValue::Specified(family)),
+ replace,
+ );
+ }
fn expand_marker_shorthand(&mut self, marker: &Marker, replace: bool) {
let Marker(v) = marker;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]