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).
- Char
Code - 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
CIDFontturns into a glyph (ISO 32000-1 §9.7.4). CID 0 is.notdefand 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-fontuses 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–/Orderingpair of a/CIDSystemInfo(ISO 32000-1 §9.7.3), reduced to the five collections that have built-in tables plus “none of them”. - Coding
Scheme - 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
unicodethrough this CMap, orCharCode(0)when none would. - charset_
from_ ordering - The character collection a
/CIDSystemInfo’s/Orderingnames (ISO 32000-1 §9.7.3). - from_
encoding_ name - Resolve a font’s
/Encodingname 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
/UseCMapkey names (ISO 32000-1 §9.7.5.3), superseding whatever ausecmapoperator inside the program named. - parse_
embedded - Read an embedded CMap program — the decoded bytes of an
/Encodingstream. - 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
Nonewhen it assigns none.