The case

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.

moonbitstack/moonfont

package

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.

type

Bounds

pub using @model {type Bounds}
type

CoverageMask

pub using @model {type CoverageMask}
type

Face

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 }
  • avar@variations.Avar?
  • cff@cff.Font?
  • cmap@table.Cmap
  • cvar@variations.Cvar?
  • cvt@table.Cvt?
  • fvar@variations.Fvar?
  • gvar@variations.Gvar?
  • head@table.Head
  • hhea@table.Hhea
  • hmtx@table.Metrics
  • hvar@variations.MetricDeltas?
  • kern@table.Kern
  • limits@model.Limits
  • maxp@table.Maxp
  • mvar@variations.Mvar?
  • os2@table.Os2
  • source@outline.GlyphSource?
  • vhea@table.Vhea?
  • vmtx@table.Metrics?
  • vvar@variations.MetricDeltas?

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.

type

FontMetrics

pub using @model {type FontMetrics}
type

GlyphId

pub using @model {type GlyphId}
type

GlyphMetrics

pub using @model {type GlyphMetrics}
type

Limits

pub using @model {type Limits}
type

Outline

pub using @model {type Outline}
type

PathCommand

pub using @model {type PathCommand}
type

Point

pub using @model {type Point}
type

Refused

pub using @model {type Refused}
type

Scale

pub using @model {type Scale}
type

TextMetrics

pub using @model {type TextMetrics}
type

VerticalMetrics

pub using @model {type VerticalMetrics}
const

limits

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.

const

limits_strict

pub let limits_strict : @model.Limits = @model.limits_strict ///| /// The version of the library. pub fn version() -> String

The untrusted-input preset.

fn

decode

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.

fn

decode_all

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.

fn

decode_from

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.

fn

version

pub fn version() -> String

The version of the library.

method

Face::advance

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.

method

Face::advance_height

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.

method

Face::at

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.

method

Face::axes

pub fn Face::axes(self : Face) -> Array[@variations.Axis]

The axes a caller may set. Empty for a font that does not vary.

method

Face::cvt

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.

method

Face::font_metrics

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.

method

Face::glyph_for

pub fn Face::glyph_for(self : Face, character : Char) -> @model.GlyphId?

Translate a character to a glyph id.

method

Face::glyph_index

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.

method

Face::has_vertical_metrics

pub fn Face::has_vertical_metrics(self : Face) -> Bool

Whether the font carries vertical metrics of its own.

method

Face::instances

pub fn Face::instances(self : Face) -> Array[@variations.Instance]

The named instances the font offers, in fvar order.

method

Face::is_postscript

pub fn Face::is_postscript(self : Face) -> Bool

Whether the outlines are PostScript (CFF or CFF2) rather than TrueType.

method

Face::is_variable

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.

method

Face::kern_between

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.

method

Face::location

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.

method

Face::measure

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.

method

Face::metric_tags

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.

method

Face::metrics

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.

method

Face::num_glyphs

pub fn Face::num_glyphs(self : Face) -> Int32

How many glyphs the font declares.

method

Face::outline

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.

method

Face::rasterise

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.

method

Face::scale

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.

method

Face::top_side_bearing

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.

method

Face::units_per_em

pub fn Face::units_per_em(self : Face) -> Int32

The units in which outlines and advances are measured.

method

Face::vertical_metrics

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.

moonbitstack/moonfont/cff

package

Copyright 2026 Leo Cheng SPDX-License-Identifier: Apache-2.0

type

Dict

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 }
  • char_stringsInt32
  • charstring_typeInt32
  • fd_arrayInt32
  • fd_selectInt32
  • is_cidBool
  • matrix_scaleInt32The a of FontMatrix in 16.16, already multiplied by units per em.
  • matrix_setBool
  • private_offsetInt32
  • private_sizeInt32
  • subrsInt32
  • vsindexInt32
  • vstoreInt32

The dictionaries this reader needs, flattened. Every operand that does not appear keeps the value a PostScript reader would assume.

type

Font

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 }
  • char_stringsIndex
  • dataBytesView
  • default_vsindexInt32The variation-store index a charstring starts from.
  • fdsArray[Int32]The font-dictionary index of every glyph; empty means all use the first.
  • gsubrsIndex
  • is_cff2Bool
  • localsArray[Index]One local subroutine index per font dictionary, empty when the font has none. A non-CID font has exactly one.
  • matrix_scaleInt32
  • topDict
  • var_store@variations.Store?

A PostScript-outline font. Opaque: a caller asks for an outline or a glyph count, not for the table's internals.

type

Index

pub(all) struct Index { data : BytesView starts : Array[Int32] }
  • dataBytesView
  • startsArray[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.

const

call_depth

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.

const

ops_per_glyph

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.

method

Font::glyph_count

pub fn Font::glyph_count(self : Font) -> Int32
method

Font::is_variable

pub fn Font::is_variable(self : Font) -> Bool

Whether the font has a variation store, which only CFF 2 does.

method

Font::outline

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.

method

Font::parse

pub fn Font::parse(cursor : @wire.Cursor, is_cff2 : Bool, units_per_em : Int32, limits : @model.Limits) -> Font raise @model.Refused
method

Index::count

pub fn Index::count(self : Index) -> Int32
method

Index::item

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.

method

Index::parse

pub fn Index::parse(cursor : @wire.Cursor, wide : Bool, limits : @model.Limits) -> Index raise @model.Refused

moonbitstack/moonfont/layout

package

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.

fn

measure

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.

moonbitstack/moonfont/model

package

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.

type

Bounds

pub(all) struct Bounds { x_min : Int32 y_min : Int32 x_max : Int32 y_max : Int32 }
  • x_maxInt32
  • x_minInt32
  • y_maxInt32
  • y_minInt32

An axis-aligned box in font units.

type

CoverageMask

pub(all) struct CoverageMask { width : Int32 height : Int32 left : Int32 top : Int32 samples : FixedArray[Byte] }
  • heightInt32
  • leftInt32
  • samplesFixedArray[Byte]
  • topInt32
  • widthInt32

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.

type

FontMetrics

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 }
  • ascentInt32
  • bounding_boxBounds
  • cap_heightInt32
  • descentInt32
  • line_gapInt32
  • num_glyphsInt32
  • units_per_emInt32
  • x_heightInt32

Font-wide metrics, in font units. All vertical values keep the font's y-up sign: descent is negative in a well-formed font.

type

GlyphId

pub(all) struct GlyphId { index : Int32 }
  • indexInt32

A glyph's index in the font. Codepoints are not glyphs: translation belongs to the charmap, and everything downstream speaks only this.

type

GlyphMetrics

pub(all) struct GlyphMetrics { advance : Int32 left_side_bearing : Int32 bounds : Bounds }
  • advanceInt32
  • boundsBounds
  • left_side_bearingInt32

Horizontal metrics of one glyph, in font units.

type

Limits

pub(all) struct Limits { file_bytes : Int32 table_bytes : Int32 glyphs : Int32 points : Int32 contours : Int32 composites : Int32 recursion : Int32 mask_pixels : Int32 }
  • compositesInt32The largest number of components accepted in one composite glyph.
  • contoursInt32The largest number of contours accepted in one glyph outline.
  • file_bytesInt32The largest font file accepted, in bytes.
  • glyphsInt32The largest number of glyphs accepted.
  • mask_pixelsInt32The largest coverage mask accepted, in pixels.
  • pointsInt32The largest number of points accepted in one glyph outline.
  • recursionInt32The deepest nesting of composite glyphs accepted.
  • table_bytesInt32The largest single table accepted, in bytes.

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.

type

Outline

pub(all) struct Outline { commands : Array[PathCommand] bounds : Bounds }
  • boundsBounds
  • commandsArray[PathCommand]

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.

type

PathCommand

pub(all) enum PathCommand { MoveTo(Point) LineTo(Point) QuadTo(Point, Point) CubicTo(Point, Point, Point) Close }
  • Close
  • CubicTo(Point, Point, Point)Two control points, then end point.
  • LineTo(Point)
  • MoveTo(Point)
  • QuadTo(Point, Point)Control point, then end point.

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.

type

Point

pub(all) struct Point { x : Int32 y : Int32 }
  • xInt32
  • yInt32

A point in font units, with the font's own y-up orientation.

type

Refused

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) }
  • Malformed(at~ : Int32, got~ : String)A structurally impossible value in an otherwise readable table.
  • MissingGlyph(glyph~ : Int32)A glyph id outside maxp.numGlyphs.
  • MissingTable(tag~ : String)A required table is absent from the directory.
  • OverLimit(limit~ : Int32, got~ : Int32)A declaration past the caller's ceiling.
  • Recursion(depth~ : Int32)Composite glyphs nested past the caller's recursion ceiling.
  • Truncated(at~ : Int32, want~ : Int32)The bytes end want short of where the format needs them.
  • Unexpected(at~ : Int32, got~ : String, want~ : String)The bytes at at are not allowed here; want says what would be.
  • Unknown(at~ : Int32, got~ : String)The signature at at is not one this library reads.
  • Unsupported(at~ : Int32, got~ : String)A well-formed part of the format that this library does not read yet.

A refusal to read bytes as a font, or to turn a glyph into a bitmap.

type

Scale

pub(all) struct Scale { ppem : Int32 units_per_em : Int32 }
  • ppemInt32Pixels per em, in 26.6 fixed point.
  • units_per_emInt32

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.

type

TextMetrics

pub(all) struct TextMetrics { advance : Int32 ascent : Int32 descent : Int32 line_gap : Int32 glyphs : Int32 }
  • advanceInt32
  • ascentInt32
  • descentInt32
  • glyphsInt32
  • line_gapInt32

The measured shape of a run of text, in 26.6 pixels.

type

VerticalMetrics

pub(all) struct VerticalMetrics { ascent : Int32 descent : Int32 line_gap : Int32 }
  • ascentInt32
  • descentInt32
  • line_gapInt32

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.

impl

Show for Refused

pub impl Show for Refused
const

limits

pub let limits : Limits =

Desktop and server defaults: generous, but finite at every declaration.

const

limits_strict

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.

method

Bounds::empty

pub fn Bounds::empty() -> Bounds
method

Bounds::equal

pub fn Bounds::equal(Self, Self) -> Bool
method

Bounds::height

pub fn Bounds::height(self : Bounds) -> Int32
method

Bounds::is_empty

pub fn Bounds::is_empty(self : Bounds) -> Bool
method

Bounds::not_equal

pub fn Bounds::not_equal(Self, Self) -> Bool
method

Bounds::to_repr

pub fn Bounds::to_repr(Self) -> @debug.Repr
method

Bounds::width

pub fn Bounds::width(self : Bounds) -> Int32
method

CoverageMask::at

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.

method

CoverageMask::of

pub fn CoverageMask::of(width : Int32, height : Int32, left : Int32, top : Int32, samples : FixedArray[Byte]) -> CoverageMask
method

GlyphId::equal

pub fn GlyphId::equal(Self, Self) -> Bool
method

GlyphId::not_equal

pub fn GlyphId::not_equal(Self, Self) -> Bool
method

GlyphId::of

pub fn GlyphId::of(index : Int32) -> GlyphId
method

GlyphId::to_int

pub fn GlyphId::to_int(self : GlyphId) -> Int32
method

GlyphId::to_repr

pub fn GlyphId::to_repr(Self) -> @debug.Repr
method

Limits::check_composites

pub fn Limits::check_composites(self : Limits, count : Int32) -> Unit raise Refused
method

Limits::check_depth

pub fn Limits::check_depth(self : Limits, depth : Int32) -> Unit raise Refused
method

Limits::check_file

pub fn Limits::check_file(self : Limits, size : Int32) -> Unit raise Refused
method

Limits::check_glyphs

pub fn Limits::check_glyphs(self : Limits, count : Int32) -> Unit raise Refused
method

Limits::check_mask

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.

method

Limits::check_outline

pub fn Limits::check_outline(self : Limits, points : Int32, contours : Int32) -> Unit raise Refused
method

Limits::check_table

pub fn Limits::check_table(self : Limits, size : Int32) -> Unit raise Refused
method

Limits::new

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.

method

Outline::bounds

pub fn Outline::bounds(self : Outline) -> Bounds
method

Outline::commands

pub fn Outline::commands(self : Outline) -> Array[PathCommand]
method

Outline::is_empty

pub fn Outline::is_empty(self : Outline) -> Bool
method

Outline::of

pub fn Outline::of(commands : Array[PathCommand], bounds : Bounds) -> Outline
method

PathCommand::equal

pub fn PathCommand::equal(Self, Self) -> Bool
method

PathCommand::not_equal

pub fn PathCommand::not_equal(Self, Self) -> Bool
method

PathCommand::to_repr

pub fn PathCommand::to_repr(Self) -> @debug.Repr
method

Point::equal

pub fn Point::equal(Self, Self) -> Bool
method

Point::not_equal

pub fn Point::not_equal(Self, Self) -> Bool
method

Point::of

pub fn Point::of(x : Int32, y : Int32) -> Point
method

Point::to_repr

pub fn Point::to_repr(Self) -> @debug.Repr
method

Refused::equal

pub fn Refused::equal(Self, Self) -> Bool
method

Refused::name

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.

method

Refused::not_equal

pub fn Refused::not_equal(Self, Self) -> Bool
method

Refused::output

pub fn Refused::output(Self, &Logger) -> Unit
method

Refused::to_repr

pub fn Refused::to_repr(Self) -> @debug.Repr
method

Refused::to_string

pub fn Refused::to_string(Self) -> String
method

Scale::apply

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.

method

Scale::of

pub fn Scale::of(pixels_per_em : Int32, units_per_em : Int32) -> Scale
method

Scale::ppem

pub fn Scale::ppem(self : Scale) -> Int32

moonbitstack/moonfont/outline

package

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.

type

GlyphSource

pub(all) struct GlyphSource { glyf : BytesView loca : @table.Loca limits : @model.Limits }
  • glyfBytesView
  • limits@model.Limits
  • loca@table.Loca

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.

fn

simple_outline

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.

method

GlyphSource::coordinates

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.

method

GlyphSource::ends

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.

method

GlyphSource::of

pub fn GlyphSource::of(glyf : BytesView, loca : @table.Loca, limits : @model.Limits) -> GlyphSource
method

GlyphSource::outline

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.

method

GlyphSource::phantom_deltas

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.

method

GlyphSource::points

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.

moonbitstack/moonfont/raster

package

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.

fn

rasterise

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.

moonbitstack/moonfont/sfnt

package

The SFNT container only: signatures, the table directory, and TrueType collections. It knows where tables are, never what is inside them.

type

Sfnt

pub struct Sfnt { }

The plain sfnt container: a single font or a TrueType collection, whose table directories are already where the readers expect them.

type

TableSet

pub(all) struct TableSet { scaler : Int32 bytes : BytesView tags : Array[Int32] offsets : Array[Int32] lengths : Array[Int32] }
  • bytesBytesViewThe buffer every offset below points into.
  • lengthsArray[Int32]
  • offsetsArray[Int32]
  • scalerInt32
  • tagsArray[Int32]Table tags, ascending, so a lookup can stop early.

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.

trait

Container

pub(open) trait Container { fn name(Self) -> String fn claims(Self, Int32) -> Bool fn open(Self, BytesView, @model.Limits) -> Array[TableSet] raise @model.Refused }
trait

TableSource

pub(open) trait TableSource { fn scaler(Self) -> Int32 fn has(Self, Int32) -> Bool fn table_bytes(Self, Int32, @model.Limits) -> BytesView raise @model.Refused }
impl

Container for Sfnt

pub impl Container for Sfnt
impl

TableSource for TableSet

pub impl TableSource for TableSet
fn

assemble

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.

fn

assemble_collection

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.

fn

read

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.

fn

scaler_of

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.

fn

table_cursor

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.

fn

tag_avar

pub fn tag_avar() -> Int32
fn

tag_cff

pub fn tag_cff() -> Int32
fn

tag_cff2

pub fn tag_cff2() -> Int32
fn

tag_cmap

pub fn tag_cmap() -> Int32
fn

tag_cpht

pub fn tag_cpht() -> Int32
fn

tag_cvar

pub fn tag_cvar() -> Int32
fn

tag_cvt

pub fn tag_cvt() -> Int32
fn

tag_fvar

pub fn tag_fvar() -> Int32
fn

tag_glyf

pub fn tag_glyf() -> Int32
fn

tag_gvar

pub fn tag_gvar() -> Int32
fn

tag_hasc

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.

fn

tag_hcla

pub fn tag_hcla() -> Int32
fn

tag_hcld

pub fn tag_hcld() -> Int32
fn

tag_hcof

pub fn tag_hcof() -> Int32
fn

tag_hcrn

pub fn tag_hcrn() -> Int32
fn

tag_hcrs

pub fn tag_hcrs() -> Int32
fn

tag_hdsc

pub fn tag_hdsc() -> Int32
fn

tag_head

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.

fn

tag_hhea

pub fn tag_hhea() -> Int32
fn

tag_hlgp

pub fn tag_hlgp() -> Int32
fn

tag_hmtx

pub fn tag_hmtx() -> Int32
fn

tag_hvar

pub fn tag_hvar() -> Int32
fn

tag_kern

pub fn tag_kern() -> Int32
fn

tag_loca

pub fn tag_loca() -> Int32
fn

tag_maxp

pub fn tag_maxp() -> Int32
fn

tag_mvar

pub fn tag_mvar() -> Int32
fn

tag_name

pub fn tag_name() -> Int32
fn

tag_os2

pub fn tag_os2() -> Int32
fn

tag_post

pub fn tag_post() -> Int32
fn

tag_string

pub fn tag_string(tag : Int32) -> String

A readable name for a refusal message; never built during a table lookup.

fn

tag_undo

pub fn tag_undo() -> Int32
fn

tag_unds

pub fn tag_unds() -> Int32
fn

tag_vasc

pub fn tag_vasc() -> Int32
fn

tag_vcof

pub fn tag_vcof() -> Int32
fn

tag_vcrn

pub fn tag_vcrn() -> Int32
fn

tag_vcrs

pub fn tag_vcrs() -> Int32
fn

tag_vdsc

pub fn tag_vdsc() -> Int32
fn

tag_vhea

pub fn tag_vhea() -> Int32
fn

tag_vlgp

pub fn tag_vlgp() -> Int32
fn

tag_vmtx

pub fn tag_vmtx() -> Int32
fn

tag_vorg

pub fn tag_vorg() -> Int32
fn

tag_vvar

pub fn tag_vvar() -> Int32
fn

tag_xhgt

pub fn tag_xhgt() -> Int32
method

Sfnt::new

pub fn Sfnt::new() -> Sfnt
method

TableSet::has

pub fn TableSet::has(self : TableSet, tag : Int32) -> Bool
method

TableSet::table_bytes

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.

method

TableSet::tags

pub fn TableSet::tags(self : TableSet) -> Array[Int32]

The tags this face carries, ascending.

moonbitstack/moonfont/table

package

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.

type

Cmap

pub(all) struct Cmap { data : BytesView chosen : Int32 format : Int32 }
  • chosenInt32
  • dataBytesView
  • formatInt32
type

Component

pub(all) struct Component { glyph_index : Int32 dx : Int32 dy : Int32 a : Int32 b : Int32 c : Int32 d : Int32 }
  • aInt32
  • bInt32
  • cInt32
  • dInt32
  • dxInt32
  • dyInt32
  • glyph_indexInt32

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.

type

CompositeGlyph

pub(all) struct CompositeGlyph { components : Array[Component] bounds : @model.Bounds }
  • bounds@model.Bounds
  • componentsArray[Component]
type

Cvt

pub(all) struct Cvt { values : Array[Int32] }
  • valuesArray[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.

type

GlyphData

pub(all) enum GlyphData { Empty Simple(SimpleGlyph) Composite(CompositeGlyph) }
  • Composite(CompositeGlyph)
  • Empty
  • Simple(SimpleGlyph)
type

Head

pub(all) struct Head { units_per_em : Int32 index_to_loc_format : Int32 mac_style : Int32 lowest_rec_ppem : Int32 bounding_box : @model.Bounds }
  • bounding_box@model.Bounds
  • index_to_loc_formatInt32
  • lowest_rec_ppemInt32
  • mac_styleInt32
  • units_per_emInt32

head: the font-wide scale and the shape of the loca table.

type

Hhea

pub(all) struct Hhea { ascender : Int32 descender : Int32 line_gap : Int32 number_of_h_metrics : Int32 }
  • ascenderInt32
  • descenderInt32
  • line_gapInt32
  • number_of_h_metricsInt32

hhea: the vertical rhythm and the width of one hmtx long metric.

type

Kern

pub(all) struct Kern { pairs : Array[(Int32, Int32, Int32)] }
  • pairsArray[(Int32, Int32, Int32)](left glyph, right glyph, adjustment in font units).
type

Loca

pub(all) struct Loca { offsets : Array[Int32] }
  • offsetsArray[Int32]

loca: one offset per glyph boundary, in either short or long form.

type

Maxp

pub(all) struct Maxp { num_glyphs : Int32 max_points : Int32 max_contours : Int32 max_composite_points : Int32 max_composite_contours : Int32 }
  • max_composite_contoursInt32
  • max_composite_pointsInt32
  • max_contoursInt32
  • max_pointsInt32
  • num_glyphsInt32

maxp: how many glyphs the file claims to have.

type

Metrics

pub(all) struct Metrics { advances : Array[Int32] bearings : Array[Int32] }
  • advancesArray[Int32]
  • bearingsArray[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.

type

Os2

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 }
  • cap_heightInt32
  • typo_ascenderInt32
  • typo_descenderInt32
  • typo_line_gapInt32
  • weight_classInt32
  • width_classInt32
  • x_heightInt32
type

SimpleGlyph

pub(all) struct SimpleGlyph { end_points : Array[Int32] points : Array[@model.Point] on_curve : Array[Bool] bounds : @model.Bounds }
  • bounds@model.Bounds
  • end_pointsArray[Int32]The index of the last point of each contour.
  • on_curveArray[Bool]
  • pointsArray[@model.Point]
type

Vhea

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 }
  • advance_height_maxInt32
  • ascenderInt32
  • caret_offsetInt32
  • caret_slope_riseInt32
  • caret_slope_runInt32
  • descenderInt32
  • line_gapInt32
  • number_of_long_metricsInt32How many glyphs the 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.

method

Cmap::format

pub fn Cmap::format(self : Cmap) -> Int32
method

Cmap::glyph_index

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.

method

Cmap::parse

pub fn Cmap::parse(cursor : @wire.Cursor, limits : @model.Limits) -> Cmap raise @model.Refused
method

Cvt::parse

pub fn Cvt::parse(cursor : @wire.Cursor, limits : @model.Limits) -> Cvt raise @model.Refused
method

GlyphData::parse

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.

method

Head::parse

pub fn Head::parse(cursor : @wire.Cursor) -> Head raise @model.Refused
method

Hhea::parse

pub fn Hhea::parse(cursor : @wire.Cursor) -> Hhea raise @model.Refused
method

Kern::between

pub fn Kern::between(self : Kern, left : Int32, right : Int32) -> Int32

The adjustment between two glyphs, in font units. Zero when there is none.

method

Kern::count

pub fn Kern::count(self : Kern) -> Int32
method

Kern::empty

pub fn Kern::empty() -> Kern
method

Kern::parse

pub fn Kern::parse(cursor : @wire.Cursor, limits : @model.Limits) -> Kern raise @model.Refused
method

Loca::count

pub fn Loca::count(self : Loca) -> Int32
method

Loca::parse

pub fn Loca::parse(cursor : @wire.Cursor, num_glyphs : Int32, index_to_loc_format : Int32, limits : @model.Limits) -> Loca raise @model.Refused
method

Loca::range

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.

method

Maxp::parse

pub fn Maxp::parse(cursor : @wire.Cursor, limits : @model.Limits) -> Maxp raise @model.Refused
method

Metrics::metrics

pub fn Metrics::metrics(self : Metrics, glyph : Int32) -> (Int32, Int32)
method

Metrics::parse

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.

method

Os2::empty

pub fn Os2::empty() -> Os2
method

Os2::parse

pub fn Os2::parse(cursor : @wire.Cursor) -> Os2 raise @model.Refused
method

Vhea::parse

pub fn Vhea::parse(cursor : @wire.Cursor) -> Vhea raise @model.Refused

moonbitstack/moonfont/variations

package

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.

type

Avar

pub(all) struct Avar { maps : Array[Array[(Int32, Int32)]] }
  • mapsArray[Array[(Int32, Int32)]]

The per-axis segment maps.

type

Axis

pub(all) struct Axis { tag : Int32 min : Int32 default_value : Int32 max : Int32 flags : Int32 name_id : Int32 }
  • default_valueInt32
  • flagsInt32
  • maxInt32
  • minInt32
  • name_idInt32
  • tagInt32

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.

type

Cvar

pub(all) struct Cvar { data : BytesView axis_count : Int32 tuple_count : Int32 data_at : Int32 shared_points : Bool }
  • axis_countInt32
  • dataBytesView
  • data_atInt32
  • shared_pointsBool
  • tuple_countInt32

The cvar table.

type

DeltaMap

pub(all) struct DeltaMap { data : BytesView entries_at : Int32 count : Int32 entry_size : Int32 inner_bits : Int32 }
  • countInt32
  • dataBytesView
  • entries_atInt32
  • entry_sizeInt32
  • inner_bitsInt32

A map from a glyph id to the two-level index of the variation store.

type

Fvar

pub(all) struct Fvar { axes : Array[Axis] instances : Array[Instance] }
  • axesArray[Axis]
  • instancesArray[Instance]

The fvar table.

type

Gvar

pub struct Gvar { data : BytesView axis_count : Int32 shared_at : Int32 shared_count : Int32 glyph_count : Int32 offsets : Array[Int32] offset_to_data : Int32 }
  • axis_countInt32
  • dataBytesView
  • glyph_countInt32
  • offset_to_dataInt32
  • offsetsArray[Int32]One offset per glyph boundary, relative to offset_to_data.
  • shared_atInt32Where the shared peaks start, and how many there are.
  • shared_countInt32

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.

type

Instance

pub(all) struct Instance { subfamily_name_id : Int32 coords : Array[Int32] }
  • coordsArray[Int32]One 16.16 user-space value per axis, in fvar order.
  • subfamily_name_idInt32

One named instance: a point in the design space and the name to show.

type

Location

pub(all) struct Location { coords : Array[Int32] }
  • coordsArray[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.

type

MetricDeltas

pub(all) struct MetricDeltas { store : Store advance : DeltaMap? bearing : DeltaMap? side : DeltaMap? }
  • advanceDeltaMap?Advance: width for HVAR, height for VVAR.
  • bearingDeltaMap?Left side bearing for HVAR, top side bearing for VVAR.
  • sideDeltaMap?Right or bottom side bearing, which this library reports but never derives an advance from.
  • storeStore

A metrics variation table: an item variation store and up to three maps, one per metric the table may move.

type

Mvar

pub(all) struct Mvar { store : Store records : Array[(Int32, Int32, Int32)] }
  • recordsArray[(Int32, Int32, Int32)](tag, outer, inner) per record, in the order the table declares them.
  • storeStore

The MVAR table.

type

Region

pub(all) struct Region { coordinates : Array[Int32] }
  • coordinatesArray[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.

type

Store

pub(all) struct Store { data : BytesView region_axis_count : Int32 regions : Array[Region] items : Array[Int32] }
  • dataBytesView
  • itemsArray[Int32]Offsets of each ItemVariationData subtable, relative to the store start.
  • region_axis_countInt32
  • regionsArray[Region]

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.

fn

scale_f2dot14

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.

fn

scale_fixed

pub fn scale_fixed(value : Int32, factor : Int32) -> Int32

Multiply by a 16.16 factor, rounding to nearest.

fn

tag_name

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.

fn

tag_of

pub fn tag_of(text : String) -> Int32

A four-character tag as a word, so a lookup compares integers.

method

Avar::map_axis

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.

method

Avar::parse

pub fn Avar::parse(cursor : @wire.Cursor, axis_count : Int32, limits : @model.Limits) -> Avar raise @model.Refused
method

Axis::is_hidden

pub fn Axis::is_hidden(self : Axis) -> Bool

The axis cannot be set by the user; it is driven by the application instead.

method

Axis::tag_name

pub fn Axis::tag_name(self : Axis) -> String
method

Cvar::deltas

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.

method

Cvar::parse

pub fn Cvar::parse(cursor : @wire.Cursor, axis_count : Int32, limits : @model.Limits) -> Cvar raise @model.Refused
method

DeltaMap::parse

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".

method

DeltaMap::resolve

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.

method

Fvar::parse

pub fn Fvar::parse(cursor : @wire.Cursor, limits : @model.Limits) -> Fvar raise @model.Refused
method

Gvar::deltas

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.

method

Gvar::parse

pub fn Gvar::parse(cursor : @wire.Cursor, glyph_count : Int32, limits : @model.Limits) -> Gvar raise @model.Refused
method

Location::at

pub fn Location::at(self : Location, fvar : Fvar, axis : Int32) -> Int32

Read one axis by its four-character tag.

method

Location::default

pub fn Location::default(fvar : Fvar) -> Location

The default instance: every axis at its fvar default.

method

Location::get

pub fn Location::get(self : Location, index : Int32) -> Int32

Read one axis value.

method

Location::normalise

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.

method

Location::of

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.

method

Location::set

pub fn Location::set(self : Location, fvar : Fvar, axis : Int32, value : Int32) -> Unit

Set one axis by its four-character tag.

method

Location::set_axis

pub fn Location::set_axis(self : Location, index : Int32, value : Int32) -> Unit

Set one axis by index.

method

MetricDeltas::advance_delta

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.

method

MetricDeltas::bearing_delta

pub fn MetricDeltas::bearing_delta(self : MetricDeltas, glyph : Int32, coords : Array[Int32]) -> Int32

The leading side-bearing delta of one glyph, in font units.

method

MetricDeltas::parse

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.

method

MetricDeltas::side_delta

pub fn MetricDeltas::side_delta(self : MetricDeltas, glyph : Int32, coords : Array[Int32]) -> Int32

The trailing side-bearing delta of one glyph, in font units.

method

Mvar::delta

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.

method

Mvar::parse

pub fn Mvar::parse(cursor : @wire.Cursor, limits : @model.Limits) -> Mvar raise @model.Refused
method

Mvar::tags

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.

method

Region::scalar

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.

method

Store::blend

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.

method

Store::delta

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.

method

Store::parse

pub fn Store::parse(cursor : @wire.Cursor, limits : @model.Limits) -> Store raise @model.Refused
method

Store::region_count

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.

moonbitstack/moonfont/web

package

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.

fn

decode

pub fn decode(bytes : Bytes) -> @moonfont.Face raise @moonfont.Refused

Decode a font from its bytes. Raises on input the library refuses.

fn

font_metrics

pub fn font_metrics(face : @moonfont.Face) -> @moonfont.FontMetrics

Font-wide metrics as plain integers, in font units.

fn

glyph_index

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.

fn

metrics

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.

fn

num_glyphs

pub fn num_glyphs(face : @moonfont.Face) -> Int32

The number of glyphs in the face.

fn

outline_svg

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.

fn

rasterise

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.

fn

scale_value

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.

fn

units_per_em

pub fn units_per_em(face : @moonfont.Face) -> Int32

The font's units-per-em, in font units.

moonbitstack/moonfont/wire

package

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.

type

Cursor

pub struct Cursor { data : BytesView mut pos : Int32 }
  • dataBytesView
  • posInt32

A position in a run of bytes. Opaque: a caller that could set pos could make it disagree with the data it points into.

type

Writer

pub struct Writer { data : Array[Byte] }
  • dataArray[Byte]

An append-only byte buffer.

fn

checksum

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.

fn

div_round

pub fn div_round(numerator : Int64, denominator : Int64) -> Int32

Divide rounding to nearest, halves away from zero.

method

Cursor::all

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.

method

Cursor::at

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.

method

Cursor::bytes

pub fn Cursor::bytes(self : Cursor, length : Int32) -> BytesView raise @model.Refused
method

Cursor::i16

pub fn Cursor::i16(self : Cursor) -> Int32 raise @model.Refused
method

Cursor::i16_at

pub fn Cursor::i16_at(self : Cursor, at : Int32) -> Int32 raise @model.Refused
method

Cursor::i8

pub fn Cursor::i8(self : Cursor) -> Int32 raise @model.Refused
method

Cursor::left

pub fn Cursor::left(self : Cursor) -> Int32
method

Cursor::length

pub fn Cursor::length(self : Cursor) -> Int32
method

Cursor::new

pub fn Cursor::new(data : BytesView) -> Cursor
method

Cursor::position

pub fn Cursor::position(self : Cursor) -> Int32
method

Cursor::rest

pub fn Cursor::rest(self : Cursor) -> BytesView
method

Cursor::seek

pub fn Cursor::seek(self : Cursor, at : Int32) -> Unit raise @model.Refused
method

Cursor::skip

pub fn Cursor::skip(self : Cursor, count : Int32) -> Unit raise @model.Refused
method

Cursor::tag

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.

method

Cursor::tag_at

pub fn Cursor::tag_at(self : Cursor, at : Int32) -> Int32 raise @model.Refused
method

Cursor::u16

pub fn Cursor::u16(self : Cursor) -> Int32 raise @model.Refused
method

Cursor::u16_at

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.

method

Cursor::u24

pub fn Cursor::u24(self : Cursor) -> Int32 raise @model.Refused
method

Cursor::u32

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.

method

Cursor::u32_at

pub fn Cursor::u32_at(self : Cursor, at : Int32) -> Int32 raise @model.Refused
method

Cursor::u8

pub fn Cursor::u8(self : Cursor) -> Int32 raise @model.Refused
method

Cursor::window

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.

method

Writer::align

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.

method

Writer::byte

pub fn Writer::byte(self : Writer, value : Int32) -> Unit
method

Writer::bytes

pub fn Writer::bytes(self : Writer, value : BytesView) -> Unit
method

Writer::i16

pub fn Writer::i16(self : Writer, value : Int32) -> Unit
method

Writer::length

pub fn Writer::length(self : Writer) -> Int32
method

Writer::new

pub fn Writer::new() -> Writer
method

Writer::tag

pub fn Writer::tag(self : Writer, value : Int32) -> Unit
method

Writer::to_bytes

pub fn Writer::to_bytes(self : Writer) -> Bytes
method

Writer::u16

pub fn Writer::u16(self : Writer, value : Int32) -> Unit
method

Writer::u32

pub fn Writer::u32(self : Writer, value : Int32) -> Unit
method

Writer::zeros

pub fn Writer::zeros(self : Writer, count : Int32) -> Unit

moonbitstack/moonfont/woff

package

Copyright 2026 Leo Cheng SPDX-License-Identifier: Apache-2.0

type

Woff1

pub struct Woff1 { }

WOFF 1.0.

type

Woff2

pub struct Woff2 { }

WOFF 2.0, including the collections the format added.

impl

@sfnt.Container for Woff1

pub impl @sfnt.Container for Woff1
impl

@sfnt.Container for Woff2

pub impl @sfnt.Container for Woff2
fn

open_woff1

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.

fn

open_woff2

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.

fn

short_at

pub fn short_at(data : BytesView, at : Int32) -> Int32 raise @model.Refused
fn

word_at

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.

method

Woff1::new

pub fn Woff1::new() -> Woff1
method

Woff2::new

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.