Skip to content

Look up symbolic TrueType codes in code-keyed cmap subtables - #559

Merged
Velli20 merged 1 commit into
mainfrom
symbolic-truetype-code-lookup
Oct 11, 2026
Merged

Velli20 merged 1 commit into
mainfrom
symbolic-truetype-code-lookup

Conversation

@Velli20

@Velli20 Velli20 commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Summary

A simple-font code without a /Differences entry was resolved only by Unicode, through skrifa's charmap, which selects Unicode subtables only and ignores the (3,0) Symbol and (1,0) Macintosh Roman subtables. A symbolic TrueType subset (descriptor flag 3, no /Encoding) whose only cmap is (1,0) therefore resolved no glyphs, and every character was drawn with a fallback face instead of the embedded program.

PDF 32000 §9.6.6.4 maps a symbolic TrueType font's codes through its (3,0) or (1,0) subtable directly. This change:

  • adds FontFace::glyph_for_code(u8) (default None, so Type 1, CFF, Type 3 and Type 0 faces are unaffected);
  • implements it for TrueType faces: (3,0) with the code, then 0xF000 | code, then (1,0) with the code; glyph 0 counts as a miss;
  • in select_glyph, without an explicit selector, tries the code before Unicode for symbolic faces and after Unicode for other faces. Explicit glyph IDs, names and CIDs are unchanged.

Test plan

  • A document with embedded symbolic Arial/Calibri subsets carrying only a (1,0) format 6 cmap: before, hundreds of glyph fallbacks per page; after, none, and the text is drawn with the embedded outlines
  • PDFium corpus run on main and on this branch: identical document and page statuses, and no change in any page's mismatch metric
  • cargo fmt --check, cargo clippy --all --workspace
  • cargo test -p pdf-font -p pdf-text-engine -p pdf-canvas -p pdf-renderer

🤖 Generated with Claude Code

A simple-font code without a /Differences entry was resolved only by
Unicode, and the Unicode charmap ignores the (3,0) Symbol and (1,0)
Macintosh Roman subtables. A symbolic TrueType subset whose only cmap is
one of those resolved no glyphs, so its text was drawn with a fallback
face instead of the embedded program.

Add FontFace::glyph_for_code, which TrueType faces answer from the
(3,0) subtable, directly and at 0xF000 + code, and then from the (1,0)
subtable. Without an explicit selector, symbolic faces try the code
before Unicode and other faces after it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Velli20
Velli20 merged commit 5fc63f6 into main Oct 11, 2026
10 checks passed
@Velli20
Velli20 deleted the symbolic-truetype-code-lookup branch October 11, 2026 11:54
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.

1 participant