Crate read_fonts

Source
Expand description

Reading OpenType tables

This crate provides memory safe zero-allocation parsing of font files. It is unopinionated, and attempts to provide raw access to the underlying font data as it is described in the OpenType specification.

This crate is intended for use by other parts of a font stack, such as a shaping engine or a glyph rasterizer.

In addition to raw data access, this crate may also provide reference implementations of algorithms for interpreting that data, where such an implementation is required for the data to be useful. For instance, we provide functions for mapping codepoints to glyph identifiers using the cmap table, or for decoding entries in the name table.

For higher level/more ergonomic access to font data, you may want to look into using skrifa instead.

§Structure & codegen

The root tables module contains a submodule for each supported table, and that submodule contains items for each table, record, flagset or enum described in the relevant portion of the spec.

The majority of the code in the tables module is auto-generated. For more information on our use of codegen, see the codegen tour.

  • write-fonts is a companion crate for creating/modifying font files
  • skrifa provides access to glyph outlines and metadata (in the same vein as freetype)

§Example

use read_fonts::{FontRef, TableProvider};
let font_bytes = std::fs::read(path_to_my_font_file).unwrap();
// Single fonts only. for font collections (.ttc) use FontRef::from_index
let font = FontRef::new(&font_bytes).expect("failed to read font data");
let head = font.head().expect("missing 'head' table");
let maxp = font.maxp().expect("missing 'maxp' table");

println!("font version {} containing {} glyphs", head.font_revision(), maxp.num_glyphs());

Re-exports§

Modules§

Macros§

  • be_buffer!(val1, …, valn) - Constructs a BeBuffer from the provided list of values:
  • be_buffer_add!(buffer, value) - Add an item to a be_buffer.

Structs§

Enums§

  • Reference to the content of a font or font collection file.
  • An error that occurs when reading font data

Traits§

  • A type that can compute its size at runtime, based on some input.
  • A type that can be read from raw table data.
  • A trait for types that require external data in order to be constructed.
  • Any offset type.
  • A trait for a type that needs additional arguments to be read.
  • A helper trait providing a ‘resolve’ method for nullable offset types
  • A helper trait providing a ‘resolve’ method for offset types
  • An interface for accessing tables from a font (or font-like object)
  • A table that has an associated tag.
  • A trait for types that have variable length.

Type Aliases§