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§

pub extern crate font_types as types;

Modules§

array
Custom array types
collectionsstd
Data structures useful for font work.
tables
The various font tables

Structs§

ArrayOfNullableOffsets
An array of nullable offsets that can be resolved on access.
ArrayOfOffsets
An array of offsets that can be resolved on access.
CollectionRef
Reference to the content of a font collection file.
FontData
A reference to raw binary font data.
FontRef
Reference to an in-memory font.
TableRecord
Record for a table in a font.
TableRef
Typed access to raw table data.

Enums§

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

Traits§

ComputeSize
A type that can compute its size at runtime, based on some input.
FontRead
A type that can be read from raw table data.
FontReadWithArgs
A trait for types that require external data in order to be constructed.
MinByteRange
Return the minimum range of the table bytes
Offset
Any offset type.
ReadArgs
A trait for a type that needs additional arguments to be read.
ResolveNullableOffset
A helper trait providing a ‘resolve’ method for nullable offset types
ResolveOffset
A helper trait providing a ‘resolve’ method for offset types
TableProvider
An interface for accessing tables from a font (or font-like object)
TopLevelTable
A table that has an associated tag.
VarSize
A trait for types that have variable length.

Type Aliases§

TTCHeader
TTC Header
TableDirectory
The OpenType Table Directory