Re: [csswg-drafts] [css-fonts] Font matching algorithm; issue with weight selection

We're somewhat limited by historical design here; when font-weights were limited to the multiples of 100, the rules were:

* If the requested weight is 400 or 500, see if the other weight exists; otherwise find the largest weight less than 400, otherwise find the smallest weight greater than 500.
* If the requested weight is less than 400, find the largest weight less than the request; otherwise find the smallest weight greater than the request.
* If the requested weight is greater than 500, find the smallest weight larger than the request; otherwise find the largest weight smaller than the request.

These rules more or less have the effect of dividing the weight space into three categories - "light", "medium", and "heavy", and searching within the requested space before going elsewhere.  They also encode an intent of "if you're asking for something light, and you don't find it, you'd probably prefer something even lighter rather than something closer to medium" and the reverse for heavy.

Now that we allow any integer in the 1-1000 space, the rules are written to be more explicit about this - if you ask for 398, and the only weights are 1 and 399, you'll get 1.  The three categories are now (1-399), (400-500), and (501-1000).

While the above example is a *little bit* ridiculous, the alternative would be to come up with a much more complex relative weighting scheme, so that the browser would *prefer* to select lighter weights, but would choose a heavier weight if it's much closer than the closest lighter weight (and vice versa for heavy, and something more complex for medium weights).  In practice this would rarely come up, and a much simpler rule does the job just fine.

Note that in complicated cases, you can always set up several `@font-face` rules and manually map them to a particular chosen weight, so you know for sure what the weight you need to use is.

-- 
GitHub Notification of comment by tabatkins
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/1701#issuecomment-320787743 using your GitHub account

Received on Monday, 7 August 2017 21:37:33 UTC