Expand description
The render backend contract (ADR 0004): every Lamina PDF surface renders pages through
RenderBackend and RenderDocument, which draw bounded tiles of a page at a scale into
a caller-supplied straight-alpha RGBA8 buffer.
- Requests are validated once, by
TilePlan::new, so every backend agrees on sizes and refuses oversized tiles (render-too-large) before allocating. - The pure-Rust adapter,
HayroBackend, is behind thehayrofeature: ADR 0004’s CI oracle and debug choice. The PDFium adapter is the edge cratelaminapdf-render-pdfium. - Errors follow the ADR 0026 contract (
RenderError).
Structs§
- Annotated
- The same tile drawn with its annotations, and the rectangles kept whole.
- Cancel
Token - A cancel flag shared by the jobs and calls it is passed to (ADR 0028 §5). Cloning shares the flag: cancel one clone and every holder sees it.
- Export
Options - What
export_pageswrites. - Hayro
Backend - The pure-Rust renderer: hayro 0.8 with its standard 14 fonts and predefined CMaps built in.
- Kept
- What a recoloured tile keeps as drawn.
- Matrix
- An affine transformation
[a b c d e f](§8.3.3): a point(x, y)maps to(a·x + c·y + e, b·x + d·y + f). - Page
Palette - An appearance’s paper (what white becomes) and ink (what black becomes).
- Pixel
Rect - A rectangle in the output pixel space of the whole page at the request’s scale and rotation, top-left origin, y down.
- Quad
- A quadrilateral in tile pixels: where an image’s unit square or an annotation’s rectangle lands.
- Render
Flags - What to draw besides the page content.
- Render
Limits - Bounds on one render, checked before anything is allocated (
render-too-large). - Render
Open Options - How a backend opens a document.
- Render
Page - A page as a backend reports it.
- Render
Request - One render: a page, a scale, an optional tile, a view rotation, flags, a background and the page appearance.
- Rgba8
- A straight-alpha sRGB colour.
- Tiff
Writer - A TIFF file in memory, one page per
TiffWriter::add_page: straight 8-bit RGBA, Deflate-compressed, each page with its resolution in dots per inch. It is neitherSendnorSync: the file and its encoder share one buffer through anRc, so a writer stays on the thread that made it (the web reader’s worker has only one). - Tile
Plan - The geometry of one validated request: the whole page’s pixel size at the scale and view rotation, and the tile inside it. Both backends render from this, so they agree on sizes.
Enums§
- Export
Format - The file format pages are exported to.
- Page
Appearance - How the page’s colours are drawn. The default keeps them.
- Render
Error - Why a render backend refused a request or couldn’t render.
- Rotation
- A rotation by a multiple of 90°, clockwise when displayed: a page’s
/Rotate(§7.7.3.3), or a view rotation added to it. - Source
Error - Why a
ByteSourcecould not deliver a range.
Constants§
- BYTES_
PER_ PIXEL - The output pixel format of every backend: RGBA8, straight (not premultiplied) alpha,
sRGB, rows packed at
width × 4bytes. WhatImageDataandcreateImageBitmaptake. - DARK
- Dark’s paper and ink:
@laminapdf/tokens’PAGE_APPEARANCES.dark. - SEPIA
- Sepia’s paper and ink:
@laminapdf/tokens’PAGE_APPEARANCES.sepia(@laminapdf/render’s tests hold both to the tokens).
Traits§
- Byte
Source - Random-access input bytes: in memory, memory-mapped, a browser
Blob, an HTTP range cache. - Render
Backend - A rendering engine: opens documents. Object-safe, so shells hold
Box<dyn RenderBackend>. - Render
Document - One open document.
Sendbut notSync: one call at a time on a document. A backend whose engine isn’t thread-safe (PDFium) also serialises calls across its documents.
Functions§
- export_
pages - Draws
pages(0-based) ofdocone at a time and encodes each asExportOptionssays: one file per page, in order, except a multi-page TIFF, which is one file. Only one page’s pixels are held at a time. - merge_
ranges - Sorts
(offset, len)ranges and merges those that overlap or touch (the formError::DataPendingreports them in). - mostly_
changed - Which annotations change at least half of their rectangle (a highlight, a filled shape, a
stamp), decided once for the page:
plainandannotatedare the whole page drawn small, without and with annotations,widthpixels wide, andrectsthe rectangles in its pixels. Deciding per tile instead would split an annotation that two tiles share. - read_
all - Reads all of
sourceinto memory, at mostmax_bytes(an in-memory source is copied: backends that can borrow its slice, like hayro, checkByteSource::as_slicefirst). - recolour_
tile - Recolours a tile drawn without annotations, in place: straight RGBA8 rows of
width × 4.