Skip to main content

Crate pdfrum_cmap

Crate pdfrum_cmap 

Source
Expand description

§pdfrum-cmap

A CMap does two jobs at once for a composite font (ISO 32000-1 §9.7.5): it splits a show-operator’s string into character codes one, two, three or four bytes wide, and it maps each code to a CID. The split is the part a byte oriented reader gets wrong — code widths vary within one string, so a CMap has to be consulted to know where the next code even begins.

use pdfrum_cmap::from_encoding_name;
use pdfrum_common::Diagnostics;
use pdfrum_object::Name;

let cmap = from_encoding_name(&Name::from("Identity-H"), &mut Diagnostics::default());
assert!(!cmap.is_vertical());
let cids: Vec<_> = cmap.decode(&[0x00, 0x41, 0x00, 0x42]).collect();
assert_eq!(cids.len(), 2);

59 named tables over 32 decoder stems ship compiled in (predefined), plus parse_embedded for a CMap the file carries as a stream. from_encoding_name is the /Encoding entry point: an unknown name is a diagnostic and a one-byte identity CMap, never an error, because a font whose encoding cannot be resolved still has to draw something.

Inheritance runs through three live mechanisms and they are not interchangeable. The built-in tables chain among themselves, which is what makes GB-EUC-V a thin override of GB-EUC-H. usecmap inside an embedded program is resolved by parse_embedded. The /UseCMap key of an /Encoding stream’s dictionary is attached by inherit_from and supersedes the operator. The last two are §9.7.5.3’s two channels, and both are child-wins: a code the child maps is the child’s answer, and only a code it maps to nothing reaches the parent. The oracle implements neither.

Part of pdfrum. #![forbid(unsafe_code)].

MIT OR Apache-2.0

Structs§

CMap
A CMap: a byte decoder plus a charcode→CID map (ISO 32000-1 §9.7.5).
CharCode
A character code: one unit of a PDF string as split by a CMap’s decoder (ISO 32000-1 §9.7.5). Between 1 and 4 bytes wide depending on the coding scheme, so the value alone does not say how many bytes it came from; ask CMap::char_size.
Cid
A character identifier: an index into a character collection, which a CIDFont turns into a glyph (ISO 32000-1 §9.7.4). CID 0 is .notdef and is also what an unmapped character code yields.
Words
An iterator over the words of a CMap program.

Enums§

CidCoding
How a predefined CMap’s character codes relate to a legacy encoding. Purely descriptive at this layer — nothing in this crate branches on it — but pdfrum-font uses it to pick a code page when a CID font falls back to a system face, so it is part of the CMap’s observable identity.
CidSet
The character collection a CID belongs to — the /Registry/Ordering pair of a /CIDSystemInfo (ISO 32000-1 §9.7.3), reduced to the five collections that have built-in tables plus “none of them”.
CodingScheme
How a byte string splits into character codes (ISO 32000-1 §9.7.6.2).
Error
Something a CMap operation could not do.

Functions§

charcode_from_unicode
The character code that would draw unicode through this CMap, or CharCode(0) when none would.
charset_from_ordering
The character collection a /CIDSystemInfo’s /Ordering names (ISO 32000-1 §9.7.3).
from_encoding_name
Resolve a font’s /Encoding name to a CMap, failures included.
has_cid2unicode
Whether a character collection has a built-in CID→Unicode table. Only the four CJK collections do.
inherit_from
Attach the parent a CMap stream’s /UseCMap key names (ISO 32000-1 §9.7.5.3), superseding whatever a usecmap operator inside the program named.
parse_embedded
Read an embedded CMap program — the decoded bytes of an /Encoding stream.
predefined
Look up one of the built-in CMap names.
unicode_from_cid
The Unicode scalar a character collection assigns to a CID (ISO 32000-1 §9.10.2), or None when it assigns none.