PdfNameTree Class

Definition

A name tree: a sorted map from string keys to objects, spread over a tree of node dictionaries. A live view.

[SuppressMessage("Naming", "CA1710:Identifiers should have correct suffix", Justification = "The name is the ISO 32000-2 term (§7.9.6).")]
public sealed class PdfNameTree : IEnumerable<KeyValuePair<CosString, CosObject>>, IEnumerable

Remarks

ISO 32000-2 §7.9.6, Table 36 (PDF 1.2). Keys are strings compared byte by byte (Annex J.3.3): (a) and the UTF-16BE key <FEFF0061> are different keys even though both read as "a". The tree is read lazily: a lookup loads one node per level, guided by each node's Limits; enumeration walks the whole tree in order. Values come back resolved one level (a value stored as an indirect reference returns the object it refers to).

Damaged trees are read leniently. A node without usable Limits, a key outside its node's Limits, keys out of order, a key that appears twice, a node reached twice (a cycle), a tree deeper than 64 levels, an odd-length Names array, and a key that is not a string are each reported once per node as a diagnostic; lookups then fall back to an index of every key, built once by walking the whole tree and kept until a node of the tree changes. When a key appears twice, the first occurrence in tree order is the one both lookups and enumeration return once a walk has met the damage (until then a lookup follows the Limits it finds). Diagnostics are reported when the damage is first read, so in strict mode the lookup or enumeration that meets it throws a DiagnosticException, not Open(String).

Editable in place (issue #146): Set(CosString, CosObject) inserts or replaces a key and Remove(CosString) removes one, changing only the nodes on the way from the root to the key's leaf and keeping every Limits entry correct; see CreateNameTree(IEnumerable<KeyValuePair<CosString, CosObject>>) for building a new tree. A damaged tree is rebuilt balanced on its first edit.

Safe for concurrent reads while nobody changes the document; edits are single-threaded, like every change to a document.

Tip: use kind:method, kind:property, kind:ctor. Press Esc to clear.

Properties (2)

Methods (7)

Explicit Interface Implementation Methods (1)