Expand description
Raster image XObject emission for the PDF backend.
The layout engine hands us a [mos_layout::PageGraph::images]
table: one entry per unique on-disk image, dedup’d by resolved
path. For each entry we emit a single Image XObject
(/Type /XObject /Subtype /Image) with /Width, /Height,
/BitsPerComponent, /ColorSpace /DeviceRGB, and the raw RGB8
pixel buffer flate-compressed under /Filter /FlateDecode. Each
page’s /Resources /XObject dict lists every image, so per-page
resource dicts stay byte-stable across pages.
Per-page placements arrive as [ImagePlacement]s; the content
stream wraps each in q w 0 0 h x y cm /Im<id> Do Q so the image
occupies the requested width/height rectangle at the requested
page-relative position (after the same top→bottom flip the text
emit path applies).
Alpha/soft-mask support is deferred. The eval layer composites
every input image onto opaque white before handing the bytes off,
so the emit path can stay on a single /DeviceRGB /Filter
/FlateDecode codepath.
Functions§
- emit_
image_ 🔒xobject - Emit one Image
XObject(/Subtype /Image) forhandleatid.compressedis the zlib-compressed pixel stream produced byflate_compress; passed in pre-compressed so the caller can hold onto the bytes for byte-stability assertions in tests. - emit_
placement 🔒 - Emit the
q w 0 0 h x y cm /Im<id> Do Qblock for one placement, translated into PDF’s bottom-origin coordinate space usingpage_height_pt. - flate_
compress 🔒 - Compress a flat RGB8 byte buffer with zlib (the format PDF expects
behind
/FlateDecode). Uses default compression for a reasonable size/speed tradeoff; imageXObjectbyte stability across runs is preserved becauseflate2’s default settings are deterministic. - resource_
name 🔒 - Stable PDF resource name for the image with
handle.id. Mirrors the/F<n>convention used by the font emitter; every page’s resource dict declares/Im<n>so PDF readers can resolve the references in the content stream.