Giter Site home page Giter Site logo

fontdb's Introduction

fontdb

Build Status Crates.io Documentation Rust 1.49+

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.

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

fontdb's People

Contributors

razrfalcon avatar notgull avatar 7sdream avatar dabreegster avatar jackpot51 avatar declantsien avatar messense avatar cryze avatar dhardy avatar flovangh avatar linus789 avatar riey avatar tronical avatar neinseg avatar

Stargazers

Roman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.