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
XObjectemission for the PDF backend.
Structs§
- PdfMetadata
- Document-level metadata that gets written to the PDF Info
dictionary. Populated by the lowerer from
#set document(...). Thelanguagefield is captured but not yet emitted (it belongs in the catalog/Langentry, which is the next slice).
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_
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_
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 🔒