Aurora Font

Description

Parses a TrueType (.ttf) font and bakes an MTSDF glyph atlas. Two roles: (1) a serializable container for the font’s table directory + character set (loaded from .afm), and (2) the static atlas generator that reads the .ttf tables, reconstructs glyph outlines, colors their edges, and renders a multi-channel-plus-true-distance atlas PNG along with the .agd metadata (Atlas Meta Data).

Text rendering is an active WIP area. The pipeline now produces MTSDF (RGB edge channels + an alpha “true distance” channel), having moved on from plain MSDF.

API summary

MemberKindSummary
Deserialize(string path)publicLoad .afmFontMeta, the TableEntry[] directory, and the char set.
GenerateGlyphAtlas(AuroraFont fontData, string fontName, int perGlyphSize)staticBake the atlas + .agd from a system .ttf.

Fields & Properties

[StructLayout(Sequential, Pack=1), @Serializable] public struct FontMeta   { uint version; ushort tableCount; }
[StructLayout(Sequential, Pack=1), @Serializable] public struct TableEntry { string name; uint checksum, offset, length; }
[StructLayout(Sequential, Pack=1), @Serializable] public struct TextData   { int characterCount; char[] characters; }

[@Serializable] public FontMeta fontMeta;
[@Serializable] public TableEntry[] tableEntries;
[@Serializable] public TextData textData;

Methods

Deserialize (public)

Reads the FontMeta, the TableEntry directory, and the character list from the .afm binary.

GenerateGlyphAtlas (static)

Reads the .ttf from the system fonts folder (Environment.SpecialFolder.Fonts), then: maxp → glyph count headunitsPerEm + indexToLocFormat loca → glyph offsets per character: cmap (GetGlyphIndex) → glyf (GetGlyphOutline) → a Glyph of bezier contours hhea/hmtxadvanceWidth + left side bearings derive tsb serialize the Atlas Meta Data.agd render each glyph cell via GenerateMTSDF save {font}_atlas.png (plus a debug SDF_A.png)

Helpers

  • GetGlyphIndexcmap format-4 segmented lookup (char → glyph index).
  • GetGlyphOutline — parse glyf contours into beziers, BuildEdges, then assign MSDF edge colors (R/G/B) by corner detection so channels can be combined.
  • GenerateMTSDF — per pixel: three per-channel signed distances + a true distance, packed into RGBA.
  • GetClosestDistanceOfChannel · ClosestTOnBezier (coarse sample + Newton refinement) · ComputeWindingNumber (ray-cast via quadratic roots) · SolveCubic / SolveQuadratic.