servo: Merge #17846 - Allow nonstandard font-weight values for system fonts (from Manishearth:font-weight); r=upsuper a=tomcat
authorManish Goregaokar <manishsmail@gmail.com>
Mon, 24 Jul 2017 17:26:31 -0700
changeset 421722 131e19a573e901fb4d01b471b11b7916420b9fee
parent 421721 a2058025fd776f8e4ec889ab8ba1c217dc390e4f
child 421846 80394cbcae0f02da8eb801edd92e56f974e5db4f
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersupsuper, tomcat
milestone56.0a1
first release with
nightly linux32
131e19a573e9 / 56.0a1 / 20170725100346 / files
nightly linux64
131e19a573e9 / 56.0a1 / 20170725100346 / files
nightly mac
131e19a573e9 / 56.0a1 / 20170725100255 / files
nightly win32
131e19a573e9 / 56.0a1 / 20170725030209 / files
nightly win64
131e19a573e9 / 56.0a1 / 20170725030209 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
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 a=tomcat 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