mirror of
https://github.com/servo/servo.git
synced 2025-08-07 22:45:34 +01:00
style: Update font-weight property and descriptor to css-fonts-4.
Bug: 1454596 Reviewed-by: xidorn MozReview-Commit-ID: 27aS2UrgXjs
This commit is contained in:
parent
76a14d6a64
commit
bc1126ee8c
10 changed files with 199 additions and 141 deletions
|
@ -9,7 +9,7 @@
|
|||
#![deny(missing_docs)]
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
use computed_values::{font_stretch, font_style, font_weight};
|
||||
use computed_values::{font_stretch, font_style};
|
||||
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
|
||||
use cssparser::{CowRcStr, SourceLocation};
|
||||
#[cfg(feature = "gecko")]
|
||||
|
@ -27,7 +27,7 @@ use style_traits::{StyleParseErrorKind, ToCss};
|
|||
use style_traits::values::SequenceWriter;
|
||||
use values::computed::font::FamilyName;
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::specified::font::{SpecifiedFontFeatureSettings, SpecifiedFontVariationSettings};
|
||||
use values::specified::font::{AbsoluteFontWeight, SpecifiedFontFeatureSettings, SpecifiedFontVariationSettings};
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
|
||||
/// A source for a font-face rule.
|
||||
|
@ -92,38 +92,21 @@ pub enum FontDisplay {
|
|||
Optional,
|
||||
}
|
||||
|
||||
/// A font-weight value for a @font-face rule.
|
||||
/// The font-weight CSS property specifies the weight or boldness of the font.
|
||||
#[cfg(feature = "gecko")]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, ToCss)]
|
||||
pub enum FontWeight {
|
||||
/// Numeric font weights for fonts that provide more than just normal and bold.
|
||||
Weight(font_weight::T),
|
||||
/// Normal font weight. Same as 400.
|
||||
Normal,
|
||||
/// Bold font weight. Same as 700.
|
||||
Bold,
|
||||
}
|
||||
/// The font-weight descriptor:
|
||||
///
|
||||
/// https://drafts.csswg.org/css-fonts-4/#descdef-font-face-font-weight
|
||||
#[derive(Clone, Debug, PartialEq, ToCss)]
|
||||
pub struct FontWeight(pub AbsoluteFontWeight, pub Option<AbsoluteFontWeight>);
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
impl Parse for FontWeight {
|
||||
fn parse<'i, 't>(
|
||||
_: &ParserContext,
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<FontWeight, ParseError<'i>> {
|
||||
let result = input.try(|input| {
|
||||
let ident = input.expect_ident().map_err(|_| ())?;
|
||||
match_ignore_ascii_case! { &ident,
|
||||
"normal" => Ok(FontWeight::Normal),
|
||||
"bold" => Ok(FontWeight::Bold),
|
||||
_ => Err(())
|
||||
}
|
||||
});
|
||||
result.or_else(|_| {
|
||||
font_weight::T::from_int(input.expect_integer()?)
|
||||
.map(FontWeight::Weight)
|
||||
.map_err(|()| input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
})
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let first = AbsoluteFontWeight::parse(context, input)?;
|
||||
let second =
|
||||
input.try(|input| AbsoluteFontWeight::parse(context, input)).ok();
|
||||
Ok(FontWeight(first, second))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue