pdfrum_render/lib.rs
1#![doc = include_str!("../README.md")]
2#![forbid(unsafe_code)]
3#![cfg_attr(docsrs, feature(doc_cfg))]
4// Every number reaching this crate came from an untrusted file by way of
5// `pdfrum-page`: index with `get()` and do arithmetic with `checked_*`.
6#![warn(clippy::indexing_slicing)]
7
8// The engine's own machinery. Private: the surface is the
9// `pub use` block below plus the four modules a *backend* implementing
10// `RasterBackend` has to reach into, which are declared separately under
11// "The backend seam".
12mod clip;
13mod color;
14mod ctx;
15mod device;
16mod error;
17mod group;
18mod image;
19mod imagecache;
20mod options;
21mod paint;
22mod path;
23mod pattern;
24mod shading;
25mod shear;
26mod softmask;
27mod stretch;
28mod stroke;
29mod text;
30mod transfer;
31mod type3;
32mod walk;
33mod zero_area;
34
35// # The backend seam
36//
37// Four modules stay public because a crate implementing [`RasterBackend`]
38// needs more than the trait's own signatures name: it rasterizes coverage,
39// composites it, blits an LCD glyph, and rounds alpha. Doing any of those in
40// the oracle's arithmetic means calling the engine's. `pdfrum-raster-agg` is
41// the in-tree proof — a backend written against exactly these four and
42// nothing else. Each module's own header says what a backend takes from it.
43//
44// A `///` on any of these lines would move the whole module's rustdoc into
45// this scope and break every intra-module link in it, so the prose lives
46// where the items do.
47pub mod blend;
48pub mod glyph;
49pub mod pixmap;
50pub mod scanline;
51
52// The walk's own phase timers and allocation counters. Public *with the
53// default-off `profiling` feature and only then*: the module always
54// exists, because the walk calls its entry points unconditionally and they
55// compile to empty inline functions with the feature off, but its forty-five
56// reporting items are part of the instrument rather than of the crate a
57// `cargo add pdfrum-render` reaches, which is why the committed API
58// snapshots deliberately do not cover the `profiling` feature.
59// Its own docs make the
60// argument for the thread-local, and it holds.
61#[cfg(feature = "profiling")]
62pub mod walkprofile;
63#[cfg(not(feature = "profiling"))]
64mod walkprofile;
65
66pub use color::{Argb, ObjectKind};
67pub use ctx::RenderCaches;
68pub use device::{
69 AntiAlias, Brush, FillRule, ImageQuality, MAX_TARGET_DIMENSION, RasterBackend, RasterImage,
70 RenderDevice,
71};
72pub use error::Error;
73pub use options::{ColorMode, ColorScheme, RenderOptions, TextAa};
74pub use pixmap::{AlphaMask, Pixmap};
75pub use walk::{
76 RenderSession, needs_alpha_background, render_page, render_page_to_device,
77 render_page_to_device_with, render_page_with,
78};
79
80/// A decoded image as a pixmap, composed the way a page draw would compose
81/// it: its mask applied, its matte removed, a stencil painted black.
82///
83/// For an image that is not on a page — a `/Thumb`, an embedded file — where
84/// there is no graphics state to take a fill colour or a transfer function
85/// from.
86#[must_use]
87pub fn image_to_pixmap(image: &pdfrum_page::ImageData) -> Pixmap {
88 image::to_pixmap(image, Argb::BLACK, None)
89}