Skip to main content

Crate pdfrum_render

Crate pdfrum_render 

Source
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§

pub use pixmap::AlphaMask;
pub use pixmap::Pixmap;

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, and AlphaMask, 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.
walkprofileprofiling
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.
ColorScheme
The four replacement colours a forced-colour render substitutes.
DeviceRect
A rectangle of whole device pixels, measured from the top-left corner of the page’s full device box (the box the render transform maps the page to, whose size is the whole-page render’s pixmap size).
RenderCaches
Caches owned by one render session, passed down by the owner.
RenderOptions
Everything a render is parameterised by.
RenderSession
What one render call may reuse or restrict, beyond the page and the options.

Enums§

AntiAlias
Whether a primitive’s edges are antialiased.
Brush
What a fill or stroke paints with.
ColorMode
The four colour modes. Three are reachable without any caller asking: Alpha from an alpha-type soft mask and from an uncoloured tiling pattern, Gray from a grayscale render, Forced from a colour scheme.
Error
A render that could not produce a pixmap.
FillRule
Which winding rule decides a path’s interior.
ImageQuality
How an image’s samples are reconstructed when it is scaled.
ObjectKind
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.
Region
How much of the page a render draws.
TextAa
How glyphs are antialiased.

Constants§

MAX_TARGET_DIMENSION
The largest render target either backend accepts in one axis.

Traits§

RasterBackend
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.
RenderDevice
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_device with a RenderSession.
render_page_with
Render a page, reusing caller-owned caches and honouring optional content.

Type Aliases§

RasterImage
A premultiplied RGBA8 image ready to be drawn, with its own dimensions.