Design: custom fonts, a shared module used first by Slides
Short design for Paul's review. Upload once per app, pick it in Deck settings, everything that can't use it falls back; pictures and the PDF embed static TrueType faces whose flags allow it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+131
−0
docs/superpowers/specs/2026-11-23-custom-fonts-design.md+131 −0
diff --git a/docs/superpowers/specs/2026-11-23-custom-fonts-design.md b/docs/superpowers/specs/2026-11-23-custom-fonts-design.md| new file mode 100644 |
| index 0000000..404fa7b |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-11-23-custom-fonts-design.md |
| @@ -0,0 +1,131 @@ |
| +# Custom fonts for Oficina, starting in Slides — design |
| + |
| +Short design, 2026-11-23, by Claude Opus 5.5 from conversation with Paul |
| +the same day. Not yet approved. |
| + |
| +## Intent |
| + |
| +Paul wants to set a deck in Timeless Sans, the face the HalfStack talk |
| +used, and the same for any font he has the right to use. Upload it once, |
| +pick it like any other font, and everything that can't use it falls back |
| +to the next font, as CSS does. Docs and Sheets should be able to use the |
| +same machinery later. |
| + |
| +Timeless Sans comes as a variable WOFF2 (`TimelessSansVF.woff2`). Its |
| +licence (Timeless Free Font License 1.2) allows embedding in a website |
| +and forbids committing it to a repository or handing it out. |
| + |
| +## Goals |
| + |
| +1. A person uploads font files to their font library in Slides and picks |
| + an uploaded family for a deck's headings or body. |
| +2. Everyone who can see the deck (editor, viewer, share and follow links, |
| + presenter and slide windows) sees it in that font, behind the font |
| + gate: no flash, and a family late past the gate's deadline falls back. |
| +3. Slide pictures and the PDF use the font when the upload is a static |
| + TrueType face whose embedding flags allow it; otherwise they fall back |
| + to the deck's next font. |
| +4. The upload, checking, storage and serving are one shared Go module that |
| + Docs can adopt without copying. |
| + |
| +## Non-goals |
| + |
| +- A suite-wide library in Home. Home stays as designed (theme only, no |
| + storage). The module keeps that door open. |
| +- Converting fonts: WOFF2 decompression and instancing variable fonts for |
| + pictures and PDF. Those files serve the web only; pictures and PDF fall |
| + back. Possible later. |
| +- Fonts from a URL or a font service. |
| +- Docs and Sheets adoption (next, separately). |
| + |
| +## Anti-goals |
| + |
| +- A font file that can attack a viewer or the server. Every upload is |
| + parsed and refused if malformed before it is stored. |
| +- A font reaching anyone who can't see a deck that uses it, or anyone |
| + else's library. |
| +- Committing or redistributing a font: files live only in the app's |
| + object store, never in a repository, a bundle or an export bundle. |
| +- A flash: the gate's rule holds. |
| +- Embedding a font in a PDF when its own flags forbid it. |
| + |
| +## Approaches |
| + |
| +1. **A shared module; fonts stored per app (chosen by Paul).** One Go |
| + module does parsing, metadata, checks, storage keys and serving; each |
| + app keeps the files in its own store. Upload once per app. |
| +2. A font library in Home. True "upload once", but reverses Home's |
| + founding rules (§5.4, theme-only preferences, no storage). |
| +3. Gotenberg (server-side Chrome) for PDFs. Not needed: Slides' own PDF |
| + engine already embeds TrueType subsets, and Chrome's output would |
| + differ from the editor and pictures. |
| + |
| +## The design |
| + |
| +**The module.** `amadan.net/oficina/estilo/typeface`, a nested module in |
| +the estilo repo beside `theme`, because estilo is already what every |
| +Oficina app imports. It owns: |
| + |
| +- `Inspect(data []byte) (Face, error)`: accepts TTF, OTF, WOFF and WOFF2; |
| + refuses anything else or anything malformed. `Face` carries the family |
| + and style names from the `name` table, weight, italic, whether it is |
| + variable (and its weight range), the outline kind (TrueType or CFF), the |
| + `OS/2` embedding flags, and a SHA-256 ref. |
| +- Limits: 10 MiB a file, 16 faces a family, 32 families a person. |
| +- `Pictures(f Face) bool`: true for a static TrueType-outline face whose |
| + flags allow embedding (installable, editable or print-and-preview). |
| +- Serving helpers: content type, `nosniff`, long caching by ref, and a |
| + CSP that allows nothing. |
| +- No storage of its own and no routes: the app gives it bytes and stores |
| + the result with its existing blob store. |
| + |
| +**In Slides.** |
| + |
| +- **Library.** A person's fonts: `fonts` rows (owner, family, faces) and |
| + the files in the object store, uploaded through the same signed-upload |
| + path pictures use, then inspected before they are kept. Account menu |
| + gains *Fonts*: a page listing families with a sample line, upload, and |
| + delete (a deck still using a deleted family keeps its own reference, |
| + below). |
| +- **Using one in a deck.** Choosing an uploaded family in Deck settings |
| + copies a reference into the deck, as pictures are: the deck's document |
| + records `{family, faces: [{ref, weight, italic, variable}]}` under |
| + `meta.fontFiles`, and the server records which refs the deck may serve |
| + (like `DeckAsset`). So anyone who can see the deck can load its fonts, |
| + and nobody can load a font through a deck that doesn't use it. |
| + `meta.fonts` keeps its stacks; the uploaded family goes first and the |
| + theme's family follows as the fallback. |
| +- **Serving.** `/d/{sqid}/fonts/{ref}`, `/s/{token}/fonts/{ref}`, |
| + `/p/{session}/fonts/{ref}`, each checking the deck's record, as assets |
| + do. Same origin, so the CSP doesn't change. |
| +- **The gate.** The manifest lists the deck's uploaded faces beside the |
| + catalog's; the editor, viewer, share, follow, presenter and slide |
| + windows all wait for them under the same deadline. |
| +- **Pictures and PDF.** The layout engine measures with an uploaded face |
| + where `Pictures` is true; the SVG names the family with the fallback |
| + stack; the PDF embeds a subset. Otherwise both use the fallback, as |
| + today. |
| +- **The core and the API.** `meta.fontFiles` travels on `set_meta` with |
| + vectors in Rust, JS and Go, as the fixtures rule requires; the API |
| + describes it; the font name pattern (`fontPattern`) already admits |
| + ordinary family names. |
| + |
| +**Words.** New strings (the Fonts page, upload errors, the Deck settings |
| +group, and a reminder to upload only fonts the person may use on the |
| +web) go through Paul's copy review before they are written. |
| + |
| +## Testing |
| + |
| +- `Inspect` against real files: TTF, OTF (CFF), WOFF, WOFF2, variable, |
| + and malformed, truncated and oversize files. |
| +- A deck in an uploaded font: viewer, share link and presenter load it |
| + behind the gate; a deck that doesn't use it can't serve it; another |
| + person can't read your library. |
| +- Pictures and PDF embed a static TrueType face, and fall back for a |
| + WOFF2, a variable font and a face whose flags forbid embedding. |
| +- Existing decks render byte for byte as today. |
| + |
| +## Left to the builder |
| + |
| +Table and column names, the page's layout within estilo's patterns, the |
| +exact limits if a real font needs more. |