Skip to main content

Crate laminapdf_render

Crate laminapdf_render 

Source
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 the hayro feature: ADR 0004’s CI oracle and debug choice. The PDFium adapter is the edge crate laminapdf-render-pdfium.
  • Errors follow the ADR 0026 contract (RenderError).

Structs§

Annotated
The same tile drawn with its annotations, and the rectangles kept whole.
CancelToken
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.
ExportOptions
What export_pages writes.
HayroBackend
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).
PagePalette
An appearance’s paper (what white becomes) and ink (what black becomes).
PixelRect
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.
RenderFlags
What to draw besides the page content.
RenderLimits
Bounds on one render, checked before anything is allocated (render-too-large).
RenderOpenOptions
How a backend opens a document.
RenderPage
A page as a backend reports it.
RenderRequest
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.
TiffWriter
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 neither Send nor Sync: the file and its encoder share one buffer through an Rc, so a writer stays on the thread that made it (the web reader’s worker has only one).
TilePlan
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§

ExportFormat
The file format pages are exported to.
PageAppearance
How the page’s colours are drawn. The default keeps them.
RenderError
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.
SourceError
Why a ByteSource could 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 × 4 bytes. What ImageData and createImageBitmap take.
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§

ByteSource
Random-access input bytes: in memory, memory-mapped, a browser Blob, an HTTP range cache.
RenderBackend
A rendering engine: opens documents. Object-safe, so shells hold Box<dyn RenderBackend>.
RenderDocument
One open document. Send but not Sync: 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) of doc one at a time and encodes each as ExportOptions says: 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 form Error::DataPending reports 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: plain and annotated are the whole page drawn small, without and with annotations, width pixels wide, and rects the rectangles in its pixels. Deciding per tile instead would split an annotation that two tiles share.
read_all
Reads all of source into memory, at most max_bytes (an in-memory source is copied: backends that can borrow its slice, like hayro, check ByteSource::as_slice first).
recolour_tile
Recolours a tile drawn without annotations, in place: straight RGBA8 rows of width × 4.