Encoding CMap Decoding

Fonts, Unicode, Rendering, Extraction

Description

Encoding CMaps are parsed and bound to a descendant CIDFont, with codespace and cidchar/cidrange limits, inherited codespaces, declared metadata, notdef fallbacks and invalid-code recovery driving native rendering, extraction and content analysis. Reach for it when a Type0 font decodes to unexpected CIDs, when inheritance or a custom CMap is rejected, or when embedded and external glyph sources disagree on a code.

Native composite-font decoding

Native rendering, text extraction, and content-state analysis use verified Encoding CMaps for supported Type0 fonts, including predefined resources and declarative stream inheritance

Character codes contain one to four bytes. Decoding preserves the original byte sequence, its length, and the mapped CID separately; glyph selection then follows the font's CID-to-glyph mapping

Verified WMode values determine horizontal or vertical movement. A custom CMap name ending in -H or -V does not override its verified writing mode

Declarative mapping constraints

Each codespace, cidchar, cidrange, notdefchar, or notdefrange section accepts at most 100 entries. Multiple sections retain the aggregate source and range limits

All normal and explicit notdef mapping codes must belong to the combined codespace of their byte length. Inherited codespaces participate in this check. Numeric endpoints alone do not establish coverage when the corresponding per-byte domains contain gaps

Codespaces of the same byte length may overlap, for example a local range that repeats part of an inherited one; they describe the union of their codes, and each code is counted once. Codespaces of different lengths are rejected when a shorter code is a prefix of a longer one, because the byte sequence would be ambiguous

When the dictionary UseCMap entry is a stream, a body usecmap operator agrees with it when it names the stream's CMapName

The domain check counts intersections with disjoint byte rectangles without expanding the codes. A four-byte notdef range can therefore cover the complete 32-bit domain within the normal planning limits

The usefont operator is supported only with descendant number zero. Other descendant numbers remain unsupported in PDF Encoding CMaps

Section and descendant rules follow Adobe Technical Note 5014 and ISO 32000-2 section 9.7.5.4

Declared metadata and source identity

A declared stream Type must be CMap. CMapName is a nonempty name of at most 127 bytes; when supplied in the stream dictionary it must also be declared in the body with the same value

A declared CIDSystemInfo has Registry, Ordering and Supplement exactly once in its body dictionary. Registry and Ordering are nonempty ASCII byte strings of at most 65535 bytes, and Supplement is a non-negative integral value. Both literal dictionaries and the supported dict/begin/def form are read without executing PostScript

When CIDSystemInfo is supplied in the stream dictionary, all three values must match the body. Inheritance compares Registry and Ordering for character-collection compatibility; Supplement is not a compatibility discriminator

Standard CIDInit prologs and paired CMap envelopes are recognised. Unknown nested dictionary scopes and declarations after endcmap cannot install metadata, and a body usecmap reference must precede mapping sections

Metadata fields, absent optional fields, scalar values, indirect reference numbers and targets, and stream-dictionary identity are retained and rechecked after parsing and before an exact edit commits. Replacing an object with an equal value still changes its source identity

Metadata capture is bounded separately and charged to the shared transaction source budget. Parser-created names for inherited resources remain owned by the map for the snapshot lifetime

Supported mapping fragments may omit metadata; accepting such a fragment does not certify all required entries of a complete PDF CMap. The descendant checks below apply when the parsed map is used with a font; full format conformance remains a separate check

Metadata rules follow ISO 32000-2 sections 9.7.3 and 9.7.5.3, Table 118, and Adobe Technical Note 5014

External font glyph selection

For qualified external Type 2 CIDFonts, supported named predefined CMaps supply source-code Unicode values for glyph selection in the actual loaded standalone TrueType program. CIDToGIDMap and ToUnicode do not override this selection; the original mapped CID continues to supply PDF metrics

Traditional predefined encodings can translate through the bundled Adobe Japan1, GB1, CNS1 and Korea1 character collections when a code has a single-scalar Unicode result. Translation re-derives the collection selector from original bytes and width; the decoded metric CID does not become a font glyph index, and multi-scalar results cannot authorise exact replacement

Supported UCS-2, UTF-8, UTF-16BE and UTF-32BE inputs retain their full source bytes. Leading FE FF bytes remain character codes, invalid Unicode scalars do not authorise a glyph, and missing glyphs display known glyph zero whilst exact editing rejects unverified correspondence

See Composite font glyph qualification for source, cache, resource and remaining external-font boundaries

Descendant character-collection binding

GetVerifiedEncoding binds a parsed map to its actual descendant CIDFont before returning it for verified decoding or measurement. The descendant CIDSystemInfo must be a dictionary with Registry, Ordering and Supplement, using the same bounded string and integer rules as CMap metadata

When the effective CMap declares a character collection, its Registry and Ordering must match the descendant values exactly. Supplement values may differ in either direction. Identity-H and Identity-V accept every valid descendant character collection; a custom CMap that declares Adobe-Identity still undergoes the ordinary exact comparison

Inherited character collections are checked even if the local stream omits CIDSystemInfo. Mapping fragments without any effective collection declaration retain their existing parsing behaviour and do not establish complete format conformance

The binding retains descendant field identities, scalar values and indirect-reference chains in the metadata snapshot. Equivalent object replacements and supplement changes invalidate the source check even when collection compatibility would remain unchanged. Binding is fixed for a cached font analysis; failures do not rebase onto later changes

Incompatible collections return no verified codes or displacement and reject exact replacements before selected page content and resource roots are committed. Supported embedded and qualified external native rendering and text-to-path conversion report the failure instead of retrying legacy decoding; other external and unavailable native glyph sources retain their separate eligibility boundary

See ISO 32000-2 §9.7.3 and Table 114 for character-collection compatibility and §9.7.5 for CMaps

Embedded-font missing glyphs

For supported native embedded CFF1 and TrueType font sources, decoding separates the original mapped CID from the glyph selector. If the normal CID has no glyph, the font consults the explicit notdef mapping; if that selector also has no glyph, it uses the glyph for CID zero

A valid code with neither a normal nor an explicit notdef mapping can use CID zero when that embedded font supplies a known fallback glyph. A normal mapping with a present glyph takes precedence over notdef mappings

Unicode lookup retains the complete original source bytes. Horizontal and vertical advances retain the original mapped CID's metrics, or the initial notdef/default CID when no normal mapping exists. Glyph substitution does not replace those metrics with the substitute glyph's widths

Extraction marks substituted glyphs with PDF_TEXT_CHAR_UNICODE_FALLBACK whilst preserving an available ToUnicode result. Exact editing continues to require verified original and replacement glyph correspondence; displaying a fallback does not establish that correspondence

Unqualified external fonts and unavailable native glyph sources retain their existing decoding paths. Invalid-code recovery follows the rules below when a known embedded CID-zero or qualified external glyph-zero source is available

Invalid input codes

For supported native embedded and qualified external glyph sources, a code outside all Encoding codespaces uses glyph zero and metric CID zero. The decoder resets to that code's starting position and chooses the range with the longest matching byte prefix; equal prefix lengths choose the shortest code length. With no matching first byte, it chooses the shortest codespace length

The selected length determines consumption. At the end of an operand, a truncated code consumes only the remaining source bytes and separately retains its expected length. Bytes are never read or fabricated beyond the operand, and the next text-showing operand starts a new decoding operation

Recovery does not turn a valid but unmapped code into an invalid code. Explicit notdef and default CID-zero mappings for valid codes retain their separate selection rules

Extraction retains an available ToUnicode result for the actual source bytes whilst reporting PDF_TEXT_CHAR_UNICODE_INVALID and PDF_TEXT_CHAR_UNICODE_FALLBACK. Recovered display text does not authorise exact source editing; strict transaction decoding still rejects invalid codes

A truncated multibyte code with only byte 20 remaining is not a single-byte space. Rendering, displacement measurement and text-to-path conversion use the selected code length when applying word spacing

Each decoding operation shares a 16777216-step codespace work limit, along with the existing source-byte and decoded-code limits. A known embedded or qualified external glyph path reports limit failures and cannot retry through legacy splitting

Invalid-code selection follows ISO 32000-2 section 9.7.6.3. Unqualified external or unavailable native glyph sources retain their existing paths

Spacing and Unicode

Character spacing applies after each decoded code. Word spacing applies only to a single-byte code 20, including in a mixed-length CMap; a two-byte code 0020 does not receive that spacing

Verified composite-font ToUnicode lookup uses complete source bytes, retaining distinctions between different byte lengths that have the same numeric value. Ligature and supplementary mappings retain their complete Unicode sequences

Text-showing operands contain font codes. A leading FE FF sequence remains part of those codes, rather than a Unicode text-string marker; metadata and ActualText retain their separate PDF text-string rules

Extraction locations

GetTextBlockCharContentLocation returns the decoded operand's actual byte offset and code length. Multiple UTF-16 positions produced by one glyph can share the same source range

Vertical extraction follows the column baseline with DW2 and W2 advances, whilst horizontal scaling affects glyph width independently of vertical cursor movement

Coverage and editing boundaries

Composite horizontal metrics retain real DW and W widths, and staged replacement rechecks its Encoding, horizontal-width, and used vertical-metric sources before commit; see CID Font Widths

The reader accepts supported declarative codespaces, CID mappings, explicit notdef mappings, and bounded inheritance without executing PostScript. Declared metadata consistency is checked as described above; complete CMap conformance remains a separate qualification boundary. It is not a complete CMap or font conformance validator

Unsupported encodings retain the ordinary renderer's existing fallback behaviour. Unknown or invalid Unicode mappings remain visible through extraction diagnostics

Exact replacement has additional source, metric, and ownership requirements. Vertical exact editing retains Identity-V support and qualifies additional Encoding CMaps with verified embedded TrueType or CFF1 glyph sources, or qualified external TrueType sources; see Composite Font Glyph Sources. Decoding support alone does not authorise every custom CMap edit

The raw character-byte editor retains its existing read-only restrictions for nested and otherwise unverified sources