Skip to content

Embedded subset fonts and fallback chains in SVG export - #2629

Merged
JanKallman merged 5 commits into
develop9from
svg-subsetting
Nov 27, 2026
Merged

JanKallman merged 5 commits into
develop9from
svg-subsetting

Conversation

@swmal

@swmal swmal commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Embedded subset fonts and fallback chains in SVG export

Summary

Shapes and charts exported to SVG now render with the same fonts the text was measured with, in any browser, independent of the fonts installed on the viewer's machine.

Fonts

  • Embedding (SvgRenderOptions.EmbedFonts, default true): fonts are embedded as subsets via @font-face. Only fonts with an open licence (OFL, Apache, Ubuntu, Bitstream Vera) and fonts bundled with EPPlus are embedded by default. Commercial fonts are referenced by name, followed by an embedded safety net (ultimately Archivo Narrow). OnFontEmbedding can override this per font, using FontEmbeddingInfo.Target.
  • Font stacks: every font-family lists the measured font, glyph fallbacks with their script chains, the fallback chain and a generic family. Glyph fallbacks written by name get their own tspan, so browsers cannot pick a different font for those characters.
  • Unhinted web subsets: SubsetOptions.RemoveHinting removes cvt/fpgm/prep, glyph instructions and the maxp hinting limits, producing a valid unhinted font. A three-kana BIZ UDGothic subset shrinks from ~8.5 kB to ~3 kB. PDF export is unchanged.

Robustness against host pages

  • A scoped rule (.epplus-svg text, .epplus-svg tspan { … !important }) protects kerning, ligatures, spacing and synthesis from host CSS.
  • Font properties and fill are written as inline styles rather than presentation attributes.
  • textLength keeps each run at its measured width.

Fixes

  • Underline combined with strike-through produced invalid CSS.
  • Bold/italic now follow the measured subfamily.
  • A failed subset falls back to its name plus a safety net instead of vanishing from the stack.

Tests

  • New tests for subsetting, licence detection, stacks, unhinted subsets and the style output.
  • SvgBrowserCheckTests.WriteBrowserCheckPage (category Manual) writes a visual check page. Verified in Chrome, Edge and Firefox. Safari/WebKit pending.

@swmal
swmal requested a review from JanKallman November 26, 2026 13:00
@swmal swmal self-assigned this Nov 26, 2026
@JanKallman
JanKallman merged commit b07de81 into develop9 Nov 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants