Skip to main content

parse_embedded

Function parse_embedded 

Source
pub fn parse_embedded(
    bytes: &[u8],
    limits: &Limits,
    diags: &mut Diagnostics,
) -> CMap
Expand description

Read an embedded CMap program — the decoded bytes of an /Encoding stream.

Never fails; damage is recorded on diags. limits caps how many codespace and wide-code ranges one program may declare, which the oracle leaves unbounded.

A usecmap operator inside the program names a parent, which is resolved against the built-in CMaps and consulted for every code this program does not map itself (ISO 32000-1 §9.7.5.3). For the other inheritance channel — the stream dictionary’s /UseCMap key, which may name a stream rather than a built-in — use inherit_from, which takes precedence.

use pdfrum_cmap::{CharCode, Cid, CodingScheme, parse_embedded};
use pdfrum_common::{Diagnostics, Limits};

let program = b"
    begincodespacerange <0000> <ffff> endcodespacerange
    1 begincidrange <0020> <007e> <0001> endcidrange
";
let mut diags = Diagnostics::default();
let cmap = parse_embedded(program, &Limits::default(), &mut diags);

assert_eq!(cmap.coding_scheme(), CodingScheme::TwoBytes);
assert_eq!(cmap.cid(CharCode(0x20)), Cid(1));
assert_eq!(cmap.cid(CharCode(0x7e)), Cid(0x5F));
assert_eq!(cmap.cid(CharCode(0x7f)), Cid(0));   // outside the range