Skip to main content

Crate pdf2_render

Crate pdf2_render 

Source
Expand description

A rasteriser for the pdf2 crate: paths, clips, transforms, dashes and the beginnings of a content-stream interpreter.

The walker reuses pdf2’s tokenizer and document model — there is no second PDF parser here. What it can draw today:

  • path construction (m, l, c, v, y, h, re) in user space, with the CTM applied at flattening time;
  • fills with the non-zero (f, F, B) and even-odd (f*, B*) rules;
  • strokes with butt, round and square caps, round joins, and dash patterns (d) with a phase;
  • clipping (W, W*) as a per-pixel mask that nested q/Q restores;
  • colour operators g/G, rg/RG and the naive k/K conversion.

Not yet drawn, and reported per page in Report::unsupported instead of failing: text and images. Rendering is deliberately without anti-aliasing for now: coverage is decided at pixel centres, which keeps the golden images exact and the scanline code small.

Structs§

Canvas
An RGBA8 raster.
ClipMask
A per-pixel inclusion mask produced by clipping.
Color
A colour with straight (non-premultiplied) components.
Dash
Line-dash pattern, in user-space lengths.
Glyph
One glyph’s outline in em units: y grows upwards, the baseline is y = 0 and one em is 1.0.
Image
A decoded image: width, height and one colour per pixel, top row first.
Matrix
A 2×3 affine transform, in the order PDF writes it: a b c d e f.
Path
A path in user space.
Point
A point in user or device space.
Rect
A rectangle in PDF user space: [x0 y0 x1 y1].
RenderOptions
What a page render should look like.
RenderedPage
A rendered page.
Report
What happened while rendering, beyond the pixels.
Subpath
A connected run of segments.

Enums§

Cap
How a stroked path ends.
Error
Every failure mode the crate reports.
Font
A resolved font ready to place glyphs.
Join
How stroked segments meet, from the j operator.
Segment
One segment of a subpath.

Functions§

clip_mask
Rasterise polygons into a clip mask of the given size: inside where the fill rule says painted, outside everywhere else.
encode_png
Encode the canvas as a PNG.
fill_polygons
Fill polygons with color, restricted to mask.
render_page
Rasterise one page.
render_page_number
A document, page number (zero based) and rasterisation scale in one call.

Type Aliases§

Result
Result type used throughout the crate.