Skip to main content

Crate mos_pdf

Crate mos_pdf 

Source
Expand description

PDF backend for Mosaic (manifest §21.1).

Emits a fixed-A4 PDF declaring all 14 standard PDF base fonts (Helvetica/Times/Courier × 4 + Symbol + ZapfDingbats). No font data ships; every glyph outline is supplied by the PDF reader’s built-in Core 14 implementations.

For each Latin Core 14 face actually used, the backend plans a per-document /Encoding dict that layers a /Differences array on top of WinAnsiEncoding to reach the 99 extended glyphs each AFM carries beyond WinAnsi (Ł, ł, Ě, ě, Ő, ő, the Romanian comma-below set, math operators −≤≥≠√∂∑∆◊, fi/fl). A matching /ToUnicode CMap is emitted so the bytes we mint decode back to real Unicode in copy/paste and search.

See the private encoding module for the planner. PDF/A, tagged PDF, hyperlinks, bookmarks, and full font embedding (issue #9) are deferred.

Modules§

content 🔒
Per-page PDF content stream emission.
embedded 🔒
Type 0 CID-keyed font emission for bundled embedded faces.
encoding 🔒
Per-document /Differences-based encoding planning for the Core 14 Latin fonts.
images 🔒
Raster image XObject emission for the PDF backend.

Structs§

PdfMetadata
Document-level metadata that gets written to the PDF Info dictionary. Populated by the lowerer from #set document(...). The language field is captured but not yet emitted (it belongs in the catalog /Lang entry, which is the next slice).

Constants§

PRODUCER 🔒
Identifies Mosaic as the PDF’s producing application, written to the Info dictionary /Producer and /Creator so a built PDF traces back to the compiler that bred it (the way ffmpeg/Word/Adobe stamp theirs). A compile-time constant, so output stays byte-for-byte deterministic: no wall-clock, host, path, or user data leaks in. The version tracks the workspace CARGO_PKG_VERSION automatically.

Functions§

build_pdf 🔒
Build the PDF bytes from graph. Pulled out of emit so tests can round-trip without touching the filesystem. Returns the bytes plus any encoding diagnostics (currently MOS0032 for Base14 /Differences overflow). Kept pub(crate); the public surface is emit.
emit
Emit graph as a PDF file at out. Creates out’s parent directory if it doesn’t already exist.
emit_encoding_dict 🔒
Emits one PDF indirect object: a custom /Encoding dict with /BaseEncoding /WinAnsiEncoding and a /Differences array. pdf-writer’s Differences::consecutive(start, names) emits the run-length form [ start /n1 /n2 /n3 ]. We use one group per contiguous run for compactness; isolated slots get their own single-element group.
emit_to_unicode_cmap 🔒
Emits a /ToUnicode CMap stream that round-trips every byte used by enc back to its original Unicode codepoint, so copy-paste and full-text search work for both WinAnsi natives and /Differences-remapped slots.
io_diagnostic 🔒