MCPcopy Index your code
hub / github.com/RazrFalcon/fontdb

github.com/RazrFalcon/fontdb @v0.23.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.23.0 ↗ · + Follow
55 symbols 115 edges 3 files 14 documented · 25% updated 21mo ago★ 17412 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

fontdb

Build Status Crates.io Documentation Rust 1.60+

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

Features

  • The database can load fonts from files, directories and raw data (Vec<u8>).
  • The database can match a font using CSS-like queries. See Database::query.
  • The database can try to load system fonts. Currently, this is implemented by scanning predefined directories. The library does not interact with the system API.
  • Provides a unique ID for each font face.

Non-goals

  • Advanced font properties querying.

The database provides only storage and matching capabilities. For font properties querying you can use ttf-parser.

  • A font fallback mechanism.

This library can be used to implement a font fallback mechanism, but it doesn't implement one.

  • Application's global database.

The database doesn't use static, therefore it's up to the caller where it should be stored.

  • Font types support other than TrueType.

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.

For example, on Mac Book Pro 14 with M1 Pro, it takes just ~24ms to load 1361 font faces.

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

Extension points exported contracts — how you extend this code

NameExt (Interface)
(no doc) [1 implementers]
src/lib.rs

Core symbols most depended-on inside this repo

load_fonts_dir_impl
called by 16
src/lib.rs
is_empty
called by 6
src/lib.rs
len
called by 3
src/lib.rs
set_sans_serif_family
called by 3
src/lib.rs
name_to_unicode
called by 3
src/lib.rs
is_mac_roman
called by 3
src/lib.rs
load_font_source
called by 2
src/lib.rs
load_fonts_from_file
called by 2
src/lib.rs

Shape

Method 36
Function 9
Class 5
Enum 4
Interface 1

Languages

Rust100%

Modules by API surface

src/lib.rs53 symbols
tests/add_fonts.rs1 symbols
examples/find-system-font.rs1 symbols

For agents

$ claude mcp add fontdb \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact