Expand description
§pdfrum-render
Walks a page-object graph onto a rasterizer (ISO 32000-1 §8.4–8.7): paths, clips, images, shadings, transparency groups, soft masks, patterns and glyph runs. It is the engine, not a rasterizer — it owns what to paint and the order to paint it in, and knows nothing about how a pixel gets set.
use pdfrum_common::Diagnostics;
use pdfrum_page::Page;
use pdfrum_raster_tinyskia::TinySkiaBackend;
use pdfrum_render::{RenderOptions, render_page};
let pixmap = render_page(
&Page::empty(),
&RenderOptions::default(),
&TinySkiaBackend,
&mut Diagnostics::default(),
)?;
assert_eq!((pixmap.width(), pixmap.height()), (612, 792));The seam is two traits. RenderDevice is six drawing primitives plus a
hard-edged rectangle clip, object-safe, and the engine holds one per target;
RasterBackend is the factory that makes a second target, which is what
soft masks, transparency groups, pattern cells and the fill-plus-stroke
knockout buffer all need. A backend implements both and is otherwise
invisible: because the engine never learns which rasterizer it has, two
independent CPU backends can be run over the same corpus and made to agree,
and that agreement is the test that the engine is not compensating for one of
them.
The background is a decision, not a default: an opaque page paints onto
white, a transparent one onto nothing, and
needs_alpha_background is the query. Getting it backwards is the
difference between a page composited over a viewer’s chrome and one with a
white card behind it.
Damage never fails a render. An object the engine cannot draw is skipped with
a diagnostic; Err is reserved for a target that is empty or too large under
opts. RenderSession carries the caches a repeated render reuses — give
each worker thread its own.
Part of pdfrum. #![forbid(unsafe_code)].
MIT OR Apache-2.0
Re-exports§
Modules§
- blend
- The sixteen PDF blend modes (ISO 32000-1 §11.3.5), computed the way the oracle does: all-integer, truncating, unclamped.
- glyph
- Glyphs as alpha bitmaps, rendered the way the oracle’s FreeType renders them.
- pixmap
- The two raster buffers the engine and the backends share:
Pixmap, a premultiplied RGBA8 image, andAlphaMask, an 8-bit coverage plane. - scanline
- The analytic cell rasterizer: exact per-pixel area and cover, in the style the oracle’s scan converter uses.
- walkprofile
profiling - Where the engine half of a render goes, split finer than the backend seam.
Structs§
- Argb
- A resolved draw colour: straight (non-premultiplied) RGB plus an alpha.
- Color
Scheme - The four replacement colours a forced-colour render substitutes.
- Render
Caches - Caches owned by one render session, passed down by the owner.
- Render
Options - Everything a render is parameterised by.
- Render
Session - What one render call may reuse or restrict, beyond the page and the options.
Enums§
- Anti
Alias - Whether a primitive’s edges are antialiased.
- Brush
- What a fill or stroke paints with.
- Color
Mode - The four colour modes. Three are reachable without any caller asking:
Alphafrom an alpha-type soft mask and from an uncoloured tiling pattern,Grayfrom a grayscale render,Forcedfrom a colour scheme. - Error
- A render that could not produce a pixmap.
- Fill
Rule - Which winding rule decides a path’s interior.
- Image
Quality - How an image’s samples are reconstructed when it is scaled.
- Object
Kind - Which kind of object a colour is being resolved for. A forced-colour scheme replaces path and text colours only; images, shadings and forms keep their own and are then not gray-translated either.
- TextAa
- How glyphs are antialiased.
Constants§
- MAX_
TARGET_ DIMENSION - The largest render target either backend accepts in one axis.
Traits§
- Raster
Backend - The factory that lets the engine rasterize offscreen: soft masks, transparency groups, pattern cells and the fill+stroke knockout buffer all need a second target.
- Render
Device - The device a page is drawn into: six primitives plus a hard-edged rect clip, all object-safe.
Functions§
- image_
to_ pixmap - A decoded image as a pixmap, composed the way a page draw would compose it: its mask applied, its matte removed, a stencil painted black.
- needs_
alpha_ background - Whether the page renders onto a transparent background rather than white.
- render_
page - Render a page into a pixmap.
- render_
page_ to_ device - Record a page onto a backend device without rasterizing the root target.
- render_
page_ to_ device_ with render_page_to_devicewith aRenderSession.- render_
page_ with - Render a page, reusing caller-owned caches and honouring optional content.
Type Aliases§
- Raster
Image - A premultiplied RGBA8 image ready to be drawn, with its own dimensions.