feat(fonts): face-aware font-load planner (load used faces, not declared families)#3612
Merged
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".
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
…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.
…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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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