pickClosest
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:
normalprefers normal, then oblique, then italic;italicprefers italic, then oblique, then normal;obliqueprefers oblique, then italic, then normal. - Weight: 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.
Available since v3.1.8
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
faces | readonly T[] | The faces of one family, for instance the entries of a font catalogue |
wanted | FontFaceDescriptor | What was asked; each missing property is its CSS initial value |
Returns
Section titled “Returns”T | undefined — The closest face, the first one when several are equally close, or undefined for no face
Examples
Section titled “Examples”Pick the face for a weight that is not available
Section titled “Pick the face for a weight that is not available”Above 500, CSS goes to the next heavier face before any lighter one.
Ask for an italic, with a fallback
Section titled “Ask for an italic, with a fallback”Without an italic face, oblique is tried, then normal, as in a browser.
Related Types
Section titled “Related Types”FontFaceDescriptor
Section titled “FontFaceDescriptor”The properties of a font face that CSS font matching compares.
