mirror of
https://github.com/servo/servo.git
synced 2025-06-20 23:28:59 +01:00
stylo: make font-weight descriptor in @font-face preserve keyword values
This commit is contained in:
parent
f5a61684f4
commit
632c5571a9
2 changed files with 74 additions and 2 deletions
|
@ -70,6 +70,66 @@ define_css_keyword_enum!(FontDisplay:
|
||||||
"optional" => Optional);
|
"optional" => Optional);
|
||||||
add_impls_for_keyword_enum!(FontDisplay);
|
add_impls_for_keyword_enum!(FontDisplay);
|
||||||
|
|
||||||
|
/// 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, PartialEq, Eq)]
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
impl ToCss for FontWeight {
|
||||||
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
|
match *self {
|
||||||
|
FontWeight::Normal => dest.write_str("normal"),
|
||||||
|
FontWeight::Bold => dest.write_str("bold"),
|
||||||
|
FontWeight::Weight(ref weight) => weight.to_css(dest),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
impl Parse for FontWeight {
|
||||||
|
fn parse<'i, 't>(_: &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(|_| {
|
||||||
|
FontWeight::from_int(input.expect_integer()?)
|
||||||
|
.map_err(|()| StyleParseError::UnspecifiedError.into())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
impl FontWeight {
|
||||||
|
fn from_int(kw: i32) -> Result<Self, ()> {
|
||||||
|
match kw {
|
||||||
|
100 => Ok(FontWeight::Weight(font_weight::T::Weight100)),
|
||||||
|
200 => Ok(FontWeight::Weight(font_weight::T::Weight200)),
|
||||||
|
300 => Ok(FontWeight::Weight(font_weight::T::Weight300)),
|
||||||
|
400 => Ok(FontWeight::Weight(font_weight::T::Weight400)),
|
||||||
|
500 => Ok(FontWeight::Weight(font_weight::T::Weight500)),
|
||||||
|
600 => Ok(FontWeight::Weight(font_weight::T::Weight600)),
|
||||||
|
700 => Ok(FontWeight::Weight(font_weight::T::Weight700)),
|
||||||
|
800 => Ok(FontWeight::Weight(font_weight::T::Weight800)),
|
||||||
|
900 => Ok(FontWeight::Weight(font_weight::T::Weight900)),
|
||||||
|
_ => Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
/// Parse the block inside a `@font-face` rule.
|
/// Parse the block inside a `@font-face` rule.
|
||||||
///
|
///
|
||||||
/// Note that the prelude parsing code lives in the `stylesheets` module.
|
/// Note that the prelude parsing code lives in the `stylesheets` module.
|
||||||
|
@ -329,7 +389,7 @@ font_face_descriptors! {
|
||||||
"font-style" style / mStyle: font_style::T = font_style::T::normal,
|
"font-style" style / mStyle: font_style::T = font_style::T::normal,
|
||||||
|
|
||||||
/// The weight of this font face
|
/// The weight of this font face
|
||||||
"font-weight" weight / mWeight: font_weight::T = font_weight::T::Weight400 /* normal */,
|
"font-weight" weight / mWeight: FontWeight = FontWeight::Normal,
|
||||||
|
|
||||||
/// The stretch of this font face
|
/// The stretch of this font face
|
||||||
"font-stretch" stretch / mStretch: font_stretch::T = font_stretch::T::normal,
|
"font-stretch" stretch / mStretch: font_stretch::T = font_stretch::T::normal,
|
||||||
|
|
|
@ -9,7 +9,7 @@ use computed_values::{font_feature_settings, font_stretch, font_style, font_weig
|
||||||
use computed_values::font_family::FamilyName;
|
use computed_values::font_family::FamilyName;
|
||||||
use counter_style;
|
use counter_style;
|
||||||
use cssparser::UnicodeRange;
|
use cssparser::UnicodeRange;
|
||||||
use font_face::{FontFaceRuleData, Source, FontDisplay};
|
use font_face::{FontFaceRuleData, Source, FontDisplay, FontWeight};
|
||||||
use gecko_bindings::bindings;
|
use gecko_bindings::bindings;
|
||||||
use gecko_bindings::structs::{self, nsCSSFontFaceRule, nsCSSValue};
|
use gecko_bindings::structs::{self, nsCSSFontFaceRule, nsCSSValue};
|
||||||
use gecko_bindings::structs::{nsCSSCounterDesc, nsCSSCounterStyleRule};
|
use gecko_bindings::structs::{nsCSSCounterDesc, nsCSSCounterStyleRule};
|
||||||
|
@ -34,6 +34,18 @@ impl ToNsCssValue for font_weight::T {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ToNsCssValue for FontWeight {
|
||||||
|
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||||
|
match self {
|
||||||
|
FontWeight::Normal =>
|
||||||
|
nscssvalue.set_enum(structs::NS_STYLE_FONT_WEIGHT_NORMAL as i32),
|
||||||
|
FontWeight::Bold =>
|
||||||
|
nscssvalue.set_enum(structs::NS_STYLE_FONT_WEIGHT_BOLD as i32),
|
||||||
|
FontWeight::Weight(weight) => nscssvalue.set_integer(weight as i32),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ToNsCssValue for font_feature_settings::T {
|
impl ToNsCssValue for font_feature_settings::T {
|
||||||
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||||
match self {
|
match self {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue