Skip to content

Layout: a per-character font fallback chain on TextStyle #601

Done

Description

@Tim81

Problem

A text style names one font. On an embedded font a character that font lacks is drawn as glyph 0 (#592); on a standard-14 font ShowText
writes ? (PdfCanvas.cs:614-650). Either way the caller has no way to
say "use font B for what font A does not cover". (origin/main 1c61fa6.)

  • src/VellumPdf.Layout/Core/TextStyle.cs:59: public FontReference FontRef { get; init; } = Standard14.Helvetica;,
    one font per style.
  • src/VellumPdf.Kernel/Fonts/EmbeddedFontHandle.cs:38-47: GetGlyphIds maps every rune through one embedder.
  • ParagraphRenderer.cs:598 tokens carry one TextStyle each, and a word is one token (:593-598).

Why it matters

A product that mixes a text font with a symbol font has to split every run by coverage by hand. That only works
once #590 is fixed (today a run boundary inside a word draws a space).

Measured 2026-11-17 with fontTools 4.62.1 on in-tree files: LiberationSans-Regular.ttf has no U+2609 and no
U+263D, and DejaVuSans.ttf has both (and 96 private-use code points at U+E000 to U+F8FF, with U+EF00 and U+F6C5
present). A planning-session measurement (2026-11-17, not re-run here) found no planet or zodiac sign in Inter,
IBM Plex Mono or Bodoni Moda, and 13 of 13 planets and 12 of 12 zodiac signs in DejaVuSansAstro.ttf. Those
three fonts and that file are verification inputs only; they are not bundled and are not committed.

Scope

  • An ordered fallback list on the style (TextStyle.FallbackFonts, or on Document; the design review decides)
    of embedded or standard-14 fonts. The first font whose cmap covers a character draws it.
  • A word that mixes fonts is one unbreakable unit and wraps as one (Layout: adjacent text runs are joined with a space that is not in the text #590's tokeniser). Measurement uses the
    glyph advance of the font that draws each character.
  • A character that no font in the chain covers is reported (Kernel: a character missing from an embedded font is written as glyph 0 (.notdef) and the save reports nothing #592) naming every font tried.
  • Each font actually used is embedded as a subset with its own ToUnicode map. ISO 19005-2 6.2.11.5 (widths in the
    font dictionary and in the program agree within 1/1000 unit) holds per font.
  • Text extraction returns the original characters in order, whichever font drew them.
  • A style with no fallback list behaves and writes exactly as today.
  • The standard-14 path is not part of the chain's coverage logic beyond WinAnsi: a standard-14 font can only
    cover what WinAnsi covers (PdfCanvas.ShowText, PdfCanvas.cs:614-650); the brief states what the chain does
    with it.

Acceptance

  • A paragraph in LiberationSans with fallback DejaVuSans and the characters U+2609 and U+263D (both in-tree
    fonts) draws them from DejaVuSans: the glyph ids come from the DejaVuSans subset, both fonts appear in the
    resource dictionary, pdftotext returns the original characters.
  • A character in neither font is reported once with both font names, and still saves in default mode.
  • A word of a + U+2609 + b wraps as one word.
  • Widths in each embedded font dictionary match the program within 1/1000 (assert on the font dictionaries).
  • A style without fallbacks produces the bytes it produces today (golden test).
  • Tests use the in-tree fonts only.
  • The test fails on origin/main 1c61fa6 (no such member), proven by mutation.

Relates to

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/fontsarea/layoutenhancementtype/feature

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions