laminapdf-render
The render backend contract of ADR 0004. Every Lamina PDF surface draws pages through two object-safe traits:
RenderBackendopens documents from the sameByteSourceLamina PDF reads.RenderDocumentreports page sizes and renders tiles: a rectangle of a page at a scale, with a view rotation, flags and a background. View rotations and a page's own/Rotateshare one type,Rotation, re-exported fromlaminapdf-syntax. The output goes into a caller-supplied buffer in straight-alpha RGBA8, rows packed atwidth × 4.
A renderer only produces pixels. Text, glyph quads, structure, annotation and form geometry, links and outlines come from Lamina PDF's model, never from a renderer.
use Arc;
use ;
let doc = new.open?;
// The top-left 512 × 512 tile of page 1 at 2× (144 DPI), on white.
let req = page.with_clip;
let plan = doc.plan?; // validated geometry and the byte count
let mut out = vec!;
doc.render?;
Requests and limits
TilePlan::newvalidates every request once, so all backends agree on sizes.- Page size: the whole page is
max(1, floor(points × scale))pixels per side, after the view rotation. - Tiles: the tile must lie inside the page.
- Page size: the whole page is
RenderLimitsare checked before anything is allocated (render-too-large):max_render_pixelsper tile, default 16,777,216 (4096 × 4096);max_render_side, default 16,384;max_input_bytes, default 1 GiB, for backends that read the whole file (hayro).
- Errors are
RenderError, in the ADR 0026 contract:- new codes under
renderErrorsinfixtures/codes.json:render-too-large,render-failedandrender-backend-unavailable; - reused codes:
page-index-out-of-range,password-required,wrong-password,data-pending,source,invalid-argumentandcancelled.
- new codes under
- Cancellation: a
CancelToken(the façade's, which now lives inlaminapdf-syntax) is checked before and after the engine call. A running render can't be interrupted (ADR 0004 §1). - Determinism: the same backend version, input and request give the same bytes.
Backends
| Feature / crate | Backend | Notes |
|---|---|---|
hayro (off by default) |
HayroBackend: hayro 0.8.0, pure Rust |
ADR 0004's CI oracle and debug choice. Reads the whole source into memory (data-pending lists every missing range in one error). Draws tiles with render_into under an offset transform. It has no print intent, and draws widgets with the other annotations. |
laminapdf-render-pdfium (edge crate) |
PdfiumBackend: native PDFium |
The default on every viewer surface. |
This crate is core: no unsafe, no I/O, and it builds for wasm32, iOS and Android.
Tests
- Fast lane:
cargo test -p laminapdf-render --features hayroruns:- request validation and the source reader;
- the error codes against
codes.json; - hayro's error cases and tile geometry (four tiles stitch back into the whole page, and a 90° view equals the upright render rotated).
- Goldens: the render goldens are
laminapdf-render-pdfium's.