Skip to main content

Module render

Module render 

Source
Expand description

The pure-Rust page renderer — phase 3 of retiring pdfium (docs/PDF_CONFORMANCE.md, “Retiring pdfium”): the raster of a page’s vector content, text and images that the layout / TableFormer / OCR stages consume — the default renderer since phase 5 (docling-parse’s renderer plugin draws them only under DOCLING_RS_RENDERER=docling-parse).

It draws what docling-parse’s renderer<BLEND2D> draws, in its frame: the page’s crop box on a ceil(width · scale) × ceil(height · scale) white canvas (resolve_canvas_size), y down, the box mapped onto the whole canvas, /Rotate applied to the finished pixels; content-stream semantics as in content; fonts as in font; the anti-aliased rasterizer, strokes, masks, gradients and image blits are tiny-skia’s. It is not byte-identical to that renderer — Blend2D’s font engine, rasterizer and JIT compositor round differently — and the docling-parse shim stays the reference the PDF baselines are pinned to; this renderer is measured against it (tests::against_the_docling_parse_shim).

Modules§

color
Colour spaces (ISO 32000-1, 8.6) → device RGB in [0, 1].
content
The content-stream interpreter (ISO 32000-1, 8–9): graphics state, path construction and painting, clipping, text, XObjects, inline images, shadings and patterns, ExtGState, and the widget annotations’ appearance streams — drawn onto a tiny-skia canvas in device space.
font
PDF fonts for the renderer: a font dictionary becomes a LoadedFont that splits strings into codes, gives each code its advance and its glyph outline in text space, or — for Type 3 — its glyph procedure.
function
PDF functions (ISO 32000-1, 7.10): sampled (type 0), exponential (2), stitching (3) and PostScript calculator (4) — what shadings, Separation / DeviceN tint transforms and /Decode-less colour ramps evaluate.
geom
Affine geometry for the renderer: PDF’s [a b c d e f] matrices in f64, applied as x' = a·x + c·y + e, y' = b·x + d·y + f (ISO 32000-1, 8.3.4).
image
Image XObjects and inline images → premultiplied RGBA pixmaps (ISO 32000-1, 8.9): every bit depth, the colour spaces of super::color, /Decode ranges, stencil masks painted in the fill colour, /SMask soft masks, stencil and colour-key /Masks. The sample data comes through the raster’s filter chain, its libjpeg-exact JPEG decoder and its CCITT decoder, JPEG 2000 through super::jpx (#598) and JBIG2 through super::jbig2 (#811). An image no decoder can read comes out as a mid-gray block (the picture the layout model should see is “a picture”) — a stencil mask too, which used to draw nothing at all.
jbig2
JBIG2Decode images (ISO 32000-1, 7.4.7): the embedded JBIG2 streams of scanned PDFs, decoded with hayro-jbig2 (#811).
jpx
JPXDecode images (ISO 32000-1, 7.4.9): JPEG 2000 codestreams and JP2 files, decoded with hayro-jpeg2000 (#598).
objects
Small lopdf helpers shared by the renderer’s modules.
prepass
A pre-pass over a content stream for the two constructs lopdf’s content lexer (0.44) does not hand over intact:

Structs§

Omission
An image the render could not draw as its pixels (#916): a placeholder block stands in for it (a codec that failed or is missing), or it was left out. rect is the image’s device bounding box in the output bitmap’s pixels (before /Rotate is applied to the page).
Renderer
A document’s renderer: the per-document caches (fonts, CMYK table, decoded image samples) that its page renders share. The pipeline renders every page at two scales; hold one Renderer per document across both.

Functions§

pixels_for_extent
docling-parse’s pixels_for_extent: ceil(extent − 1e-6).
render_page
One-off Renderer::render_scaled (no cache carried across pages).
render_page_sized
One-off Renderer::render.