From 3addd775a5765c1d0c95794fca654bad56f4ca4c Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 9 May 2016 16:00:16 -0700 Subject: [PATCH] gfx: Change the mapping from Mac weights to CSS weights so that 0.0 maps to 400, not 500. CSS `normal` font-weight is specified as 400, while Mac "Regular" font weight is reported as 0.0. On the Mac, we need to center the two ranges on the same value to avoid choosing "Light" fonts where "Regular" would have been more appropriate. Closes #9487. fix for mac --- components/gfx/platform/macos/font.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/components/gfx/platform/macos/font.rs b/components/gfx/platform/macos/font.rs index abdb620ba36..c6be7c16d78 100644 --- a/components/gfx/platform/macos/font.rs +++ b/components/gfx/platform/macos/font.rs @@ -103,16 +103,20 @@ impl FontHandleMethods for FontHandle { fn boldness(&self) -> font_weight::T { let normalized = self.ctfont.all_traits().normalized_weight(); // [-1.0, 1.0] - let normalized = (normalized + 1.0) / 2.0 * 9.0; // [0.0, 9.0] - match normalized { - v if v < 1.0 => font_weight::T::Weight100, - v if v < 2.0 => font_weight::T::Weight200, - v if v < 3.0 => font_weight::T::Weight300, - v if v < 4.0 => font_weight::T::Weight400, - v if v < 5.0 => font_weight::T::Weight500, - v if v < 6.0 => font_weight::T::Weight600, - v if v < 7.0 => font_weight::T::Weight700, - v if v < 8.0 => font_weight::T::Weight800, + let normalized = if normalized <= 0.0 { + 4.0 + normalized * 3.0 // [1.0, 4.0] + } else { + 4.0 + normalized * 5.0 // [4.0, 9.0] + }; // [1.0, 9.0], centered on 4.0 + match normalized.round() as u32 { + 1 => font_weight::T::Weight100, + 2 => font_weight::T::Weight200, + 3 => font_weight::T::Weight300, + 4 => font_weight::T::Weight400, + 5 => font_weight::T::Weight500, + 6 => font_weight::T::Weight600, + 7 => font_weight::T::Weight700, + 8 => font_weight::T::Weight800, _ => font_weight::T::Weight900, } }