From fe8f5fad161ff863b91b3103d5fdd99c30216f8e Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 2 Feb 2017 19:52:57 +0100 Subject: [PATCH] Add font-weight descriptor to @font-face --- components/style/font_face.rs | 5 ++++- components/style/properties/longhand/font.mako.rs | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/components/style/font_face.rs b/components/style/font_face.rs index 868ca8524a2..b4f4b6185cb 100644 --- a/components/style/font_face.rs +++ b/components/style/font_face.rs @@ -8,8 +8,8 @@ #![deny(missing_docs)] +#[cfg(feature = "gecko")] use computed_values::{font_style, font_weight}; use computed_values::font_family::FamilyName; -#[cfg(feature = "gecko")] use computed_values::font_style; use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser}; use parser::{ParserContext, log_css_error, Parse}; use std::fmt; @@ -295,6 +295,9 @@ font_face_descriptors! { optional descriptors = [ /// The style of this font face "font-style" style: font_style::T = font_style::T::normal, + + /// The weight of this font face + "font-weight" weight: font_weight::T = font_weight::T::Weight400 /* normal */, ] } diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index 838851b8a4e..b8d682ffcdf 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -273,6 +273,20 @@ ${helpers.single_keyword("font-variant-caps", } }) } + + /// Used in @font-face, where relative keywords are not allowed. + impl Parse for computed_value::T { + fn parse(context: &ParserContext, input: &mut Parser) -> Result { + match parse(context, input)? { + % for weight in range(100, 901, 100): + SpecifiedValue::Weight${weight} => Ok(computed_value::T::Weight${weight}), + % endfor + SpecifiedValue::Bolder | + SpecifiedValue::Lighter => Err(()) + } + } + } + pub mod computed_value { use std::fmt; #[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]