Skip to content

feat(fonts): face-aware font-load planner (load used faces, not declared families)#3612

Merged
caio-pizzol merged 8 commits into
mainfrom
caio/font-load-planner
Jun 3, 2026
Merged

feat(fonts): face-aware font-load planner (load used faces, not declared families)#3612
caio-pizzol merged 8 commits into
mainfrom
caio/font-load-planner

Conversation

@caio-pizzol
Copy link
Copy Markdown
Contributor

Stacked on caio/font-load-gate-t3 (PR #3608) — review that first; this diff is the planner only.

Makes the load gate await the exact physical font faces a document renders — family + weight + style — instead of every family declared in the docx fontTable. Two problems this fixes: bold/italic text measured against the regular face (or a synthesized faux-bold) and reflowed once the real face arrived; and a larger font pack would over-fetch declared-but-unrendered fonts. This is the prerequisite that makes scaling past the current five-font pack safe.

What changed

  • @superdoc/font-system: a FontFaceRequest type and face-keyed registry APIs (awaitFaceRequest(s), getFaceStatus, weight/style-specific probes like italic 700 16px "Carlito"). register() seeds face-level status; getStatus(family) rolls up from faces for diagnostics — a failed/timed-out used face outranks a loaded sibling so a broken face is never masked.
  • font-load-planner.ts: walks the layout input (blocksForLayout, available before measure) — paragraph runs, table cells, list item paragraphs, and the word-layout marker run — and emits the deduped physical faces actually rendered, resolving logical→physical with the same resolver measure and paint use.
  • The gate gains a getRequiredFaces path (family path kept as fallback); its late-load handler reflows only when a loaded face matches a required one (“the bold face loaded”, not “the family loaded”).
  • Declared-font diagnostics (getDocumentFonts / getReport) are unchanged and stay separate from the narrowed load set.

Verified

  • Live: a doc declaring Arial/Times/Aptos but rendering only Calibri loads only Carlito (no Liberation Serif for declared-but-unused Times); bolding the text then loads Carlito-Bold.woff2 (the old family-only gate never did, causing a measured ~2% bold-width drift).
  • Repo typecheck clean; unit tests for the planner (extraction/dedupe/table/list/marker/unmapped/stack), the registry face APIs + rollup, and the gate face-path late-load (regular load → no reflow, bold load → one reflow).

Not included

  • The larger font pack itself.
  • The bounded late-load reflow scheduler (the next step for font-heavy docs on slow networks).
  • Per-numeric-weight faces (the run model is binary bold/italic; pack ships 400/700 × normal/italic).
  • List-marker fonts are planned from the paragraph's word-layout marker run; a marker whose font is resolved only at measure time outside that structure is not separately planned.

…red families)

The load gate waited on every family declared in the docx fontTable and only
ever loaded each family's regular face. Two problems: bold/italic text measured
against the regular face (or faux-bold) and reflowed once the real face loaded;
and a large pack would over-fetch declared-but-unrendered fonts.

The planner walks the layout input (blocksForLayout, available before measure)
and emits the exact physical faces the document RENDERS - family + weight +
style - resolving logical to physical with the same resolver measure and paint
use. The gate awaits those faces (weight/style-specific probes) and its late-load
handler reflows only when a loaded face matches a required one. Declared-font
diagnostics (getDocumentFonts / getReport) are unchanged; the registry now keys
load state per face and rolls a family up for the report (a failed used face
outranks a loaded sibling, so it is not masked).

Prerequisite for scaling to a larger font pack. Does not add the pack, the
late-load reflow scheduler, or per-numeric-weight faces.
@caio-pizzol caio-pizzol marked this pull request as ready for review June 3, 2026 11:27
@caio-pizzol caio-pizzol requested a review from a team as a code owner June 3, 2026 11:27
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a2ddf5ac46

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 9 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/super-editor/src/editors/v1/core/presentation-editor/fonts/font-load-planner.ts">

<violation number="1" location="packages/super-editor/src/editors/v1/core/presentation-editor/fonts/font-load-planner.ts:67">
P2: Table-cell nested blocks are only partially traversed, so some rendered fonts can be omitted from the load plan.</violation>

<violation number="2" location="packages/super-editor/src/editors/v1/core/presentation-editor/fonts/font-load-planner.ts:91">
P3: `ListBlock` traversal in the planner is dead code for the runtime layout path, because `blocksForLayout` is paragraph/table based and does not include `kind: 'list'` blocks.

(Based on your team's feedback about no runtime ListBlock in layout.) [FEEDBACK_USED]</violation>
</file>

<file name="packages/super-editor/src/editors/v1/core/presentation-editor/fonts/FontReadinessGate.ts">

<violation number="1" location="packages/super-editor/src/editors/v1/core/presentation-editor/fonts/FontReadinessGate.ts:172">
P1: If face planning throws, the gate now skips font loading altogether instead of falling back to the family path, which can let fallback metrics reach layout.</violation>
</file>

Tip: cubic used a learning from your PR history. Let your coding agent read cubic learnings directly with the cubic MCP.

Re-trigger cubic

caio-pizzol and others added 2 commits June 3, 2026 10:39
…planner throw

Two review follow-ups on the face-aware planner:
- A font used only in a header/footer was never planned: #fontPlanBlocks held only
  body+notes, but incrementalLayout also measures header/footer blocks, so that face
  measured against fallback and reflowed on late load. Build the header/footer input
  before the gate and feed its blocks into the same planRequiredFontFaces input
  (planner dedups, so getBatch/getBlocksByRId overlap is harmless).
- If face planning ever throws, the gate skipped loading entirely; degrade to the
  family path (which still awaits the resolved physical families) instead. Add a
  regression test.
Base automatically changed from caio/font-load-gate-t3 to main June 3, 2026 14:02
caio-pizzol and others added 3 commits June 3, 2026 11:50
…per-family

Follow-ups from review of the face-aware planner:
- Paginated footnotes are measured via layoutOptions.footnotes (not blocksForLayout),
  so footnote-only faces were unplanned and reflowed on late load. Flatten the
  footnote blocks into the same planner input (semantic mode already folds them in).
- A drop cap is measured from attrs.dropCapDescriptor.run with its own often-distinct
  font; collect that run in the planner.
- A field annotation with no explicit font is measured against 'Arial' by the
  measurer; mirror that default in the planner instead of skipping the run.
- FontLoadSummary is documented as per-family and rides the public fonts-changed
  payload, but summarizeFaces counted per face (3 Carlito faces -> loaded: 3). Collapse
  to per-family, taking each family's worst face status.
- Assert the gate forwards its configured timeoutMs to the registry (test gap).
…s fix

- Drop the summarizeFaces line claiming counts are per-face; it now collapses to
  per-family (the function's own comment already documents this).
- Generalize the planRequiredFontFaces docstring: the caller passes every measured
  block (body, notes, header/footer, paginated footnotes), so the old "appended to
  blocks" wording no longer describes the paginated-footnote path.
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@caio-pizzol caio-pizzol merged commit f6035b5 into main Jun 3, 2026
69 checks passed
@caio-pizzol caio-pizzol deleted the caio/font-load-planner branch June 3, 2026 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants