Skip to content

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 build

Carrot.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):

TableChunkDescription
nameTtfNameChunkFont name and branding
headTtfFontHeaderChunkFont metadata (unitsPerEm, flags)
maxpTtfMaximumProfileChunkGlyph count and limits
cmapTtfCharacterMapChunkUnicode → glyph mapping (formats 0, 4, 6, 12, 14)
kernTtfKerningChunkKerning pairs
GPOSTtfGlyphPositioningChunkGlyph positioning (formats 2, 4, 5, 6)
hheaTtfHorizontalHeaderChunkHorizontal layout metrics
hmtxTtfHorizontalAdvanceChunkPer-glyph advance widths
locaTtfGlyphLocationsChunkGlyph offset table
glyfTtfGlyphTableChunkGlyph outlines
OS/2TtfWindowsMetricsChunkTypographic metrics
postTtfPostScriptChunkPostScript metadata
fpgmTtfFontProgramChunkFont program bytecode
prepTtfPreProgramChunkPre-glyph program bytecode
CPALTtfColorPaletteChunkColour palettes
COLRTtfColorLayersChunkColour layers
sbixTtfStandardBitmapGraphicsChunkBitmap 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)

ShapeRenderPipelineGlyphSampledSampledCoverage / SampledHitPositions / SampledSignedDistanceNormalizedNormalizedCoverage / NormalizedHitPositions / NormalizedSignedDistancePaintedPaintedCoverage

Atlases (full atlas processing)

ShapeRenderPipelineAtlasSampledSampledCoverage / SampledHitPositions / SampledSignedDistanceNormalizedNormalizedCoverage / NormalizedHitPositions / NormalizedSignedDistancePackedPaintedPaintedCoverage

Rendering

ShapeRendererAtlas · ShapeRendererGlyph - render pipeline outputs to raster images

Extension Methods

ShapeGraphExtensions · ShapeLayerExtensions · ShapeNodeGroupExtensions - shape graph to render pipeline conversions

Carrot