Skip to content

Commit

Permalink
gfx: Change the mapping from Mac weights to CSS weights so that 0.0 maps
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pcwalton committed May 10, 2016
1 parent 479c6c9 commit 3addd77
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions components/gfx/platform/macos/font.rs
Expand Up @@ -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,
}
}
Expand Down

0 comments on commit 3addd77

Please sign in to comment.