Repository navigation
feat(preview): add resolveFamily to keep custom font families in svg mode - #462
Merged
Merged
Conversation
…mode In `textLayout: 'svg'`, every family outside the bundled substitutes was written as Carlito, so a host embedding its own @font-face rules could not get its fonts applied. `RenderSlideOptions.resolveFamily` now maps each authored font name to the family written to the SVG and passed to `measureText`, including in the shrink-to-fit search. Closes #461 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
… face A family returned by `resolveFamily` that is not a sequence of CSS identifiers (e.g. "M PLUS 1p") made the font-family value invalid, so it is now quoted in the SVG. The audit's shrink-to-fit search now measures with the same authored family its layout pass uses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The previous commit quoted every family at emit time, which wrapped the browser path's whole CSS stack (used by gradient-fill, reflection and bevel overlays in default mode) as one family name. Quoting now happens where a single resolved name becomes a piece, and the browser stack is written verbatim. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
renderSlideToSvg(…, { textLayout: 'svg' })wrote every font other than the Calibri / Cambria / Arial / Times / Courier families asCarlito, so a host that shows the SVG as a sanitized<img>and embeds its own@font-facerules could not get Lora / Inter / etc. applied. This addsRenderSlideOptions.resolveFamily, which maps each authored font name to the family written to<text font-family>and passed tomeasureText.Motivation
Closes #461
The hook already existed internally (
SvgTextArgs.resolveFamily, used by the audit path and the foreignObject path); this exposes it for svg mode, as proposed in the issue. Afonts: [{ family, src }]option that also embeds@font-facewas the alternative, but it would put font loading inside the library; the host already owns that.Changes
RenderSlideOptions.resolveFamily?: (family: string | null) => string. Consulted only whentextLayoutis'svg'; defaults tosubstituteFamily, so output is unchanged when it is not passed.<a:normAutofit/>) search, so the measurer sees the same family for fitting and for laying out.M PLUS 1p) is quoted in the SVG; otherwise the browser would drop the wholefont-familyvalue. The measurer still receives the bare name. The default substitute names are identifiers, so default output is unchanged.auditTextLayout: its shrink-to-fit search measured with the substitute family while its layout pass used the authored one; both now use the authored family.renderSlideToImage) doesn't take the option yet — resvg matches a font file's internal family name, so keeping the emitted name, the resvg name and the measurer key consistent needs its own design.Testing
test/preview-resolve-family.test.ts: default substitution unchanged; kept family is written to the SVG and handed to the measurer; table cells; autofit search measures with the resolved family; foreignObject output is identical with or without the option. quoting of non-identifier names; audit fit/layout family consistency. Each fails without the corresponding change (the autofit one fails if only the fit threading is removed).npx vitest run(full suite),oxlint,oxfmt --check,tsc --noEmitpass locally.Breaking changes
None
Checklist
flagged it above.
comments.
PR represents real work that warrants a maintainer's review, and I am
willing to defend each line in review.
🤖 Generated with Claude Code