Files
AniCraft/docs/adr/0012-text.md
T
Tanish Manku 912d524c6e feat(text): carets move the way the arrows point through mixed directions, and the commands say which font lent letters (M5)
In a field while a movie plays, Left and Right move the caret by where text is displayed,
crossing lines by the paragraph's direction, and a selection across a change of direction is
highlighted in its separate stretches. text.create and text.edit return a note naming the
families letters were borrowed from and how many characters no installed font has; the stage
shows it in the status bar. craft-text is pinned to the craft-libs commit the app already
uses. ADR 0130, the guide, the roadmap and the parity matrix say what is done and what is
left; outside PRs #39 and #40 are credited.
2026-11-23 13:11:02 -07:00

3.8 KiB

ADR 0012: Text

  • Status: accepted (2026-11-07)
  • Relates to: roadmap M5 (text engine), ADR 0001 (persistent document), ADR 0002 (render pipeline), ADR 0005 (typography and fonts)

Context

Titles, captions, speech bubbles and credits are some of the most common things animators put on the stage, and Animate documents are full of text. Text depends on fonts, and fonts differ between computers: a document made on one machine may be opened on another that lacks its typeface. The renderer is the oracle (AGENTS.md rule 4) and evaluate must stay pure (rule 3), so neither may depend on which fonts happen to be installed.

Decision

  1. A text element keeps its source and its outlines. ElementKind::Text(Arc<TextBlock>) stores the text and its style (font family, size, bold, italic, colour, alignment, letter and line spacing, and an optional width that wraps lines), plus the glyph outlines the engine computed for them (outline: Arc<Path>, local coordinates, top-left at the origin) and the layout box. The outlines are saved with the document.
  2. Rendering uses the outlines only. evaluate turns a text element into one filled display item, so the stage, every export (PNG, GIF, SVG, Lottie, sprite sheet, video) and hit testing treat it like a shape. A document looks the same on every computer, with or without its fonts. Exactness comes from the font data and the shaper, not from the platform's text rendering.
  3. The engine lays text out when it changes. Creating or editing a text element (a command, so undoable) shapes it with the fonts on this computer and stores the new outlines. Opening a document never re-shapes it. If the stored family isn't installed, editing falls back to the default family; the element records the family actually used and the command says so.
  4. A text crate (anicraft-text, layer 1) owns fonts and layout. It finds fonts with fontdb (system folders, CRAFT_FONTS_DIR, and faces the app registers, such as its embedded Inter), shapes with harfrust (a HarfBuzz port), reads outlines and metrics with skrifa, and breaks lines (paragraphs at line breaks; with a width, greedily at spaces). These crates are already in the dependency tree through egui, so no new licences. Text that mixes directions (Arabic or Hebrew with numbers or Latin words) follows the Unicode bidi algorithm, and letters the chosen face doesn't have (Arabic in Inter, say) come from a fallback face: ADR 0130. Bold and italic pick the matching face of the family; there is no synthetic styling.
  5. Break Apart turns a text element into a shape with the same outlines, as Animate's second Break Apart does.

Consequences

  • Files with text are bigger than the characters alone (the outlines are a vector path per block, stored like any shape's path).
  • Changing a font on a computer that lacks it changes the look of that block only when it is edited, and the user is told.
  • Text in Animate documents imports onto this model (ADR 0014).
  • Not yet: per-character styles in one block, vertical text, text along a path, font embedding for export (a character no installed face has draws as the font's "notdef" box, and the command says so: ADR 0130).

Note (2026-11-11): text fields

Dynamic and input text fields are built on this model (ADR 0066): a block with field settings, whose box is the field's and whose stored outline is its authored text laid out inside the box, so rendering still uses only the outlines. Text a script sets or a viewer types is laid out by the player's host with the fonts on the computer that plays it.

Note (2026-11-12): text on a path

Static text can follow a path (ADR 0070): the block keeps a copy of the path, glyphs are set along it by arc length and stored as outlines as before, so rendering still needs no fonts.