Jim's Depository

this code is not yet written

I wrote swift-glyph, a pure-Swift TrueType glyph engine. OpenType goes in, 8-bit coverage comes out.

It speaks glyphs, not strings. You hand it font bytes, ask for the glyph id of a scalar, ask for that glyph's exact bitmap size at a pixel height, and then tell it to fill a buffer you own.

let font = try Font(validating: bytes)
let sized = font.sized(pixelHeight: 18)

let glyph = font.glyphID(for: "A")!
let m = try sized.metrics(of: glyph)

var pixels = [UInt8](repeating: 0, count: m.bitmapWidth * m.bitmapHeight)
var target = RenderTarget(pixels: pixels.mutableSpan,
                          width: m.bitmapWidth, height: m.bitmapHeight,
                          stride: m.bitmapWidth)
try sized.render(glyph, into: &target)

The use case I have in mind is a small display on an embedded board, where you want real text from a real font instead of a bitmap font baked in 1987. The library never allocates a pixel buffer; the caller owns all the storage, and the stride argument means you can render straight into a glyph atlas. A Font either owns its bytes or borrows flash- or mmap-resident memory without copying. All the structural validation happens at load, so a malformed font fails at boot rather than the first time a label shows an unusual character. It works fine on a desktop too, it just refuses to do anything expensive behind your back.

From a font it handles glyf outlines, composite glyphs, cmap formats 4 and 12, the classic kern table for pair kerning, anti-aliased rasterization with subpixel positioning, and a visitor over the raw quadratic outline if you would rather flatten the curves yourself. There is a thin layout function that turns scalars into positioned glyphs.

It does not do shaping, hinting, CFF/PostScript outlines, GPOS kerning, variable-font axes, or embedded bitmap strikes. No bidi, no complex scripts, no font fallback, no color output—coverage only, and blending is your compositor's problem. Fonts that need the missing pieces should be instanced or flattened offline.

The whole engine is under 1,500 lines of code, which is either the appeal or the warning depending on what you were hoping for. It is extremely young, built for one specific use, and the API will move as that use demands.

It requires Swift 6.3. The source, and a macOS app that diffs its output against Core Text, are on GitHub.