servo / font-kit

A cross-platform font loading library written in Rust
Apache License 2.0
693 stars 104 forks source link

Some fonts incorrectly match to medium weights #118

Closed jazzfool closed 4 years ago

jazzfool commented 4 years ago

When using select_best_match, fonts such as Roboto get matched to Roboto Medium, even when Properties explicitly requests for the normal (400) weight.

I have Roboto Regular installed so it should be finding that instead. Browsers seem to be matching it correctly.

OS: Windows 10 x64

pcwalton commented 4 years ago

So the problem here is that we follow the CSS Fonts 3 specification, even though it seems to be nonsensical. Here are the rules in question from step 4c:

  • If the desired weight is 400, 500 is checked first and then the rule for desired weights less than 400 is used.
  • If the desired weight is 500, 400 is checked first and then the rule for desired weights less than 400 is used.

This seems to indicate that a specified weight of 400 really maps to 500 and that a specified weight of 500 really maps to 400. But that causes the bug here, and it seems illogical to me.

@SimonSapin Any advice?

SimonSapin commented 4 years ago

This comes after:

if the desired weight is available that face matches. Otherwise, a weight is chosen using the rules below:

So the rule you quoted only applies when there is no exact match for weight.

SimonSapin commented 4 years ago

My reading is that with font-weight: 400 as the computed CSS values, faces with weights 400, 500, 399, 398, …, 2, 1, 401, 402, …, 499, 501, 502, … would be matched in that order of preference.

pcwalton commented 4 years ago

Oh yes, thanks.