fontdb

Build Status Crates.io Documentation Rust 1.42+

fontdb is a simple, in-memory font database with CSS-like queries.

Features

Non-goals

Font vs Face

A font is a collection of font faces. Therefore, a font face is a subset of a font. A simple font (*.ttf/*.otf) usually contains a single font face, but a font collection (*.ttc) can contain multiple font faces.

fontdb stores and matches font faces, not fonts. Therefore, after loading a font collection with 5 faces (for example), the database will be populated with 5 FaceInfo objects, all of which will be pointing to the same file or binary data.

Performance

The database performance is largely limited by the storage itself. We are using [ttf-parser], so the parsing should not be a bottleneck.

On my machine with Samsung SSD 860 and Gentoo Linux, it takes ~20ms to load 1906 font faces (most of them are from Google Noto collection) with a hot disk cache and ~860ms with a cold one.

On Mac Mini M1 it takes just 9ms to load 898 fonts.

Safety

The library relies on memory-mapped files, which is inherently unsafe. But since we do not keep the files open it should be perfectly safe.

If you would like to use a persistent memory mapping of the font files, then you can use the unsafe [Database::make_shared_face_data] function.

License

MIT