Skip to content

Map MSTT GNN/gNNN/cidNNN glyph-index names to Unicode - #4

Open
lfoppiano wants to merge 1 commit into
mainfrom
bugfix/work-on-glyphs
Open

Map MSTT GNN/gNNN/cidNNN glyph-index names to Unicode#4
lfoppiano wants to merge 1 commit into
mainfrom
bugfix/work-on-glyphs

Conversation

@lfoppiano

@lfoppiano lfoppiano commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Summary

Recover real Unicode for subset fonts whose glyphs are named by glyph index rather than by a semantic character name, which xpdf's pass-2 heuristic otherwise misreads (e.g. G34 → the literal '4', g50'2'), garbling body text in MSTT MSTT31c… fonts that carry no ToUnicode.

Changes

  • FoFiTrueType::getMacGlyphName(gid) — exposes the existing 258-entry standard Macintosh glyph-name table (macGlyphNames), bounds-checked.
  • GfxFont.cc:
    • mapHexGlyphIndexName() — MSTT uppercase-G + hex index naming (glyph 0 / .notdef dropped, so the index is offset by one; optional .suffix ignored).
    • mapGlyphIndexName()decimal index naming with a longest-prefix-first, case-insensitive prefix set (glyph, index, cid, g, c).
    • Wired into the Gfx8BitFont constructor: tried before the generic hex/numeric heuristic (and the Type 3 identity fallback), resolving the index through the standard Mac glyph ordering to recover the intended Unicode.

Validated downstream

Built into pdfalto (see kermitt2/pdfalto#234), degruyter MSTT documents now extract Received/Contributions instead of the Caesar-shifted 4GEGKXG/8QNWOG.

Resolve glyph-index-named glyphs (hex 'GNN' MSTT and decimal 'gNNN'/'cidNNN'/
'glyphNNN'/'indexNNN'/'cNNN') through the standard Macintosh glyph ordering
before the pass-2 hex/numeric heuristic, which otherwise garbles MSTT subset
fonts with no ToUnicode (e.g. 'Received' -> '4GEGKXG'). Adds
FoFiTrueType::getMacGlyphName() to expose the 258-entry Mac glyph table.
@lfoppiano lfoppiano changed the title feat: map MSTT GNN/gNNN/cidNNN glyph-index names to Unicode Map MSTT GNN/gNNN/cidNNN glyph-index names to Unicode Jun 30, 2026
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