Skip to content

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.

Cargo feature font (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features font

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.11", default-features = false, features = ["font"] }

Import path: helpers4::font.

ItemWhat it does
font_countHow many fonts a font file holds: the number of fonts of a collection (.ttc), 1 for a TrueType, OpenType or WOFF file.
FontFaceA face of a font family, with the properties CSS font matching compares.
FontInfoWhat a font file says about itself, as read_font reads it.
FontRequestWhat a text asks of a family: the properties pick_closest matches.
FontStyleThe font-style of a face or a request.
is_italicWhether a style name is italic or oblique, as design tools and font files write it ("Italic", "Semi Bold Italic", "Light Oblique").
pick_closestPicks 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_fontReads 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_atReads 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_familyWhether 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_postscriptSplits a PostScript font name into family and style at its first hyphen: NeutrifPro-SemiBold is NeutrifPro and SemiBold.
to_sfntThe 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_styleThe 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.

Documented on the page of the helper that returns them.

TypeReturned by
FontErrorfont_count, read_font, read_font_at, to_sfnt