fontations

repository·main·Indexed 21 days ago

https://github.com/googlefonts/fontations

A collection of high-performance, memory-safe Rust crates for reading, parsing, and manipulating OpenType font files. The project includes font-types for OpenType definitions, a codegen tool for generating font table parsing and compilation code, and fauntlet, a testing tool for comparing Skrifa and FreeType glyph output.

Tokens
54.6K
Snippets
181
Records
245
Agent score
73%

What's inside fontations

  1. Overview of Fontations library crates

    main

    Fontations is a collection of Rust crates designed for robust and performant reading and manipulation of OpenType font files. The repository is organized into several specialized libraries:

    • font-types: Provides core type definitions from the OpenType specification. It is intended as a lightweight dependency for any project interacting with font data.
    • read-fonts: A high-performance, zero-allocation, and zero-copy parser for accessing font files, optimized for shaping tasks.
    • write-fonts: A library for modifying and writing font data. It uses owned types for tables and records and can optionally depend on read-fonts to parse data before modification.
    • skrifa: A mid-level library for accessing font metadata and loading glyph outlines. It is designed as a memory-safe replacement for FreeType in Google applications.
    • skera: A crate used for creating font subsets.
    • incremental-font-transfer: A client-side library for applying IFT patches.
  2. Overview of Incremental Font Transfer

    main

    This library is a client-side implementation of the W3C Incremental Font Transfer (IFT) standard. It is built on top of the read-fonts crate and provides functionality for:

    • Parsing and reading incremental font patch mappings: Handles the font format extensions defined in the IFT specification.
    • Parsing and applying incremental font patches: Implements the logic to process and apply font patches as described in the IFT specification.
  3. Overview of skrifa

    main
    skrifa is a robust, ergonomic, and high-performance Rust library designed for reading OpenType fonts. It is built on top of the read-fonts low-level parsing library and is a component of the oxidize project. It is designed to be safe, forbidding unsafe code via #![forbid(unsafe_code)], and aims to never panic even when encountering corrupted or malicious font files.
  4. Overview of Shared Brotli Patch Decoder

    main

    The shared-brotli-patch-decoder crate provides a wrapper around brotli-sys to support decoding Brotli-encoded data that utilizes a shared raw LZ77 dictionary. This functionality extends standard Brotli decoding to support the shared Brotli format as specified in the IETF draft: draft-vandevenne-shared-brotli-format-11#section-3.2.

    This decoder is primarily intended for use when decoding incremental font transfer (IFT) patches, following the specifications found in the W3C IFT Overview.

  5. Overview of the read-fonts crate

    main
    The read-fonts crate is a high-performance implementation for parsing and reading OpenType fonts. It is designed to be suitable for performance-critical tasks like font shaping while providing a high-level API. The crate is strictly safe, as it uses #![forbid(unsafe_code)] to ensure no unsafe code is present in the library.
  6. Use font-types for OpenType definitions and encoding/decoding

    main

    The font-types crate provides core definitions for OpenType specification types. It is designed as a general-purpose library for Rust projects that need to work with font data.

    Key features include:

    • Definitions of basic OpenType types.
    • Informal but useful types, such as a distinct type for Glyph IDs.
    • Traits for encoding and decoding these types as big-endian bytes.
  7. Use otexplorer to query font file contents

    main

    otexplorer is a Rust binary used to print and query the contents of font files. It uses a custom text format (rather than XML) and supports a specific query syntax to navigate font tables.

    To use it, you run the binary and can optionally provide a query string via the -q flag to target specific subtables or records within the font.

  8. Understand the format of codegen inputs

    main

    The files located in resources/codegen_inputs/ are not standard Rust source files. Instead, they serve as specialized inputs for the font-codegen tool.

    While they do not follow strict Rust syntax rules, they are composed entirely of valid Rust tokens. This design choice allows the code generation process to utilize the syn and quote crates for parsing and manipulation, while still providing functional Rust syntax highlighting in editors.

    For detailed instructions on how to use these inputs or how the generation process works, refer to the font-codegen/README.md documentation.

  9. Understand Zerocopy vs Copy-on-Read records

    main

    Records within tables are generated using one of two strategies based on their size:

    Zerocopy Records

    Used when a record has a constant size known at compile time. The generated struct uses #[repr(C)] and #[repr(packed)] to match the raw memory layout exactly. These can be 'cast' directly from a byte slice using the FixedSize trait.

    Copy-on-Read Records

    Used when a record has a variable size (e.g., size depends on a format field in the parent table). These cannot be cast from bytes. Instead, the project generates a standard struct and implements FontRead (often with Args) to manually copy and instantiate the fields from the FontData during the read call.