servo: Merge #17846 - Allow nonstandard font-weight values for system fonts (from Manishearth:font-weight); r=upsuper
authorManish Goregaokar <manishsmail@gmail.com>
Mon, 24 Jul 2017 17:26:31 -0700
changeset 419401 b2739564fde59c05be530407f37a1185f43ee8c2
parent 419400 29131feeed60e26f0a1c977438ae9a80458a69d5
child 419402 23a8fd85ad7225dce11834ca42e48ccf46621d78
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersupsuper
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #17846 - Allow nonstandard font-weight values for system fonts (from Manishearth:font-weight); r=upsuper Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1379895 Source-Repo: https://github.com/servo/servo Source-Revision: b8ac4a7a2efabe11af1366207f9649982250c0e2
servo/components/style/properties/gecko.mako.rs
servo/components/style/properties/longhand/font.mako.rs
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -2017,20 +2017,18 @@ fn static_assert() {
     }
 
     pub fn set_font_weight(&mut self, v: longhands::font_weight::computed_value::T) {
         self.gecko.mFont.weight = v.0;
     }
     ${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")}
 
     pub fn set_font_size_adjust(&mut self, v: longhands::font_size_adjust::computed_value::T) {
         use properties::longhands::font_size_adjust::computed_value::T;
         match v {
             T::None => self.gecko.mFont.sizeAdjust = -1.0 as f32,
--- a/servo/components/style/properties/longhand/font.mako.rs
+++ b/servo/components/style/properties/longhand/font.mako.rs
@@ -452,16 +452,19 @@ macro_rules! impl_gecko_keyword_conversi
                 None
             }
         }
     }
 
     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);
 
         impl T {
             /// Value for normal
             pub fn normal() -> Self {
                 T(400)
@@ -478,18 +481,19 @@ macro_rules! impl_gecko_keyword_conversi
                     Ok(T(n as u16))
                 } else {
                     Err(())
                 }
             }
 
             /// 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
             pub fn is_bold(&self) -> bool {
                 self.0 > 500
             }
 
             /// Return the bolder weight