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 region;
25mod shading;
26mod shear;
27mod softmask;
28mod stretch;
29mod stroke;
30mod text;
31mod transfer;
32mod type3;
33mod walk;
34mod window;
35mod zero_area;
36
37// # The backend seam
38//
39// Four modules stay public because a crate implementing [`RasterBackend`]
40// needs more than the trait's own signatures name: it rasterizes coverage,
41// composites it, blits an LCD glyph, and rounds alpha. Doing any of those in
42// the oracle's arithmetic means calling the engine's. `pdfrum-raster-agg` is
43// the in-tree proof — a backend written against exactly these four and
44// nothing else. Each module's own header says what a backend takes from it.
45//
46// A `///` on any of these lines would move the whole module's rustdoc into
47// this scope and break every intra-module link in it, so the prose lives
48// where the items do.
49pub mod blend;
50pub mod glyph;
51pub mod pixmap;
52pub mod scanline;
53
54// The walk's own phase timers and allocation counters. Public *with the
55// default-off `profiling` feature and only then*: the module always
56// exists, because the walk calls its entry points unconditionally and they
57// compile to empty inline functions with the feature off, but its forty-five
58// reporting items are part of the instrument rather than of the crate a
59// `cargo add pdfrum-render` reaches, which is why the committed API
60// snapshots deliberately do not cover the `profiling` feature.
61// Its own docs make the
62// argument for the thread-local, and it holds.
63#[cfg(feature = "profiling")]
64pub mod walkprofile;
65#[cfg(not(feature = "profiling"))]
66mod walkprofile;
67
68pub use color::{Argb, ObjectKind};
69pub use ctx::RenderCaches;
70pub use device::{
71 AntiAlias, Brush, FillRule, ImageQuality, MAX_TARGET_DIMENSION, RasterBackend, RasterImage,
72 RenderDevice,
73};
74pub use error::Error;
75pub use options::{ColorMode, ColorScheme, RenderOptions, TextAa};
76pub use pixmap::{AlphaMask, Pixmap};
77pub use region::{DeviceRect, Region};
78pub use walk::{
79 RenderSession, needs_alpha_background, render_page, render_page_to_device,
80 render_page_to_device_with, render_page_with,
81};
82
83/// A decoded image as a pixmap, composed the way a page draw would compose
84/// it: its mask applied, its matte removed, a stencil painted black.
85///
86/// For an image that is not on a page — a `/Thumb`, an embedded file — where
87/// there is no graphics state to take a fill colour or a transfer function
88/// from.
89#[must_use]
90pub fn image_to_pixmap(image: &pdfrum_page::ImageData) -> Pixmap {
91 image::to_pixmap(image, Argb::BLACK, None)
92}