feat(fonts): face-aware font-load planner (load used faces, not declared families)#3612
feat(fonts): face-aware font-load planner (load used faces, not declared families)#3612caio-pizzol wants to merge 3 commits into
Conversation
β¦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.
89f3651 to
fd58a97
Compare
There was a problem hiding this comment.
π‘ 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".
| // Stash the blocks this render will measure so the gate's planner extracts the | ||
| // exact used faces (footnote/endnote blocks are already part of blocksForLayout). | ||
| this.#fontPlanBlocks = blocksForLayout; |
There was a problem hiding this comment.
Include header/footer blocks in the face plan
When a font or style is used only in headers/footers, this stashes only blocksForLayout (body plus semantic notes) before the gate runs, while #buildHeaderFooterInput() is called afterward and incrementalLayout measures those header/footer blocks via layoutHeaderFooterWithCache. In that scenario the new face planner never awaits the header/footer face, and the late-load handler also ignores its loadingdone event because the face key is not in #requiredFaceKeys, so header/footer text can be measured and cached with fallback metrics without a reflow.
Useful? React with πΒ / π.
There was a problem hiding this comment.
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
| required = getRequiredFaces(); | ||
| } catch { | ||
| return this.#lastSummary ?? emptySummary(); | ||
| } |
There was a problem hiding this comment.
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.
Prompt for AI agents
Check if this issue is valid β if so, understand the root cause and fix it. At packages/super-editor/src/editors/v1/core/presentation-editor/fonts/FontReadinessGate.ts, line 172:
<comment>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.</comment>
<file context>
@@ -143,6 +159,55 @@ export class FontReadinessGate {
+
+ let required: FontFaceRequest[];
+ try {
+ required = getRequiredFaces();
+ } catch {
+ return this.#lastSummary ?? emptySummary();
</file context>
| required = getRequiredFaces(); | |
| } catch { | |
| return this.#lastSummary ?? emptySummary(); | |
| } | |
| try { | |
| required = getRequiredFaces(); | |
| } catch { | |
| return this.#ensureFamiliesReady(); | |
| } |
| for (const row of table.rows) { | ||
| for (const cell of row.cells) { | ||
| collectParagraph(out, cell.paragraph); | ||
| if (cell.blocks) for (const b of cell.blocks) collectBlock(out, b as FlowBlock); |
There was a problem hiding this comment.
P2: Table-cell nested blocks are only partially traversed, so some rendered fonts can be omitted from the load plan.
Prompt for AI agents
Check if this issue is valid β if so, understand the root cause and fix it. At packages/super-editor/src/editors/v1/core/presentation-editor/fonts/font-load-planner.ts, line 67:
<comment>Table-cell nested blocks are only partially traversed, so some rendered fonts can be omitted from the load plan.</comment>
<file context>
@@ -0,0 +1,109 @@
+ for (const row of table.rows) {
+ for (const cell of row.cells) {
+ collectParagraph(out, cell.paragraph);
+ if (cell.blocks) for (const b of cell.blocks) collectBlock(out, b as FlowBlock);
+ }
+ }
</file context>
| case 'table': | ||
| collectTable(out, block); | ||
| break; | ||
| case 'list': |
There was a problem hiding this comment.
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.)
Prompt for AI agents
Check if this issue is valid β if so, understand the root cause and fix it. At packages/super-editor/src/editors/v1/core/presentation-editor/fonts/font-load-planner.ts, line 91:
<comment>`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.) </comment>
<file context>
@@ -0,0 +1,109 @@
+ case 'table':
+ collectTable(out, block);
+ break;
+ case 'list':
+ collectList(out, block);
+ break;
</file context>
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: aFontFaceRequesttype and face-keyed registry APIs (awaitFaceRequest(s),getFaceStatus, weight/style-specific probes likeitalic 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.getRequiredFacespath (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β).getDocumentFonts/getReport) are unchanged and stay separate from the narrowed load set.Verified
Carlito-Bold.woff2(the old family-only gate never did, causing a measured ~2% bold-width drift).Not included