pick_closest
Picks the face that CSS would use for a request, among the faces of one family: the CSS Fonts Level 4 matching algorithm (§5.2), as a pure function. The stretch is matched first, then the style, then the weight; each step keeps only the faces closest to what was asked.
- Stretch: at or below 100, narrower faces first (nearest), then wider ones; above 100, the other way round.
- Style: normal prefers normal, then oblique, then italic; italic prefers italic, then oblique, then normal; oblique prefers oblique, then italic, then normal.
- Weight: a variable face whose range covers the weight is an exact match. Otherwise, from 400 to 500, the nearest heavier weight up to 500, then lighter ones, then heavier ones above 500; below 400, lighter first then heavier; above 500, heavier first then lighter. A variable face counts for the bound of its range closest to the weight.
Import
Section titled “Import”Cargo feature font (enabled by default). To compile only this module:
or in Cargo.toml:
Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
faces | &[FontFace] | The faces of one family. |
wanted | FontRequest | What was asked. |
Returns
Section titled “Returns”Option<usize> — The index of the closest face, the first one when several are equally close, or None for no
face.
