Skip to content

Fonts: derive /StemV instead of hardcoding 80 #268

Open

Description

@Tim81

TrueTypeFontEmbedder.cs:185:

.Set(new Core.PdfName("StemV"), new Core.PdfInteger(80)) // heuristic

Every font this library embeds gets /StemV 80. The comment is honest about it, which is better than
pretending, but the value is wrong for every font that is not a regular-weight text face — a light
face, a bold face and a display face all get the same stem width.

Why it is not cosmetic

/StemV is a required font descriptor entry, and it is what a reader uses to synthesise a substitute
when the embedded program is unavailable or when rendering at very small sizes. A wrong value produces
a substitute of visibly wrong weight. PDF/A requires the entry be present; nothing requires it be
true, which is exactly why it drifts.

Approaches, cheapest first

  1. From OS/2 weight class — usWeightClass (100–900) maps to a plausible stem width range. The
    table is already parsed; this is arithmetic. Crude but strictly better than a constant.
  2. Measured from the glyph outlines — the conventional approach is to measure the vertical stem of
    a known glyph such as I or l in the glyf or CFF charstrings. More accurate, more work, and it
    needs care for fonts lacking those glyphs.

Approach 1 is a clear improvement and can land first; 2 is a refinement worth noting in the issue but
not blocking on.

Acceptance

  • A light, regular, bold and black weight of the same family produce four different /StemV values,
    ordered correctly.
  • A font with no OS/2 table still produces a defensible value rather than throwing.
  • Existing documents' output changes only in /StemV — asserted by diffing, so the change is provably
    contained.

Relates to

  • C5 — the other thing OS/2 is parsed for and then not used properly.

Plan labels used above, resolved: C5 #267.

Activity

  1. added
    area/fonts
    bug
    on Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/fontsbug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions