Use integer for specified and computed font-weight

This commit is contained in:
Xidorn Quan 2017-07-06 15:31:24 +10:00
parent 4f0f2fb13e
commit 8b842f5417
11 changed files with 111 additions and 194 deletions

View file

@ -109,29 +109,13 @@ impl Parse for FontWeight {
}
});
result.or_else(|_| {
FontWeight::from_int(input.expect_integer()?)
font_weight::T::from_int(input.expect_integer()?)
.map(FontWeight::Weight)
.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.
///
/// Note that the prelude parsing code lives in the `stylesheets` module.