Expand description
PDF simple-font encoding resolver — /Encoding dictionary +
/Differences array → 256-entry byte → Unicode map.
ISO 32000-1:2008 §9.6.6.1 “Type 1 Encodings” defines a simple
font’s /Encoding as either a single name
(WinAnsiEncoding / MacRomanEncoding / MacExpertEncoding /
StandardEncoding) or a dictionary with a /BaseEncoding name
and an optional /Differences array. The array is a flat sequence
of (code, glyph-name, glyph-name, …, code, glyph-name, …): every
numeric starts a new run of code points, and every following name
token is the glyph at the next consecutive code. Each glyph name is
mapped to a Unicode scalar value via the Adobe Glyph List
(docs/document/pdf/agl/subset.txt).
Round 28 wires this resolver into the text-extraction path so a
simple font whose /Encoding carries /Differences decodes to the
correct Unicode payload (matching what pdftotext produces).
§Provenance
ISO 32000-1:2008 §9.6.6.1 (Type 1 Encodings) + §D.2 (Latin character set) for the encoding tables; Adobe Glyph List v2.0 (public document, 5 Sep 2002) for the glyph-name → Unicode mapping. No third-party PDF library SOURCE was consulted.
Structs§
- Encoding
Differences - Parsed
/Differencesarray — flat list of(code, name)overrides. - Encoding
Map - 256-entry byte → Unicode (UTF-8 string) map. Most entries hold a
single
charbut the AGL also defines ligature glyphs whose expansion is multi-character (/fi→ “fi”), so the slot has to accommodate a shortString. Slots for unassigned bytes hold the empty string — the decoder emits U+FFFD when it sees one. - Encoding
Override - One
/Differencesarray override: at code pointcode, the rendering glyph isglyph_name.
Enums§
- Base
Encoding - The named base encodings ISO 32000-1 §9.6.6.1 + §D.2 define for simple Type 1 / TrueType fonts.
Functions§
- apply_
encoding_ differences - Overlay
differenceson top ofbase, returning a fresh map. The base map is left untouched (cheap clone —Stringallocations are per-entry). - glyph_
name_ to_ unicode - Adobe Glyph List lookup. Returns the UTF-8 expansion of a PostScript
glyph name (multi-char for ligatures like
/fi, single-char for the common case). ReturnsNonefor unknown names — the caller emits U+FFFD as a marker. - parse_
encoding_ differences - Parse a
/Differencesarray — flat[N name1 name2 … M nameK …].