Skip to content

Commit

Permalink
Allow nonstandard font-weight values for system fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Jul 25, 2017
1 parent a35c8f0 commit 9c6f11c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 2 additions & 4 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -2022,10 +2022,8 @@ fn static_assert() {
${impl_simple_copy('font_weight', 'mFont.weight')}

pub fn clone_font_weight(&self) -> longhands::font_weight::computed_value::T {
debug_assert!(self.gecko.mFont.weight >= 100);
debug_assert!(self.gecko.mFont.weight <= 900);
debug_assert!(self.gecko.mFont.weight % 10 == 0);
unsafe { transmute(self.gecko.mFont.weight) }
debug_assert!(self.gecko.mFont.weight <= ::std::u16::MAX);
longhands::font_weight::computed_value::T(self.gecko.mFont.weight)
}

${impl_simple_type_with_conversion("font_synthesis", "mFont.synthesis")}
Expand Down
8 changes: 6 additions & 2 deletions components/style/properties/longhand/font.mako.rs
Expand Up @@ -457,6 +457,9 @@ ${helpers.single_keyword_system("font-variant-caps",
pub mod computed_value {
/// As of CSS Fonts Module Level 3, only the following values are
/// valid: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
///
/// However, system fonts may provide other values. Pango
/// may provide 350, 380, and 1000 (on top of the existing values), for example.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, ToCss)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
pub struct T(pub u16);
Expand All @@ -483,8 +486,9 @@ ${helpers.single_keyword_system("font-variant-caps",

/// Convert from an Gecko weight
pub fn from_gecko_weight(weight: u16) -> Self {
Self::from_int(weight as i32)
.expect("from_gecko_weight: called with invalid weight")
// we allow a wider range of weights than is parseable
// because system fonts may provide custom values
T(weight)
}

/// Weither this weight is bold
Expand Down

0 comments on commit 9c6f11c

Please sign in to comment.