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.
Structs§
- Page
Emit 🔒Context - PdfMetadata
- Document-level metadata written to the PDF Info dictionary.
Constants§
- PRODUCER 🔒
- Identifies Mosaic as the PDF’s producing application, written to the
Info dictionary
/Producerand/Creatorso 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 workspaceCARGO_PKG_VERSIONautomatically.
Functions§
- build_
pdf 🔒 - Build the PDF bytes from
graph. Pulled out ofemitso tests can round-trip without touching the filesystem. Returns the bytes plus any encoding diagnostics (currentlyMOS0032for Base14/Differencesoverflow). Keptpub(crate); the public surface isemit. - emit
- Emit
graphas a PDF file atout. Createsout’s parent directory if it doesn’t already exist. - emit_
base14_ 🔒fonts - emit_
encoding_ 🔒dict - Emits one PDF indirect object: a custom
/Encodingdict with/BaseEncoding /WinAnsiEncodingand a/Differencesarray.pdf-writer’sDifferences::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_
images 🔒 - emit_
outline 🔒 - Emit the
/Outlinestree fromgraph.outline(flat, document order, each entry carrying a headinglevel1..=3). Nesting is reconstructed in a single pass over a level stack of entry indices, then the root dict and one/Outlineitem per entry are wired with parent/prev/next/first/last links and page destinations. - emit_
pages 🔒 - emit_
to_ 🔒unicode_ cmap - Emits a
/ToUnicodeCMapstream that round-trips every byte used byencback to its original Unicode codepoint, so copy-paste and full-text search work for bothWinAnsinatives and/Differences-remapped slots. - io_
diagnostic 🔒 - plan_
base14_ 🔒encodings