Bounds
pub using @model {type Bounds}
Every package is a drawer and every declaration a compartment. The cast line comes from the interface; the note beside it comes from the source.
The façade. One import gives a caller the types, the entry points and the whole vertical slice from bytes to a coverage mask. Every package below is also public, so a caller that only needs charmap lookup or only needs a rasteriser does not have to load the rest.
pub using @model {type Bounds}
pub using @model {type CoverageMask}
pub struct Face {
head : @table.Head
hhea : @table.Hhea
maxp : @table.Maxp
hmtx : @table.Metrics
vhea : @table.Vhea?
vmtx : @table.Metrics?
cmap : @table.Cmap
kern : @table.Kern
os2 : @table.Os2
source : @outline.GlyphSource?
cff : @cff.Font?
fvar : @variations.Fvar?
avar : @variations.Avar?
gvar : @variations.Gvar?
hvar : @variations.MetricDeltas?
vvar : @variations.MetricDeltas?
mvar : @variations.Mvar?
cvar : @variations.Cvar?
cvt : @table.Cvt?
limits : @model.Limits
}
A loaded font face. It owns no bytes it did not borrow: parsing is lazy for glyph outlines, so loading a large font costs a table directory and a few small tables, not every glyph.
pub using @model {type FontMetrics}
pub using @model {type GlyphId}
pub using @model {type GlyphMetrics}
pub using @model {type Limits}
pub using @model {type Outline}
pub using @model {type PathCommand}
pub using @model {type Point}
pub using @model {type Refused}
pub using @model {type Scale}
pub using @model {type TextMetrics}
pub using @model {type VerticalMetrics}
pub let limits : @model.Limits = @model.limits ///| /// The untrusted-input preset. pub let limits_strict : @model.Limits = @model.limits_strict ///| /// The version of the library. pub fn version() -> String
The desktop preset, re-exported so one import reaches every name a caller needs.
pub let limits_strict : @model.Limits = @model.limits_strict ///| /// The version of the library. pub fn version() -> String
The untrusted-input preset.
pub fn decode(bytes : BytesView, limits~ : @model.Limits = @model.limits) -> Face raise @model.Refused
Read the first face of a font file. A collection, a WOFF file and a WOFF2 file all have a first face; decode_all is the entry point for the rest. A caller never chooses an entry point by file extension.
pub fn decode_all(bytes : BytesView, limits~ : @model.Limits = @model.limits) -> Array[Face] raise @model.Refused
Read every face in the file. A plain font yields exactly one.
pub fn decode_from(source : &@sfnt.TableSource, limits~ : @model.Limits = @model.limits) -> Face raise @model.Refused
Build a face from a table source rather than from a file: the entry point for a caller whose tables come from somewhere this library does not read, such as a memory map, a file handle or a fetch that returns one table at a time. decode is this function over the faces a container finds.
pub fn version() -> String
The version of the library.
pub fn Face::advance(self : Face, glyph : @model.GlyphId, location? : @variations.Location) -> Int32
The advance width of one glyph in font units, at a location.
pub fn Face::advance_height(self : Face, glyph : @model.GlyphId, location? : @variations.Location) -> Int32
The advance height of one glyph in font units, at a location: the step from one glyph to the next in a column. A font without vmtx advances by its em, which is what a vertical layout does with a font that only describes horizontal text.
pub fn Face::at(self : Face, values : Array[(Int32, Int32)]) -> @variations.Location
A location on this face, from user-space axis values in 16.16 fixed point. An axis the caller does not name keeps its default, and a font without axes ignores every one of them.
pub fn Face::axes(self : Face) -> Array[@variations.Axis]
The axes a caller may set. Empty for a font that does not vary.
pub fn Face::cvt(self : Face, location? : @variations.Location) -> Array[Int32] raise @model.Refused
The control values of the font, in font units, moved to a location by cvar. Empty for a font without a cvt table. A caller that hints reads these as the distances its programs snap to.
pub fn Face::font_metrics(self : Face, location? : @variations.Location) -> @model.FontMetrics
Font-wide metrics, in font units. At a location, MVAR moves the vertical extent and the one-off heights: a face whose bold master is taller reports that height here rather than at the default instance only.
pub fn Face::glyph_for(self : Face, character : Char) -> @model.GlyphId?
Translate a character to a glyph id.
pub fn Face::glyph_index(self : Face, codepoint : Int32) -> @model.GlyphId?
Translate a Unicode codepoint to a glyph id. None means the font has no glyph; a caller decides what to draw in its place.
pub fn Face::has_vertical_metrics(self : Face) -> Bool
Whether the font carries vertical metrics of its own.
pub fn Face::instances(self : Face) -> Array[@variations.Instance]
The named instances the font offers, in fvar order.
pub fn Face::is_postscript(self : Face) -> Bool
Whether the outlines are PostScript (CFF or CFF2) rather than TrueType.
pub fn Face::is_variable(self : Face) -> Bool
Whether the font varies, and therefore whether an outline is a function of a location rather than a constant.
pub fn Face::kern_between(self : Face, left : @model.GlyphId, right : @model.GlyphId) -> Int32
The legacy kern adjustment between two glyphs, in font units. Zero for fonts that carry kerning only in GPOS, which this library does not shape.
pub fn Face::location(self : Face) -> @variations.Location
The default instance: every axis at its default, which is where a font without variation tables sits.
pub fn Face::measure(self : Face, text : String, pixels_per_em : Int32, letter_spacing? : Int32, location? : @variations.Location) -> @model.TextMetrics
Measure a run of text at a pixel size. Unknown codepoints are skipped, so the returned glyphs count can be smaller than the character count.
pub fn Face::metric_tags(self : Face) -> Array[Int32]
The MVAR value tags this face varies: empty for a font without the table, otherwise the tags as four-character words.
pub fn Face::metrics(self : Face, glyph : @model.GlyphId, location? : @variations.Location) -> @model.GlyphMetrics raise @model.Refused
Horizontal metrics of one glyph, in font units.
pub fn Face::num_glyphs(self : Face) -> Int32
How many glyphs the font declares.
pub fn Face::outline(self : Face, glyph : @model.GlyphId, location? : @variations.Location) -> @model.Outline raise @model.Refused
The outline of one glyph, in font units, as path commands. Curves are kept as curves; flattening is the rasteriser's decision. At a location, the glyph is the instance the design describes there.
pub fn Face::rasterise(self : Face, glyph : @model.GlyphId, pixels_per_em : Int32, location? : @variations.Location) -> @model.CoverageMask raise @model.Refused
Eight-bit coverage of one glyph at a pixel size. The mask carries its own origin, so it can be copied into an atlas without further arithmetic.
pub fn Face::scale(self : Face, pixels_per_em : Int32) -> @model.Scale
The scale for a pixel size, shared by measurement and rasterisation so the two never disagree about where the pen stands.
pub fn Face::top_side_bearing(self : Face, glyph : @model.GlyphId, location? : @variations.Location) -> Int32
The top side bearing of one glyph, in font units: the distance from the top of a column to the ink.
pub fn Face::units_per_em(self : Face) -> Int32
The units in which outlines and advances are measured.
pub fn Face::vertical_metrics(self : Face, location? : @variations.Location) -> @model.VerticalMetrics
The measurements of a column, in font units. A font without vhea gets the horizontal ones, so a caller that sets text vertically never has to ask whether the vertical pair exists.
Copyright 2026 Leo Cheng SPDX-License-Identifier: Apache-2.0
pub struct Dict {
mut char_strings : Int32
mut charstring_type : Int32
mut private_size : Int32
mut private_offset : Int32
mut subrs : Int32
mut fd_array : Int32
mut fd_select : Int32
mut vstore : Int32
mut vsindex : Int32
mut matrix_scale : Int32
mut matrix_set : Bool
mut is_cid : Bool
}
a of FontMatrix in 16.16, already multiplied by units per em.The dictionaries this reader needs, flattened. Every operand that does not appear keeps the value a PostScript reader would assume.
pub struct Font {
data : BytesView
is_cff2 : Bool
top : Dict
char_strings : Index
gsubrs : Index
locals : Array[Index]
fds : Array[Int32]
matrix_scale : Int32
var_store : @variations.Store?
default_vsindex : Int32
}
A PostScript-outline font. Opaque: a caller asks for an outline or a glyph count, not for the table's internals.
pub(all) struct Index {
data : BytesView
starts : Array[Int32]
}
count + 1 absolute offsets; item i spans [starts[i], starts[i + 1]).One INDEX, resolved to absolute offsets into the table it came from. An empty INDEX has no offsets at all, which is legal and common for local subroutines.
pub let call_depth : Int32 = 10 ///| /// The most operators one glyph may run. A charstring's bytes bound its own /// work, but a subroutine chain can revisit them, so the ceiling is explicit /// rather than implied by the table size. pub let ops_per_glyph : Int32 = 65_536 ///| priv struct Interp
How deep a charstring may call subroutines. The Type 2 specification's own ceiling is ten; a deeper chain is a damaged file.
pub let ops_per_glyph : Int32 = 65_536 ///| priv struct Interp
The most operators one glyph may run. A charstring's bytes bound its own work, but a subroutine chain can revisit them, so the ceiling is explicit rather than implied by the table size.
pub fn Font::glyph_count(self : Font) -> Int32
pub fn Font::is_variable(self : Font) -> Bool
Whether the font has a variation store, which only CFF 2 does.
pub fn Font::outline(self : Font, glyph : Int32, coords : Array[Int32]) -> @model.Outline raise @model.Refused
The outline of one glyph, with the variation coordinates applied when the font has a store. Coordinates are in font units.
pub fn Font::parse(cursor : @wire.Cursor, is_cff2 : Bool, units_per_em : Int32, limits : @model.Limits) -> Font raise @model.Refused
pub fn Index::count(self : Index) -> Int32
pub fn Index::item(self : Index, index : Int32) -> BytesView
One item, or an empty view past the end. A caller that asks for a glyph the INDEX does not have gets an empty charstring rather than a trap, and the outline layer renders it as a blank glyph.
pub fn Index::parse(cursor : @wire.Cursor, wide : Bool, limits : @model.Limits) -> Index raise @model.Refused
Text measurement, not shaping. It sums advances and applies legacy kerning as data. Bidi, line breaking, GSUB/GPOS and syllable clustering are out of scope by design: those are a different library's problem.
pub fn measure(glyphs : Array[@model.GlyphId], advance_of : (Int32) -> Int32, font : @model.FontMetrics, scale : @model.Scale, kern : @table.Kern, letter_spacing? : Int32) -> @model.TextMetrics
The horizontal extent of a run of glyph ids, plus the font's vertical rhythm at the same size. Advances come from a function rather than a table because a variable font's advance depends on the location, and a caller that has no variation injects the constant width of the default instance.
The domain model: the vocabulary every other layer speaks. It knows nothing about bytes, tables, scanlines or pixels, and depends on nothing but the built-in library.
pub(all) struct Bounds {
x_min : Int32
y_min : Int32
x_max : Int32
y_max : Int32
}
An axis-aligned box in font units.
pub(all) struct CoverageMask {
width : Int32
height : Int32
left : Int32
top : Int32
samples : FixedArray[Byte]
}
Eight-bit coverage of one glyph, top-down rows, left-to-right columns. left and top place the box relative to the pen in whole pixels, top counted upwards, so a caller can blit it into an atlas without recomputing the origin.
pub(all) struct FontMetrics {
units_per_em : Int32
ascent : Int32
descent : Int32
line_gap : Int32
cap_height : Int32
x_height : Int32
num_glyphs : Int32
bounding_box : Bounds
}
Font-wide metrics, in font units. All vertical values keep the font's y-up sign: descent is negative in a well-formed font.
pub(all) struct GlyphId {
index : Int32
}
A glyph's index in the font. Codepoints are not glyphs: translation belongs to the charmap, and everything downstream speaks only this.
pub(all) struct GlyphMetrics {
advance : Int32
left_side_bearing : Int32
bounds : Bounds
}
Horizontal metrics of one glyph, in font units.
pub(all) struct Limits {
file_bytes : Int32
table_bytes : Int32
glyphs : Int32
points : Int32
contours : Int32
composites : Int32
recursion : Int32
mask_pixels : Int32
}
The ceilings a reader works under. limits is the preset for an application's own assets; limits_strict is for bytes from somewhere else. A record built by hand is honoured as given: a caller who raises a ceiling has said what it is willing to spend.
pub(all) struct Outline {
commands : Array[PathCommand]
bounds : Bounds
}
A glyph outline: a command stream and the box the font declared for it. The declared box is kept separate from the measured extent of the commands, because metrics and coverage are not obliged to agree with each other.
pub(all) enum PathCommand {
MoveTo(Point)
LineTo(Point)
QuadTo(Point, Point)
CubicTo(Point, Point, Point)
Close
}
One step of an outline. Quadratic and cubic segments are kept as they are in the file: flattening is a rasteriser's decision, not a parser's. A consumer that wants SVG, a GPU tessellator or an SDF gets the same commands.
pub(all) struct Point {
x : Int32
y : Int32
}
A point in font units, with the font's own y-up orientation.
pub(all) suberror Refused {
Unknown(at~ : Int32, got~ : String)
Unexpected(at~ : Int32, got~ : String, want~ : String)
Unsupported(at~ : Int32, got~ : String)
Truncated(at~ : Int32, want~ : Int32)
OverLimit(limit~ : Int32, got~ : Int32)
Malformed(at~ : Int32, got~ : String)
MissingTable(tag~ : String)
MissingGlyph(glyph~ : Int32)
Recursion(depth~ : Int32)
}
maxp.numGlyphs.want short of where the format needs them.at are not allowed here; want says what would be.at is not one this library reads.A refusal to read bytes as a font, or to turn a glyph into a bitmap.
pub(all) struct Scale {
ppem : Int32
units_per_em : Int32
}
A size in 26.6 fixed point. The whole library computes with integers: a rasteriser that used floating point would produce different coverage on wasm, js and native for the same bytes, and a differential test could not say what the right answer is. The same scale serves measurement and rasterisation, so the two never disagree about where the pen stands, and a variable font's instance is resolved before a scale is applied.
pub(all) struct TextMetrics {
advance : Int32
ascent : Int32
descent : Int32
line_gap : Int32
glyphs : Int32
}
The measured shape of a run of text, in 26.6 pixels.
pub(all) struct VerticalMetrics {
ascent : Int32
descent : Int32
line_gap : Int32
}
The measurements of a column, in font units, for a font that sets text vertically. A font without vhea reports the horizontal metrics here, so a caller never branches on whether the vertical tables exist.
pub impl Show for Refused
pub let limits : Limits =
Desktop and server defaults: generous, but finite at every declaration.
pub let limits_strict : Limits =
What a service handling untrusted uploads would choose: a sixteenth of the file ceiling, an eighth of the points, and a mask that fits a 2048-pixel square.
pub fn Bounds::empty() -> Bounds
pub fn Bounds::equal(Self, Self) -> Bool
pub fn Bounds::height(self : Bounds) -> Int32
pub fn Bounds::is_empty(self : Bounds) -> Bool
pub fn Bounds::not_equal(Self, Self) -> Bool
pub fn Bounds::to_repr(Self) -> @debug.Repr
pub fn Bounds::width(self : Bounds) -> Int32
pub fn CoverageMask::at(self : CoverageMask, x : Int32, y : Int32) -> Int32
The coverage at x, y, from 0 to 255. Out of the box is transparent.
pub fn CoverageMask::of(width : Int32, height : Int32, left : Int32, top : Int32, samples : FixedArray[Byte]) -> CoverageMask
pub fn GlyphId::equal(Self, Self) -> Bool
pub fn GlyphId::not_equal(Self, Self) -> Bool
pub fn GlyphId::of(index : Int32) -> GlyphId
pub fn GlyphId::to_int(self : GlyphId) -> Int32
pub fn GlyphId::to_repr(Self) -> @debug.Repr
pub fn Limits::check_composites(self : Limits, count : Int32) -> Unit raise Refused
pub fn Limits::check_depth(self : Limits, depth : Int32) -> Unit raise Refused
pub fn Limits::check_file(self : Limits, size : Int32) -> Unit raise Refused
pub fn Limits::check_glyphs(self : Limits, count : Int32) -> Unit raise Refused
pub fn Limits::check_mask(self : Limits, width : Int32, height : Int32) -> Unit raise Refused
The pixel count is multiplied in 64 bits so that a declared 65535 by 65535 cannot wrap into a small number and slip through.
pub fn Limits::check_outline(self : Limits, points : Int32, contours : Int32) -> Unit raise Refused
pub fn Limits::check_table(self : Limits, size : Int32) -> Unit raise Refused
pub fn Limits::new(file_bytes~ : Int32 = limits.file_bytes, table_bytes~ : Int32 = limits.table_bytes, glyphs~ : Int32 = limits.glyphs, points~ : Int32 = limits.points, contours~ : Int32 = limits.contours, composites~ : Int32 = limits.composites, recursion~ : Int32 = limits.recursion, mask_pixels~ : Int32 = limits.mask_pixels) -> Limits
Limits by name, every knob defaulted from the preset. Use this rather than a record literal when only one ceiling changes: a later field added to the record then keeps its default instead of failing to compile.
pub fn Outline::bounds(self : Outline) -> Bounds
pub fn Outline::commands(self : Outline) -> Array[PathCommand]
pub fn Outline::is_empty(self : Outline) -> Bool
pub fn Outline::of(commands : Array[PathCommand], bounds : Bounds) -> Outline
pub fn PathCommand::equal(Self, Self) -> Bool
pub fn PathCommand::not_equal(Self, Self) -> Bool
pub fn PathCommand::to_repr(Self) -> @debug.Repr
pub fn Point::equal(Self, Self) -> Bool
pub fn Point::not_equal(Self, Self) -> Bool
pub fn Point::of(x : Int32, y : Int32) -> Point
pub fn Point::to_repr(Self) -> @debug.Repr
pub fn Refused::equal(Self, Self) -> Bool
pub fn Refused::name(self : Refused) -> String
The variant name. A differential test records this rather than a rendered message, because the prose may change while the contract does not. The text is stable and part of the public interface.
pub fn Refused::not_equal(Self, Self) -> Bool
pub fn Refused::output(Self, &Logger) -> Unit
pub fn Refused::to_repr(Self) -> @debug.Repr
pub fn Refused::to_string(Self) -> String
pub fn Scale::apply(self : Scale, units : Int32) -> Int32
Font units to 26.6 pixels. The product is taken in 64 bits so a large coordinate at a large size cannot wrap.
pub fn Scale::of(pixels_per_em : Int32, units_per_em : Int32) -> Scale
pub fn Scale::ppem(self : Scale) -> Int32
Geometry, not pixels. A TrueType glyph is a set of points and an on-curve bit; this layer turns those into a path command stream and resolves composite glyphs. Nothing here decides how a curve is flattened.
pub(all) struct GlyphSource {
glyf : BytesView
loca : @table.Loca
limits : @model.Limits
}
Everything needed to turn a glyph id into an outline, without owning the font: the glyf bytes, the glyph boundaries and the caller's ceilings.
pub fn simple_outline(glyph : @table.SimpleGlyph, deltas? : Array[(Int32, Int32)]) -> @model.Outline
The path of one simple glyph, with the deltas of the instance applied when the caller has a location. deltas is one vector per point, in the glyph's own order; the phantom points at its end are not drawn.
pub fn GlyphSource::coordinates(self : GlyphSource, glyph : @model.GlyphId) -> Array[(Int32, Int32)] raise @model.Refused
The points of a glyph as they stand in the file, phantom points excluded. A composite glyph's "points" are its component offsets, which is what a gvar tuple names.
pub fn GlyphSource::ends(self : GlyphSource, glyph : @model.GlyphId) -> Array[Int32] raise @model.Refused
The contour ends of a simple glyph, or one end per component of a composite. gvar interpolates inside a contour, so it needs this to know where a contour stops.
pub fn GlyphSource::of(glyf : BytesView, loca : @table.Loca, limits : @model.Limits) -> GlyphSource
pub fn GlyphSource::outline(self : GlyphSource, glyph : @model.GlyphId, depth? : Int32, variation? : @variations.Gvar, coords? : Array[Int32]) -> @model.Outline raise @model.Refused
The outline of one glyph. Composite components are resolved recursively; the depth ceiling is checked before each descent, so a cyclic component chain is refused rather than looping.
variation and coords come as a pair: a normalised location without a gvar table moves nothing, and a table without a location is the default instance.
pub fn GlyphSource::phantom_deltas(self : GlyphSource, glyph : @model.GlyphId, variation : @variations.Gvar, coords : Array[Int32]) -> (Int32, Int32) raise @model.Refused
How far a location moves this glyph's side bearing and advance, from the four phantom points. A font with HVAR states the advance itself; this is for the fonts that leave it to gvar.
pub fn GlyphSource::points(self : GlyphSource, glyph : @model.GlyphId) -> Int32 raise @model.Refused
How many points a glyph has, phantom points excluded. A caller that needs the count without the outline — measurement, or a delta request — asks here rather than parsing the glyph twice.
The one place that decides how geometry becomes coverage. It consumes path commands and knows nothing about SFNT, tables, charmaps or files. Dependency contract: this package may import only model. The raster -> model direction is a hard rule (LD-01); the CI gate that enforces it is not yet present in 0.1.x, so reviewers must check imports by hand.
pub fn rasterise(outline : @model.Outline, scale : @model.Scale, limits : @model.Limits) -> @model.CoverageMask raise @model.Refused
Turn an outline into eight-bit coverage at scale.
Each pixel row is sampled at eight vertical positions. At each of them the edges crossing that line are intersected, sorted and paired by non-zero winding; the horizontal span between a pair is accumulated into the pixels it covers as an exact 26.6 length. Eight samples times 64 units per pixel is 512, so the final scaling to 0..255 is exact and integer.
The SFNT container only: signatures, the table directory, and TrueType collections. It knows where tables are, never what is inside them.
pub struct Sfnt {
}
The plain sfnt container: a single font or a TrueType collection, whose table directories are already where the readers expect them.
pub(all) struct TableSet {
scaler : Int32
bytes : BytesView
tags : Array[Int32]
offsets : Array[Int32]
lengths : Array[Int32]
}
One face: the tables a container found, each a range of one buffer.
The ranges may overlap and may be shared with another TableSet — that is what a collection is — so this type never rewrites its buffer. A container that has to expand its tables builds one buffer and hands every face a view of it.
pub(open) trait Container {
fn name(Self) -> String
fn claims(Self, Int32) -> Bool
fn open(Self, BytesView, @model.Limits) -> Array[TableSet] raise @model.Refused
}
pub(open) trait TableSource {
fn scaler(Self) -> Int32
fn has(Self, Int32) -> Bool
fn table_bytes(Self, Int32, @model.Limits) -> BytesView raise @model.Refused
}
pub impl Container for Sfnt
pub impl TableSource for TableSet
pub fn assemble(scaler : Int32, tables : Array[(Int32, BytesView)], limits : @model.Limits) -> TableSet raise @model.Refused
Collect tables into one buffer and describe them as a face.
A container that expands its tables — WOFF and WOFF2 both do — ends up with owned bytes per table and no file to point into. Copying them into one buffer, four-byte aligned, gives a face whose tables are as cheap to read as a plain file's, and costs one pass over bytes that were decompressed anyway.
pub fn assemble_collection(scaler : Int32, faces : Array[Array[(Int32, BytesView)]], limits : @model.Limits) -> Array[TableSet] raise @model.Refused
One buffer assembled from the tables of several faces, so that a collection shares the tables its faces have in common. Returns one TableSet per face, all pointing into the same buffer.
pub fn read(bytes : BytesView, limits : @model.Limits) -> Array[TableSet] raise @model.Refused
Read every face in an sfnt buffer: a plain font yields one, a TrueType collection yields one per face. A caller never has to branch on which.
pub fn scaler_of(bytes : BytesView) -> Int32?
The sfnt version word of a buffer, or None when the buffer is too short to carry one or opens with something that is not an sfnt scaler.
pub fn table_cursor(source : &TableSource, tag : Int32, limits : @model.Limits) -> @wire.Cursor raise @model.Refused
A cursor bounded to one table. This is the only way a table decoder gets to read, which is why no decoder has to check that an offset stayed inside its own table.
pub fn tag_avar() -> Int32
pub fn tag_cff() -> Int32
pub fn tag_cff2() -> Int32
pub fn tag_cmap() -> Int32
pub fn tag_cpht() -> Int32
pub fn tag_cvar() -> Int32
pub fn tag_cvt() -> Int32
pub fn tag_fvar() -> Int32
pub fn tag_glyf() -> Int32
pub fn tag_gvar() -> Int32
pub fn tag_hasc() -> Int32
The MVAR value tags this library applies. They are four-character words like table tags, and they name the metric a delta moves rather than a table.
pub fn tag_hcla() -> Int32
pub fn tag_hcld() -> Int32
pub fn tag_hcof() -> Int32
pub fn tag_hcrn() -> Int32
pub fn tag_hcrs() -> Int32
pub fn tag_hdsc() -> Int32
pub fn tag_head() -> Int32
Table tags are four ASCII bytes held as a word. Comparison stays integer comparison, and no string has to be built to find a table.
pub fn tag_hhea() -> Int32
pub fn tag_hlgp() -> Int32
pub fn tag_hmtx() -> Int32
pub fn tag_hvar() -> Int32
pub fn tag_kern() -> Int32
pub fn tag_loca() -> Int32
pub fn tag_maxp() -> Int32
pub fn tag_mvar() -> Int32
pub fn tag_name() -> Int32
pub fn tag_os2() -> Int32
pub fn tag_post() -> Int32
pub fn tag_string(tag : Int32) -> String
A readable name for a refusal message; never built during a table lookup.
pub fn tag_undo() -> Int32
pub fn tag_unds() -> Int32
pub fn tag_vasc() -> Int32
pub fn tag_vcof() -> Int32
pub fn tag_vcrn() -> Int32
pub fn tag_vcrs() -> Int32
pub fn tag_vdsc() -> Int32
pub fn tag_vhea() -> Int32
pub fn tag_vlgp() -> Int32
pub fn tag_vmtx() -> Int32
pub fn tag_vorg() -> Int32
pub fn tag_vvar() -> Int32
pub fn tag_xhgt() -> Int32
pub fn Sfnt::new() -> Sfnt
pub fn TableSet::has(self : TableSet, tag : Int32) -> Bool
pub fn TableSet::table_bytes(self : TableSet, tag : Int32, limits : @model.Limits) -> BytesView raise @model.Refused
The bytes of one table, without copying. The view is exactly the table, so an offset inside the table is an offset inside the view.
pub fn TableSet::tags(self : TableSet) -> Array[Int32]
The tags this face carries, ascending.
Table decoders. Each one turns a bounded cursor into domain values and stops there: no outline commands are built here, and no pixel is touched here.
pub(all) struct Cmap {
data : BytesView
chosen : Int32
format : Int32
}
pub(all) struct Component {
glyph_index : Int32
dx : Int32
dy : Int32
a : Int32
b : Int32
c : Int32
d : Int32
}
One reference in a composite glyph. a, b, c and d are F2Dot14 values (16384 is 1.0); dx and dy are in font units.
pub(all) struct CompositeGlyph {
components : Array[Component]
bounds : @model.Bounds
}
pub(all) struct Cvt {
values : Array[Int32]
}
cvt : the control values a hinting program snaps distances to. They are plain integers here, and cvar says how they move at a location.
pub(all) enum GlyphData {
Empty
Simple(SimpleGlyph)
Composite(CompositeGlyph)
}
pub(all) struct Head {
units_per_em : Int32
index_to_loc_format : Int32
mac_style : Int32
lowest_rec_ppem : Int32
bounding_box : @model.Bounds
}
head: the font-wide scale and the shape of the loca table.
pub(all) struct Hhea {
ascender : Int32
descender : Int32
line_gap : Int32
number_of_h_metrics : Int32
}
hhea: the vertical rhythm and the width of one hmtx long metric.
pub(all) struct Kern {
pairs : Array[(Int32, Int32, Int32)]
}
pub(all) struct Loca {
offsets : Array[Int32]
}
loca: one offset per glyph boundary, in either short or long form.
pub(all) struct Maxp {
num_glyphs : Int32
max_points : Int32
max_contours : Int32
max_composite_points : Int32
max_composite_contours : Int32
}
maxp: how many glyphs the file claims to have.
pub(all) struct Metrics {
advances : Array[Int32]
bearings : Array[Int32]
}
hmtx and vmtx: one advance and one side bearing per glyph, with the tail glyphs repeating the last advance the table stores. The two tables have the same layout, so one reader serves both; which side a bearing is on depends on the table, and the caller knows that.
pub(all) struct Os2 {
weight_class : Int32
width_class : Int32
x_height : Int32
cap_height : Int32
typo_ascender : Int32
typo_descender : Int32
typo_line_gap : Int32
}
pub(all) struct SimpleGlyph {
end_points : Array[Int32]
points : Array[@model.Point]
on_curve : Array[Bool]
bounds : @model.Bounds
}
pub(all) struct Vhea {
ascender : Int32
descender : Int32
line_gap : Int32
advance_height_max : Int32
caret_slope_rise : Int32
caret_slope_run : Int32
caret_offset : Int32
number_of_long_metrics : Int32
}
vmtx table stores a full pair for.vhea: the vertical header. Same offsets as hhea for the four fields this library reads, which is why the two readers look alike.
pub fn Cmap::format(self : Cmap) -> Int32
pub fn Cmap::glyph_index(self : Cmap, codepoint : Int32) -> @model.GlyphId?
Translate a Unicode codepoint to a glyph id, or None when the font has no glyph for it. .notdef is deliberately NOT returned: a caller decides whether to show a missing-glyph box.
pub fn Cmap::parse(cursor : @wire.Cursor, limits : @model.Limits) -> Cmap raise @model.Refused
pub fn Cvt::parse(cursor : @wire.Cursor, limits : @model.Limits) -> Cvt raise @model.Refused
pub fn GlyphData::parse(view : BytesView, limits : @model.Limits) -> GlyphData raise @model.Refused
Decode one glyph's bytes. An empty range is a space or an empty glyph, not an error: asking for its outline yields no commands and asking for its mask yields a zero-sized mask.
pub fn Head::parse(cursor : @wire.Cursor) -> Head raise @model.Refused
pub fn Hhea::parse(cursor : @wire.Cursor) -> Hhea raise @model.Refused
pub fn Kern::between(self : Kern, left : Int32, right : Int32) -> Int32
The adjustment between two glyphs, in font units. Zero when there is none.
pub fn Kern::count(self : Kern) -> Int32
pub fn Kern::empty() -> Kern
pub fn Kern::parse(cursor : @wire.Cursor, limits : @model.Limits) -> Kern raise @model.Refused
pub fn Loca::count(self : Loca) -> Int32
pub fn Loca::parse(cursor : @wire.Cursor, num_glyphs : Int32, index_to_loc_format : Int32, limits : @model.Limits) -> Loca raise @model.Refused
pub fn Loca::range(self : Loca, glyph : Int32) -> (Int32, Int32)?
The half-open byte range of one glyph inside glyf. An empty range is a space, a combining mark built entirely from components, or an empty glyph.
pub fn Maxp::parse(cursor : @wire.Cursor, limits : @model.Limits) -> Maxp raise @model.Refused
pub fn Metrics::metrics(self : Metrics, glyph : Int32) -> (Int32, Int32)
pub fn Metrics::parse(cursor : @wire.Cursor, num_glyphs : Int32, long_metrics : Int32, limits : @model.Limits) -> Metrics raise @model.Refused
Read an hmtx or vmtx table. long_metrics is the count the header of the matching hhea or vhea declares.
pub fn Os2::empty() -> Os2
pub fn Os2::parse(cursor : @wire.Cursor) -> Os2 raise @model.Refused
pub fn Vhea::parse(cursor : @wire.Cursor) -> Vhea raise @model.Refused
What a variable font varies: axes, named instances, deltas per glyph, and the item-variation store the other tables share. It turns user coordinates into the normalised F2Dot14 space every table speaks, and nothing here knows what a glyph or a table directory looks like.
pub(all) struct Avar {
maps : Array[Array[(Int32, Int32)]]
}
The per-axis segment maps.
pub(all) struct Axis {
tag : Int32
min : Int32
default_value : Int32
max : Int32
flags : Int32
name_id : Int32
}
One axis, in user space. min, default_value and max are 16.16 fixed point, so 14.5 is 950_272 and 1.0 is 65_536.
pub(all) struct Cvar {
data : BytesView
axis_count : Int32
tuple_count : Int32
data_at : Int32
shared_points : Bool
}
The cvar table.
pub(all) struct DeltaMap {
data : BytesView
entries_at : Int32
count : Int32
entry_size : Int32
inner_bits : Int32
}
A map from a glyph id to the two-level index of the variation store.
pub(all) struct Fvar {
axes : Array[Axis]
instances : Array[Instance]
}
The fvar table.
pub struct Gvar {
data : BytesView
axis_count : Int32
shared_at : Int32
shared_count : Int32
glyph_count : Int32
offsets : Array[Int32]
offset_to_data : Int32
}
offset_to_data.The gvar table, read on demand. Glyph variation data is never decoded at load time: a caller that stays at the default instance never pays for it.
pub(all) struct Instance {
subfamily_name_id : Int32
coords : Array[Int32]
}
fvar order.One named instance: a point in the design space and the name to show.
pub(all) struct Location {
coords : Array[Int32]
}
A point in the design space, one 16.16 user-space value per axis. Holding user values rather than normalised ones means a caller can show the number it set, and the axis order is the only thing it has to agree with fvar about.
pub(all) struct MetricDeltas {
store : Store
advance : DeltaMap?
bearing : DeltaMap?
side : DeltaMap?
}
HVAR, height for VVAR.HVAR, top side bearing for VVAR.A metrics variation table: an item variation store and up to three maps, one per metric the table may move.
pub(all) struct Mvar {
store : Store
records : Array[(Int32, Int32, Int32)]
}
(tag, outer, inner) per record, in the order the table declares them.The MVAR table.
pub(all) struct Region {
coordinates : Array[Int32]
}
3 * axis_count values, start/peak/end per axis.One region of the store: three F2Dot14 values per axis, the start, peak and end of the tent.
pub(all) struct Store {
data : BytesView
region_axis_count : Int32
regions : Array[Region]
items : Array[Int32]
}
The parsed store. data is the whole table section the store lives in, and offsets inside it are relative to the store's own start, so a caller can hand over a cursor bounded to the table.
pub fn scale_f2dot14(value : Int32, factor : Int32) -> Int32
Multiply by an F2Dot14 factor, rounding to nearest. Used for the scalar of one variation tuple applied to one delta.
pub fn scale_fixed(value : Int32, factor : Int32) -> Int32
Multiply by a 16.16 factor, rounding to nearest.
pub fn tag_name(tag : Int32) -> String
The four characters of a tag. Bytes outside printable ASCII become ? so a hostile tag cannot break a caller's layout.
pub fn tag_of(text : String) -> Int32
A four-character tag as a word, so a lookup compares integers.
pub fn Avar::map_axis(self : Avar, axis : Int32, value : Int32) -> Int32
Apply the segment map of one axis. A coordinate outside the first and last pair keeps its distance from that pair's output, which is how avar extends a map past its own ends. An empty map is the identity.
pub fn Avar::parse(cursor : @wire.Cursor, axis_count : Int32, limits : @model.Limits) -> Avar raise @model.Refused
pub fn Axis::tag_name(self : Axis) -> String
pub fn Cvar::deltas(self : Cvar, point_count : Int32, normalised : Array[Int32]) -> Array[Int32] raise @model.Refused
The delta of every control value at a normalised location, in font units. The result has one entry per value of cvt ; values no tuple names keep zero, which is what the format means by leaving them out.
pub fn Cvar::parse(cursor : @wire.Cursor, axis_count : Int32, limits : @model.Limits) -> Cvar raise @model.Refused
pub fn DeltaMap::parse(data : BytesView, at : Int32, limits : @model.Limits) -> DeltaMap? raise @model.Refused
Read a map at at. None means the table named no map there, which the format uses to say "the glyph id is the index".
pub fn DeltaMap::resolve(self : DeltaMap, glyph : Int32) -> (Int32, Int32)
The store index of a glyph. A glyph past the end of the map uses its last entry, which is what the format intends for a map that covers fewer glyphs than the font has.
pub fn Fvar::parse(cursor : @wire.Cursor, limits : @model.Limits) -> Fvar raise @model.Refused
pub fn Gvar::deltas(self : Gvar, glyph : Int32, point_count : Int32, ends : Array[Int32], coords : Array[(Int32, Int32)], normalised : Array[Int32]) -> Array[(Int32, Int32)] raise @model.Refused
Per-point deltas of one glyph at a normalised location, in font units. point_count includes the four phantom points the metrics use; ends are the last point index of each contour, and for a composite glyph they are the component indices, so a component's offset moves as its own one-point contour.
pub fn Gvar::parse(cursor : @wire.Cursor, glyph_count : Int32, limits : @model.Limits) -> Gvar raise @model.Refused
pub fn Location::at(self : Location, fvar : Fvar, axis : Int32) -> Int32
Read one axis by its four-character tag.
pub fn Location::default(fvar : Fvar) -> Location
The default instance: every axis at its fvar default.
pub fn Location::get(self : Location, index : Int32) -> Int32
Read one axis value.
pub fn Location::normalise(self : Location, fvar : Fvar, avar? : Avar) -> Array[Int32]
The normalised F2Dot14 coordinates every table interpolates with, after the axis map in avar if the font has one. Values outside the axis range are clamped: a caller that asks for 1000 weight in a 100..900 axis gets the heaviest instance rather than an extrapolation.
pub fn Location::of(fvar : Fvar, values : Array[(Int32, Int32)]) -> Location
A location from user-space axis values. Axes the caller does not name keep their default; an unknown tag is ignored, because a design may be driven by an application that knows more axes than this font has.
pub fn Location::set(self : Location, fvar : Fvar, axis : Int32, value : Int32) -> Unit
Set one axis by its four-character tag.
pub fn Location::set_axis(self : Location, index : Int32, value : Int32) -> Unit
Set one axis by index.
pub fn MetricDeltas::advance_delta(self : MetricDeltas, glyph : Int32, coords : Array[Int32]) -> Int32
The advance delta of one glyph at a location, in font units.
pub fn MetricDeltas::bearing_delta(self : MetricDeltas, glyph : Int32, coords : Array[Int32]) -> Int32
The leading side-bearing delta of one glyph, in font units.
pub fn MetricDeltas::parse(cursor : @wire.Cursor, limits : @model.Limits) -> MetricDeltas raise @model.Refused
Read HVAR or VVAR. Both start with a version, the offset of their item variation store and three map offsets; a version this library does not know is refused rather than guessed at.
pub fn MetricDeltas::side_delta(self : MetricDeltas, glyph : Int32, coords : Array[Int32]) -> Int32
The trailing side-bearing delta of one glyph, in font units.
pub fn Mvar::delta(self : Mvar, tag : Int32, coords : Array[Int32]) -> Int32
How much one metric moves at a location, in font units. Zero for a tag the table does not carry, which makes a caller's arithmetic the same whether the font varies the metric or not.
pub fn Mvar::parse(cursor : @wire.Cursor, limits : @model.Limits) -> Mvar raise @model.Refused
pub fn Mvar::tags(self : Mvar) -> Array[Int32]
The tags this table carries, ascending, so a caller can see what a font varies without asking for each one.
pub fn Region::scalar(self : Region, axis_count : Int32, coords : Array[Int32]) -> Int32
The F2Dot14 scalar of one region at a normalised location, 1.0 being 16384. A peak of zero means the axis does not take part, which is how a delta can be restricted to a single axis.
pub fn Store::blend(self : Store, index : Int32, deltas : Array[Int32], coords : Array[Int32]) -> Int32
A run of per-region deltas applied at a location: what a CFF 2 blend operand needs.
pub fn Store::delta(self : Store, index : Int32, item : Int32, coords : Array[Int32]) -> Int32
One item's contribution at a location: the sum of its deltas times the scalar of the region each one belongs to.
pub fn Store::parse(cursor : @wire.Cursor, limits : @model.Limits) -> Store raise @model.Refused
pub fn Store::region_count(self : Store, index : Int32) -> Int32
How many regions one item of index blends. CFF2 needs this to know how many deltas to pop per operand before it can blend them.
The web adapter. It re-exposes moonfont through a flat surface that a browser caller can use without constructing or introspecting MoonBit structs: every entry point takes and returns only primitives, Bytes or Strings. The CoverageMask and FontMetrics records it returns are read by field from JavaScript.
This package is a foreign library so the JS and WASM backends emit a loadable module whose named exports are the browser-facing surface below. Each export is pinned with #export_name so the names survive minification and are stable across backends.
pub fn decode(bytes : Bytes) -> @moonfont.Face raise @moonfont.Refused
Decode a font from its bytes. Raises on input the library refuses.
pub fn font_metrics(face : @moonfont.Face) -> @moonfont.FontMetrics
Font-wide metrics as plain integers, in font units.
pub fn glyph_index(face : @moonfont.Face, codepoint : Int32) -> Int32
The glyph id for a Unicode codepoint, or -1 when the font has no glyph.
pub fn metrics(face : @moonfont.Face, glyph : Int32) -> @moonfont.GlyphMetrics raise @moonfont.Refused
One glyph's advance and left side bearing, in font units, plus the box of its ink. Raises on a glyph id the face does not have.
pub fn num_glyphs(face : @moonfont.Face) -> Int32
The number of glyphs in the face.
pub fn outline_svg(face : @moonfont.Face, glyph : Int32) -> String raise @moonfont.Refused
One glyph's outline as an SVG path in font units, with y flipped so it draws correctly in SVG space. Used for vector display and for 3D extrusion.
pub fn rasterise(face : @moonfont.Face, glyph : Int32, pixels_per_em : Int32) -> @moonfont.CoverageMask raise @moonfont.Refused
Eight-bit coverage of one glyph at a pixel size. samples is a Uint8Array of length width * height, row-major and top-down, values 0..255.
pub fn scale_value(face : @moonfont.Face, value : Int32, pixels_per_em : Int32) -> Int32
One font unit in 26.6 pixels at a size: exactly what Scale::apply returns, so a page can print the same fixed-point number the library works in.
pub fn units_per_em(face : @moonfont.Face) -> Int32
The font's units-per-em, in font units.
Bounds-checked big-endian reads over bytes that already exist in memory. This layer knows nothing about fonts; it only knows that a short file is the same failure wherever it happens.
pub struct Cursor {
data : BytesView
mut pos : Int32
}
A position in a run of bytes. Opaque: a caller that could set pos could make it disagree with the data it points into.
pub struct Writer {
data : Array[Byte]
}
An append-only byte buffer.
pub fn checksum(value : BytesView) -> Int32
The SFNT checksum of a table: the sum of its big-endian 32-bit words, with the last word zero-padded.
pub fn div_round(numerator : Int64, denominator : Int64) -> Int32
Divide rounding to nearest, halves away from zero.
pub fn Cursor::all(self : Cursor) -> BytesView
The whole window this cursor was bounded to, from its start rather than from its current position. A table that needs random access keeps this instead of seeking back and forth.
pub fn Cursor::at(data : BytesView, offset : Int32) -> Cursor raise @model.Refused
A cursor at at inside data. Used for a table slice, so that offsets inside that table stay relative to the table rather than to the file.
pub fn Cursor::bytes(self : Cursor, length : Int32) -> BytesView raise @model.Refused
pub fn Cursor::i16(self : Cursor) -> Int32 raise @model.Refused
pub fn Cursor::i16_at(self : Cursor, at : Int32) -> Int32 raise @model.Refused
pub fn Cursor::i8(self : Cursor) -> Int32 raise @model.Refused
pub fn Cursor::left(self : Cursor) -> Int32
pub fn Cursor::length(self : Cursor) -> Int32
pub fn Cursor::new(data : BytesView) -> Cursor
pub fn Cursor::position(self : Cursor) -> Int32
pub fn Cursor::rest(self : Cursor) -> BytesView
pub fn Cursor::seek(self : Cursor, at : Int32) -> Unit raise @model.Refused
pub fn Cursor::skip(self : Cursor, count : Int32) -> Unit raise @model.Refused
pub fn Cursor::tag(self : Cursor) -> Int32 raise @model.Refused
Four ASCII bytes as a table tag, held as a word so that a table lookup is a comparison of integers rather than of strings.
pub fn Cursor::tag_at(self : Cursor, at : Int32) -> Int32 raise @model.Refused
pub fn Cursor::u16(self : Cursor) -> Int32 raise @model.Refused
pub fn Cursor::u16_at(self : Cursor, at : Int32) -> Int32 raise @model.Refused
Read a value at an absolute offset without moving the cursor. Table directories are full of offsets into their own table, and a reader that sought there would lose its place in the directory.
pub fn Cursor::u24(self : Cursor) -> Int32 raise @model.Refused
pub fn Cursor::u32(self : Cursor) -> Int32 raise @model.Refused
A 32-bit big-endian word. Font files are bounded by Limits.file_bytes well below 2 GiB, so a value with the high bit set is either corrupt or hostile; it arrives as a negative number and every caller's range check refuses it.
pub fn Cursor::u32_at(self : Cursor, at : Int32) -> Int32 raise @model.Refused
pub fn Cursor::u8(self : Cursor) -> Int32 raise @model.Refused
pub fn Cursor::window(self : Cursor, at : Int32, length : Int32) -> Cursor raise @model.Refused
A bounded window into the same bytes. Lengths in a font are declared by the font, so this is the one place that decides whether a declaration is honest.
pub fn Writer::align(self : Writer, unit : Int32) -> Unit
Pad with zeroes to a multiple of unit. Tables in an SFNT start on a four-byte boundary and the padding is part of the file.
pub fn Writer::byte(self : Writer, value : Int32) -> Unit
pub fn Writer::bytes(self : Writer, value : BytesView) -> Unit
pub fn Writer::i16(self : Writer, value : Int32) -> Unit
pub fn Writer::length(self : Writer) -> Int32
pub fn Writer::new() -> Writer
pub fn Writer::tag(self : Writer, value : Int32) -> Unit
pub fn Writer::to_bytes(self : Writer) -> Bytes
pub fn Writer::u16(self : Writer, value : Int32) -> Unit
pub fn Writer::u32(self : Writer, value : Int32) -> Unit
pub fn Writer::zeros(self : Writer, count : Int32) -> Unit
Copyright 2026 Leo Cheng SPDX-License-Identifier: Apache-2.0
pub struct Woff1 {
}
WOFF 1.0.
pub struct Woff2 {
}
WOFF 2.0, including the collections the format added.
pub impl @sfnt.Container for Woff1
pub impl @sfnt.Container for Woff2
pub fn open_woff1(input : BytesView, limits : @model.Limits) -> Array[@sfnt.TableSet] raise @model.Refused
Every face a WOFF file holds. WOFF 1.0 carries a single font, so this is one set or a refusal.
pub fn open_woff2(input : BytesView, limits : @model.Limits) -> Array[@sfnt.TableSet] raise @model.Refused
Every face a WOFF2 file holds: one for a single font, one per font for a collection.
pub fn short_at(data : BytesView, at : Int32) -> Int32 raise @model.Refused
pub fn word_at(data : BytesView, at : Int32) -> Int32 raise @model.Refused
Read a big-endian word at an offset, refusing a short file rather than reading past it.
pub fn Woff1::new() -> Woff1
pub fn Woff2::new() -> Woff2
This page is rebuilt from the interface files and the notes in the source. It carries no dates and no ordering of its own.