Skip to main content

Crate pdfboss_render

Crate pdfboss_render 

Source
Expand description

Page rasterization for pdfboss: paths, fills, strokes, clipping, color spaces, images and glyph outlines, rendered to an RGBA8 pixmap and encodable as PNG.

Glyph painting is staged behind GlyphPainting tiers: embedded TrueType only, then every embedded font program (TrueType, CFF, Type1, Type3), and finally Full, which additionally substitutes a replacement face for a non-embedded simple font (see crate::glyph and crate::substitute for the loader and the request/provider plumbing). A substitute face comes from either a caller-supplied directory (SubstituteSource::Dir) or the compiled-in OFL Croscore set (SubstituteSource::Builtin), the latter gated behind this crate’s substitute-fonts Cargo feature and queryable at runtime via builtin_fonts_available. Advance widths for a substituted standard-14 font additionally consult Adobe Core-14 AFM tables (pdfboss_encoding::standard_14_width) ahead of the substitute’s own hmtx, behind only the PDF’s own /Widths.

v1 limitations: /Symbol and /ZapfDingbats have no license-clean substitute, so they stay unpainted at every tier rather than borrowing an unrelated face’s glyphs (their text still advances, via the metrics-only loader in crate::glyph); and a “bold” sans substitute request is not visually distinct from regular weight (Arimo is a [wght] variable font, rendered at its Regular instance – only italic varies, via a separate static face).

Structs§

Pixmap
An RGBA8 raster image with straight (non-premultiplied) alpha, row-major from the top-left.
RenderCache
Cross-page render state: fonts by their dictionary’s object reference, and parsed ICCBased colorspace outcomes by their profile stream’s. Send + Sync, so a parallel page walk may share one.
RenderOptions
Options controlling a single page render.
RenderReport
What a page render could not reproduce faithfully: content dropped outright (an undecodable image, an unreadable form) and content painted as an approximation (a pattern fill as flat gray). Empty means every construct the render encountered was painted as the page describes it.
SkippedContent
One kind of content dropped for one reason, with how often it happened.

Enums§

GlyphPainting
How aggressively the rasterizer turns text into filled outlines. Each tier is a strict superset of the previous one; the difference is only observable once the corresponding glyph loaders exist.
ImageFormat
The file format Pixmap::encode writes. PNG keeps every channel and carries its compression level; PPM and BMP are a header plus one packing pass over the pixels, dropping alpha; JPEG is lossy at its quality.
PngCompression
How much CPU the PNG encoder spends shrinking the file. Every level round-trips the exact same pixels; only encode time and file size move. Balanced is what Pixmap::encode_png has always used.
SkipReason
Why a piece of page content was dropped or approximated during rasterization.
SkippedKind
Which piece of page content a render could not reproduce.
SubstituteSource
Where non-embedded glyph substitution (the Full GlyphPainting tier) draws replacement faces from. The default, None, substitutes nothing – Full behaves exactly like AllEmbedded until a caller opts in.

Functions§

builtin_fonts_available
Whether this binary was built with the substitute-fonts feature, i.e. whether SubstituteSource::Builtin has compiled-in faces to hand out. Callers (e.g. the CLI) use this to give an actionable message when Full is requested with no --font-dir and no compiled-in set, rather than silently rendering as if Full had never been asked for.
extract_page_images
Decodes every image the page draws, at the image’s own pixel dimensions, in drawing order. An image drawn twice appears twice; an XObject the content never draws does not appear at all. Stencil masks (/ImageMask true) paint a fill color rather than carrying one of their own, so they are not extracted. Optional-content visibility is not consulted: an image inside a hidden /OC group is still embedded in the file, so it still extracts. Extraction is lenient the way rendering is: content that cannot be read or decoded contributes nothing rather than failing the call.
extract_page_images_with
Extracts like extract_page_images against any object source; the synchronous form is this implementation over pdfboss_core::Immediate.
render_page
Renders a page at scale onto a white background. The pixel size is ceil(crop_w * scale) x ceil(crop_h * scale) (after /Rotate), and the base transform maps the crop box to device space with a y-flip and the page rotation applied.
render_page_reporting
Renders a page like render_page_with_options, additionally returning a RenderReport describing any content that had to be dropped or approximated. Use this when a silently blank page would be misleading.
render_page_reporting_with
Renders a page like render_page_reporting against any object source, awaiting whatever I/O the source needs — this is the asynchronous entry point, and the synchronous ones above are this implementation over pdfboss_core::Immediate (with RenderOptions::oc filled from the document when the caller left it unset), so under the same options the two APIs cannot render differently.
render_page_with_options
Renders a page like render_page, honoring opts (currently the glyph painting tier). See render_page for the geometry contract and for what leniency means for the pixels you get back.