Appearance
Carrot.Text.Fonts
net
.NET font baking library - parses TTF/TTC font files, extracts glyph outlines and metadata, and bakes SDF atlas textures for runtime rendering in Unity and TypeScript.
Usage
csharp
using Carrot.Text.Fonts;
using Carrot.Text.Fonts.Data;
using TtfReader reader = TtfReader.Load("path/to/font.ttf");
Ttf font = reader.Parse();Contents
Readers: TtfReader · TtcReader - parse TTF/TTC font files from file path, byte array, or binary reader.
Data model: Ttf - font data with Names, Glyphs, Kerning, Adjustments, Palettes.
Atlas: TtfAtlas<TPacker> - glyph atlas generation with configurable rect packing and serialization.
Shape pipeline: Multi-stage render pipeline for SDF glyph rendering - sampling, normalisation, coverage, hit positions, signed distance.
Glyph sets: TtfGlyphFontSet · TtfGlyphCollection · UnicodeCharacters - glyph selection and character set management.
Build
bash
dotnet buildCarrot.Text.Fonts - Contents
Readers
TtfReader - parses a single TTF font; Load(path), Load(byte[]), Load(IHasBinaryReader) → Parse() → Ttf
TtcReader - parses TrueType Collection files containing multiple fonts
Data Model
Ttf - root font object: Names · Glyphs · Kerning · Adjustments · Palettes · UnitsPerEm · GetScaleFromPx()
TtfNames - family, subfamily, full name, version, etc.
TtfGlyphs - glyph collection with simple, composite, and blank glyph types
TtfKerning - kern pair data
TtfAdjustments - GPOS glyph positioning adjustments
TtfPalettes - CPAL colour palettes
Glyphs
TtfGlyph - base glyph with bounds, index, advance width
TtfGlyphSimple - contour-based outlines with on/off-curve control points
TtfGlyphComposite - composed from TtfGlyphComponent references
TtfGlyphBlank - no outline (whitespace)
TtfGlyphType - Simple · Composite · Blank
Contours
TtfGlyphContour - closed contour loop
TtfGlyphContourBezier - quadratic Bézier segment
TtfGlyphContourControlPoint - on-curve / off-curve point
Colour (COLRv0/v1)
TtfGlyphColorSimple - colour glyph with layers
TtfGlyphColorSimpleLayer - per-layer glyph + palette index
TTF Table Chunks
Parsed table chunks (each with Chunk + ChunkData pair):
| Table | Chunk | Description |
|---|---|---|
name | TtfNameChunk | Font name and branding |
head | TtfFontHeaderChunk | Font metadata (unitsPerEm, flags) |
maxp | TtfMaximumProfileChunk | Glyph count and limits |
cmap | TtfCharacterMapChunk | Unicode → glyph mapping (formats 0, 4, 6, 12, 14) |
kern | TtfKerningChunk | Kerning pairs |
GPOS | TtfGlyphPositioningChunk | Glyph positioning (formats 2, 4, 5, 6) |
hhea | TtfHorizontalHeaderChunk | Horizontal layout metrics |
hmtx | TtfHorizontalAdvanceChunk | Per-glyph advance widths |
loca | TtfGlyphLocationsChunk | Glyph offset table |
glyf | TtfGlyphTableChunk | Glyph outlines |
OS/2 | TtfWindowsMetricsChunk | Typographic metrics |
post | TtfPostScriptChunk | PostScript metadata |
fpgm | TtfFontProgramChunk | Font program bytecode |
prep | TtfPreProgramChunk | Pre-glyph program bytecode |
CPAL | TtfColorPaletteChunk | Colour palettes |
COLR | TtfColorLayersChunk | Colour layers |
sbix | TtfStandardBitmapGraphicsChunk | Bitmap graphics |
Builder
TtfBuilder - assembles a Ttf from parsed chunks via sub-builders:
TtfBuilderNames · TtfBuilderGlyphs · TtfBuilderKerning · TtfBuilderAdjustments · TtfBuilderPalette
Hinting / Execution
TtfBytecodeReader · TtfHintingReader - bytecode instruction parsing
TtfExecutionState · TtfFontFunction · TtfInstruction · TtfOpcode · TtfOperandType - TrueType hinting VM types
Atlas
TtfAtlas<TPacker> - extends ImageAtlas; packs glyphs into a texture atlas with configurable padding and font size
TtfAtlasConfiguration - font size, padding, packer config
TtfAtlasItem - glyph + scale metadata per atlas entry
TtfAtlasSet - collection of atlases
TtfAtlasSerialized · TtfAtlasEntrySerialized - JSON serialization for baked atlas data
Glyph Sets
TtfGlyphFontSet - font + selected glyphs for atlas generation
TtfGlyphCollection - glyph collection with lookup
UnicodeCharacters - standard character sets (ASCII, Latin, symbols, etc.)
Shape Render Pipeline
Multi-stage pipeline for rendering glyph outlines to SDF/coverage textures:
Glyphs (per-glyph processing)
ShapeRenderPipelineGlyph → Sampled → SampledCoverage / SampledHitPositions / SampledSignedDistance → Normalized → NormalizedCoverage / NormalizedHitPositions / NormalizedSignedDistance → Painted → PaintedCoverage
Atlases (full atlas processing)
ShapeRenderPipelineAtlas → Sampled → SampledCoverage / SampledHitPositions / SampledSignedDistance → Normalized → NormalizedCoverage / NormalizedHitPositions / NormalizedSignedDistance → Packed → Painted → PaintedCoverage
Rendering
ShapeRendererAtlas · ShapeRendererGlyph - render pipeline outputs to raster images
Extension Methods
ShapeGraphExtensions · ShapeLayerExtensions · ShapeNodeGroupExtensions - shape graph to render pipeline conversions