Expand description
§pdfrum-page
The content layer (ISO 32000-1 §8). A page’s /Contents is a stream of
painting operators in user space — points, origin bottom-left, y-up — and
this crate turns those bytes into a page-object graph that both the renderer
and the text extractor walk. Colour spaces, PDF functions, shadings 1 through
7, transparency groups, soft masks, patterns and Type 3 glyph procedures all
resolve here.
bytes ──parse_content──▶ Vec<Op> ──build_page──▶ Pageuse pdfrum_common::{Diagnostics, Limits};
use pdfrum_page::{Op, parse_content};
let ops = parse_content(b"0 0 100 50 re f", &Limits::default(), &mut Diagnostics::default());
assert_eq!(ops, vec![Op::Rectangle(0.0, 0.0, 100.0, 50.0), Op::Fill()]);The two stages are separate pure functions, and that is the crate’s main
design decision. parse_content tokenizes and emits one Op per
recognised operator, knowing nothing about resources or state.
build_page is the fold that turns those operators into page objects, and
it is where /Resources, the graphics-state stack and form-XObject recursion
live. Splitting them means a content stream can be inspected, diffed and
fuzzed with no document behind it, and a page can be built from synthesized
operators with no bytes.
parse_content is infallible. An unrecognised operator, a wrong operand
count, or a truncated stream is a diagnostic and a skipped Op — a content
stream is the part of a PDF most likely to be damaged, and refusing to parse
it would mean refusing to draw pages that every viewer draws.
§Features
| feature | adds |
|---|---|
jpeg2000 | JPEG 2000 images (hayro-jpeg2000) |
jbig2 | JBIG2 images (hayro-jbig2) |
ccitt | CCITT Group 3/4 fax images |
Flate and JPEG are always present. A stream in a codec this build left out
decodes to a recorded failure, and the rest of the page still draws — the
facade turns all three on together as codecs-all.
Part of pdfrum. #![forbid(unsafe_code)].
MIT OR Apache-2.0
Modules§
- renderprofile
profiling - Where a whole page render goes, from the page dictionary to the pixels.
Structs§
- Axial
- A type 2 shading’s geometry.
- BitImage
- A one-bit-per-pixel image, packed MSB-first with each row starting on a byte boundary.
- Build
Context - The caches and guards a build shares across the whole page.
- Clip
Stack - The clipping state: an ordered list of contributions to intersect.
- Color
Value - A colour in some space.
- Content
- A page object with the state and marks it was created under.
- Content
Marks - The mark stack a page object is stamped with.
- Converted
- Components to premultiplied RGBA, one row at a time.
- Form
Object - A form
XObject’s contents, already interpreted. - Function
Based - A type 1 shading’s geometry.
- Function
Cache - Session-scoped function memoization, keyed on the reference that named the function.
- General
State - The
/ExtGStateparameters that reach compositing, plus the ones that do not. - Graphics
State - Everything
qsaves andQrestores. - Image
Cache - A session-scoped cache of decoded images.
- Image
Data - A fully decoded image.
- Image
Object - An image, decoded.
- Index
OutOf Range - An object index that is not on the page.
- Inline
Image - An inline image (
BI … ID … EI), already separated into its dictionary and its raw sample bytes by the tokenizer (ISO 32000-1 §8.9.7). - JpxImage
jpeg2000 - A decoded JPEG 2000 image.
- Mark
- One marked-content entry.
- Mesh
- A decoded mesh.
- Mesh
Params - The bit widths and decode ranges a mesh stream declares.
- Mesh
Reader - A cursor over a mesh stream.
- NotA
Quarter Turn - The error
Rotation’sFromStrreturns: the string named no quarter turn. - OcContext
- The visibility context: the catalog’s optional-content configuration plus the memoized answers.
- Packed
- Decoded-but-not-unpacked samples, with everything needed to walk them.
- Page
- An interpreted page.
- Page
Edit - One page’s object graph, opened for editing.
- Palette
- A palette with every entry already in the representation a row wants.
- Patch
- A Coons or tensor patch: twelve or sixteen control points and four corner colours.
- Path
Object - A path, as painted.
- Pattern
Space - A
Patterncolorspace: a marker with, for uncoloured patterns, the space itsscnoperands live in. - Pattern
Value - A pattern colour: which pattern, and the components an uncoloured one paints with.
- Post
Script - A type 4 function.
- Radial
- A type 3 shading’s geometry.
- Resources
- The resource dictionaries a lookup consults.
- Rgb
- A colour in the device’s RGB space, each channel nominally in
0..=1. - Rgb8
- Eight-bit red, green, blue.
- Rgba8
- Premultiplied RGBA, the representation the device buffer wants.
- Row
- A run of pixels in one representation.
- Separation
- A
Separationcolorspace: one tint driving an alternate space. - Shading
- A loaded, validated shading.
- Shading
Object - A shading painted directly by
sh. - Shading
Pattern - A
/PatternType 2pattern: a shading plus the matrix placing it. - Soft
Mask - A soft mask from an
/ExtGState’s/SMask. - Source
- The source stage: an image’s
Sampleswalked one row at a time. - State
Stack - The
q/Qstack. - Stream
Bounds - Where each
/Contentselement’s operators begin, within one flat operator list. - Stroke
Params - How a path is stroked.
- Text
Clip Limit - A text-clip batch that would take the clip past
MAX_TEXT_OBJECTS. - Text
Clip Run - One text run held for clipping, with the state its placement needs.
- Text
Object - One run of glyphs sharing a position and a font.
- Text
Segment - One string within a text object, and the adjustment that followed it.
- Text
State - The text-showing parameters (ISO 32000-1 table 105).
- Tile
Range - The range of tile indices covering a clip rectangle.
- Tiling
Pattern - A
/PatternType 1pattern. - Transfer
Func - Three 256-entry byte tables, one per channel.
- Transparency
- A transparency group’s attributes.
- Triangle
- A triangle from a type 4 or type 5 mesh.
- Type3
Metrics - What a Type 3 glyph procedure declares about one character, and what it paints.
- Unpacked
- The unpack stage:
Packedsamples widened to a byte per component, one row at a time into a buffer it owns and reuses. - Vertex
- One vertex: where it is and what colour it carries.
- Visibility
- Which of a page’s objects optional content hides, shaped like the page.
Enums§
- Blend
Mode - A separable blend mode (ISO 32000-1 table 136).
- Clip
Entry - One clipping contribution.
- Clip
Rule - Which rule decides a clipping path’s interior (ISO 32000-1 §8.5.4).
- Color
Space - A loaded colour space.
- Depth
- Bits per component, as the sample stream carries them.
- Error
- What went wrong in a page-level operation that can actually fail.
- Family
- The eleven colour space families, with the integer tags PDFium exposes through its public API.
- Fill
Rule - How a path-painting operator fills its interior (ISO 32000-1 §8.5.3.3).
- Form
Fonts Key - Which interactive form a set of cached form faces belongs to.
- Found
Pattern - What
scnfound when it named a pattern. - Function
- A loaded PDF function.
- Geometry
- A shading’s geometry.
- Image
Mask - An image’s alpha, however it was expressed.
- LineCap
- Line-cap style (
J,/LC; ISO 32000-1 table 52). - Line
Join - Line-join style (
j,/LJ; ISO 32000-1 table 53). - Mark
Properties - The property list a
BDCoperator carries: a name into/Properties, or an inline dictionary. - Op
- One content-stream operator with its operands already extracted.
- Page
Object - One thing to paint.
- Pattern
- A loaded pattern.
- Pixels
- Decoded pixels, in whichever shape the source produced.
- Requested
Size - The resolution an image was decoded at.
- Rotation
- A page’s
/Rotate, normalized to one of four quarter turns (ISO 32000-1 §7.7.3.3). - Samples
- An image’s samples, in whichever state the decode ladder left them.
- SetComponents
Error - Why
ColorValue::set_componentsrefused the values. - Shading
Kind - Which geometry a shading paints.
- Shading
Source - Which entry point reached a shading, which decides whether
/Backgroundis honoured. - Soft
Mask Kind - Which channel of the group a soft mask reads.
- Text
Item - One element of a
TJarray: a string to show, or an adjustment in thousandths of a text-space unit. - Text
Render Mode - How glyphs are painted (
Tr; ISO 32000-1 table 106). - Usage
Type - Which use an optional-content configuration is being read for.
Constants§
- CHANNEL_
SAMPLES - Entries per channel.
- DEFAULT_
MEDIA_ BOX - The default page size when
/MediaBoxis missing or empty: US Letter. - MAX_
BYTES - Byte budget, 100 MiB.
- MAX_
FORM_ LEVEL - The most form parses that may be in flight at once.
- MAX_
IMAGE_ PIXELS - Largest pixel grid (
width × height) this crate will materialize from file-declared dimensions. - MAX_
TEXT_ OBJECTS - The most text objects a clipping path may accumulate.
Traits§
- Rows
- Whatever yields an image’s samples one row at a time, at source width.
Functions§
- adobe_
cmyk_ to_ srgb - The Adobe CMYK -> sRGB table lookup, byte in and byte out.
- apply_
ext_ gstate - Apply an
/ExtGStatedictionary tostate. - build_
form_ object - Build one form
XObjectas a standalone page object, placed bymatrix. - build_
form_ object_ with - The same build, told whether the appearance is a live edit’s.
- build_
page - Build a page from its operators.
- build_
page_ from_ dict - Build a page from its operators and its dictionary.
- build_
page_ streams - Build a page whose
/Contentsboundaries are known, so every object records which element it came from. - cmyk_
profile_ bytes - A CMYK ICC profile, encoded as an output profile, for the same writer.
- coons_
interior - The four interior control points a Coons patch implies, from ISO 32000-2 §8.7.4.5.8.
- decode_
image - Decode an image
XObject. - decode_
jbig2 jbig2 - Decode an embedded JBIG2 image.
- decode_
jpx jpeg2000 - Decode a JPEG 2000 codestream or JP2 file.
- derive_
boxes - Derive a page’s boxes from its inherited attributes.
- display_
size_ from_ dict - A page’s displayed size, read from its dictionary rather than from a built
Page. - eliminate_
redundant_ clips - The clip-elimination post-pass a page runs after interpretation.
- image_
area_ is_ workable - Whether a file-declared width and height are small enough to convert, reduce, or unpack into a dense plane.
- load_
colorspace - Load the colorspace
objnames. - load_
pattern - A pattern named in a colour value, looked up through the resources.
- page_
visibility - Resolve which of a page’s objects optional content hides.
- parse_
content - Parse content-stream bytes into operators.
- parse_
program - Build a function from a bare program, for tests and for callers that hold a program rather than a stream.
- srgb_
profile_ bytes - An sRGB ICC profile, encoded, for a writer that must embed one.
- transform_
object - Move
objectbytransform, composed before whatever it already had — the body ofPageEdit::transform, for an object not yet on a page. - uncolored_
pattern_ rgb - The colour an uncoloured pattern paints with, and the fallbacks when none resolves.