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.
§Related projects
write-fonts
is a companion crate for creating/modifying font filesskrifa
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
- collections
std
- Data structures useful for font work.
- tables
- The various font tables
Structs§
- Array
OfNullable Offsets - An array of nullable offsets that can be resolved on access.
- Array
OfOffsets - An array of offsets that can be resolved on access.
- Collection
Ref - Reference to the content of a font collection file.
- Font
Data - A reference to raw binary font data.
- FontRef
- Reference to an in-memory font.
- Table
Record - Record for a table in a font.
- Table
Ref - Typed access to raw table data.
Enums§
- FileRef
- Reference to the content of a font or font collection file.
- Read
Error - An error that occurs when reading font data
Traits§
- Compute
Size - A type that can compute its size at runtime, based on some input.
- Font
Read - A type that can be read from raw table data.
- Font
Read With Args - A trait for types that require external data in order to be constructed.
- MinByte
Range - Return the minimum range of the table bytes
- Offset
- Any offset type.
- Read
Args - A trait for a type that needs additional arguments to be read.
- Resolve
Nullable Offset - A helper trait providing a ‘resolve’ method for nullable offset types
- Resolve
Offset - A helper trait providing a ‘resolve’ method for offset types
- Table
Provider - An interface for accessing tables from a font (or font-like object)
- TopLevel
Table - A table that has an associated tag.
- VarSize
- A trait for types that have variable length.
Type Aliases§
- TTCHeader
- TTC Header
- Table
Directory - The OpenType Table Directory