Skip to content

Generating Font Data

The Tegaki generator processes Google Fonts through a multi-stage pipeline to produce stroke data suitable for handwriting animation. Use the interactive generator on the Tegaki website to generate font bundles directly in the browser.

Each glyph goes through these stages:

  1. Extract — opentype.js extracts path commands and metrics
  2. Flatten — Adaptive de Casteljau subdivision converts bezier curves to polyline segments
  3. Rasterize — Scanline fill with nonzero winding rule produces a binary bitmap
  4. Skeletonize — Zhang-Suen thinning reduces the bitmap to 1px-wide skeleton
  5. Trace — Walks skeleton pixels into polylines, prunes short spurs, simplifies with Ramer-Douglas-Peucker
  6. Width — Distance transform computes stroke width at each skeleton point
  7. Stroke order — Groups polylines into connected components, sorts top-to-bottom/left-to-right
OptionDefaultDescription
FontCaveatGoogle Font family name
CharactersA-Za-z0-9 + punctuationCharacters to process
Resolution400Bitmap resolution for rasterization
Skeleton methodzhang-suenSkeletonization algorithm
Line caproundStroke line cap style
Bezier tolerance0.5Flatness tolerance for bezier subdivision
RDP tolerance1.0Ramer-Douglas-Peucker simplification tolerance

The generator outputs a compressed format with short keys to minimize bundle size. Per-glyph data includes w (advance width), t (total animation duration), and s (strokes). Each stroke has p (points as [x, y, width] tuples), d (delay), and a (animation duration). See the TegakiGlyphData type for full details.

Use the interactive generator tool to visualize each pipeline stage and fine-tune options.