font
Fonts without a dependency: CSS font matching, the names design tools give to weights and styles, and reading a font file’s names, weight and style.
pick_closest is CSS Fonts Level 4 matching (§5.2) among the faces of one family, with
variable faces that cover a weight range. weight_of_style, is_italic,
split_postscript and same_family read the names fonts and design files carry
("Semi Bold Italic", "NeutrifPro-SemiBold"). read_font reads a TrueType, OpenType or
WOFF file: family (typographic first), PostScript name, weight or wght range, style;
font_count and read_font_at reach every font of a collection, and to_sfnt hands
back the decompressed font file a shaper reads.
Install
Section titled “Install”Cargo feature font (enabled by default). To compile only this module:
or in Cargo.toml:
Import path: helpers4::font.
| Item | What it does |
|---|---|
font_count | How many fonts a font file holds: the number of fonts of a collection (.ttc), 1 for a TrueType, OpenType or WOFF file. |
FontFace | A face of a font family, with the properties CSS font matching compares. |
FontInfo | What a font file says about itself, as read_font reads it. |
FontRequest | What a text asks of a family: the properties pick_closest matches. |
FontStyle | The font-style of a face or a request. |
is_italic | Whether a style name is italic or oblique, as design tools and font files write it ("Italic", "Semi Bold Italic", "Light Oblique"). |
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. |
read_font | Reads what a font file says about itself: its family (typographic first), style, PostScript name, weight or wght range and whether it is italic. |
read_font_at | Reads what the font number index of a file says about itself, as read_font does for the first one: the way to read the other fonts of a collection (.ttc), whose count font_count gives. |
same_family | Whether two family names are the same family: compared without spaces or case, since design files and font files write "SF Pro", "SFPro" and "sf pro" for one family. |
split_postscript | Splits a PostScript font name into family and style at its first hyphen: NeutrifPro-SemiBold is NeutrifPro and SemiBold. |
to_sfnt | The font file as the sfnt that shapers and rasterizers read (skrifa, ttf-parser, …): a WOFF file is rebuilt with its tables decompressed; a TrueType, OpenType or collection file is already one and comes back as it is, without a copy. |
weight_of_style | The CSS weight a style name stands for, as design tools and font files write it: Thin 100, ExtraLight 200, Light 300, Regular 400, Medium 500, SemiBold 600, Bold 700, ExtraBold 800, Black 900, ExtraBlack 950. |
Error types
Section titled “Error types”Documented on the page of the helper that returns them.
| Type | Returned by |
|---|---|
FontError | font_count, read_font, read_font_at, to_sfnt |
