mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
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
This commit is contained in:
parent
479c6c9c42
commit
3addd775a5
1 changed files with 14 additions and 10 deletions
|
@ -103,16 +103,20 @@ impl FontHandleMethods for FontHandle {
|
||||||
|
|
||||||
fn boldness(&self) -> font_weight::T {
|
fn boldness(&self) -> font_weight::T {
|
||||||
let normalized = self.ctfont.all_traits().normalized_weight(); // [-1.0, 1.0]
|
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]
|
let normalized = if normalized <= 0.0 {
|
||||||
match normalized {
|
4.0 + normalized * 3.0 // [1.0, 4.0]
|
||||||
v if v < 1.0 => font_weight::T::Weight100,
|
} else {
|
||||||
v if v < 2.0 => font_weight::T::Weight200,
|
4.0 + normalized * 5.0 // [4.0, 9.0]
|
||||||
v if v < 3.0 => font_weight::T::Weight300,
|
}; // [1.0, 9.0], centered on 4.0
|
||||||
v if v < 4.0 => font_weight::T::Weight400,
|
match normalized.round() as u32 {
|
||||||
v if v < 5.0 => font_weight::T::Weight500,
|
1 => font_weight::T::Weight100,
|
||||||
v if v < 6.0 => font_weight::T::Weight600,
|
2 => font_weight::T::Weight200,
|
||||||
v if v < 7.0 => font_weight::T::Weight700,
|
3 => font_weight::T::Weight300,
|
||||||
v if v < 8.0 => font_weight::T::Weight800,
|
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,
|
_ => font_weight::T::Weight900,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue