pdf/src/read/render/mod.rs#
Source: lib/pdf/src/read/render/mod.rs
Drawing pages (ISO 32000-1, 8 to 11): Document::render gives the page as pixels (sRGB). The
content stream runs through a graphics state (q / Q, cm, the line style, colours in every
colour space with ICC profiles, the Default* spaces and the output intent (color.rs), the
rendering intent of ri and RI, ExtGState with alpha, blend mode and soft mask), paths are
filled with the non-zero or
even-odd rule and stroked with caps, joins, miter limit and dashes in user space (also under
a non-uniform matrix), clipping paths and text clipping are masks. Text through the glyph
outlines of the embedded fonts (Type 1, CFF, TrueType, OpenType, Type 3) or substitutes
(FontSource); every text render mode. Images with every bit depth and colour space, Decode,
stencil masks, colour-key masks, soft masks, the JPEG filter (through img_jpeg) and
CCITTFax; shadings of every type (sh and as patterns), tiling patterns coloured and
uncoloured; form XObjects, transparency groups and soft masks (luminosity and alpha, with
backdrop and transfer function); the annotations' appearances, and for a form field without
one (or under NeedAppearances) the appearance edit::form makes from its value; optional content (the
default configuration, membership dictionaries); JPXDecode images through img_jp2, JBIG2Decode
images through img_jbig2. Not here: knockout and non-isolated groups (drawn as isolated ones),
overprint, halftones, transfer functions outside soft masks.
let doc = read::Document::open(bytes)?;
let page: gfx::Surface = doc.render(0, &RenderOptions { dpi: 150.0, ..Default::default() })?;
Untrusted input: the work of a page is bounded (the operators, the pixels painted, forms,
patterns, Type 3 glyphs and soft masks inside each other, the pixels of images and layers),
a page that needs more gives Error::Limit.
struct RenderOptionshow to draw a pagedpi: f64-- pixels per inch: 72 draws a point as a pixelregion: Option<[u32; 4]>-- the part of the page image to draw, in pixels: x, y, width, height (None: all of it)background: Option<u32>-- the colour under the page, straight 0xAARRGGBB (None: transparent)annotations: bool-- draw the annotations' appearances (form fields, stamps, comments)fonts: Option<Rc<dyn FontSource>>-- fonts for the fonts a document does not embed (None: the system's, text::fontdb)max_pixels: u64-- the largest image to draw, in pixels
struct FontQuery<'a>a font a page uses but does not embedname: &'a str-- its PostScript name without a subset tag (Helvetica-Bold, ArialMT, ...)family: Option<&'a str>bold: boolitalic: boolserif: bool-- serifs, a fixed pitch, a symbol font (by the descriptor's flags)fixed: boolsymbolic: booltext: bool-- a simple font (one byte per code), not a composite onelang: Option<&'a str>-- a composite font of one of Adobe's CJK collections: the language of its text (zh-Hans, zh-Hant, ja, ko), so a substitute has its characters (in its forms)
trait FontSourcewhere substitutes for fonts that are not embedded come from: a TrueType, OpenType or Type 1 file and the face in itfn find(&self, q: &FontQuery) -> Option<(Vec<u8>, u32)>
struct SystemFontsthe system's fonts (text::fontdb), searched once: for the 14 standard fonts their metric-compatible families (URW's Nimbus, Liberation, the Windows fonts), others by name and flags; a font with a language (FontQuery::lang) by its own name, else the system's serif or sans-serif font for the language (text::fontconf: fontconfig's rules on Linux, Noto Sans CJK JP for ja, say; the built-in ones elsewhere)
impl SystemFonts
fn new() -> SystemFonts
impl Document
fn page_pixels(&self, page: usize, dpi: f64) -> Result<(u32, u32), Error>the size of a page drawn at dpi: width and height in pixels (the crop box after /Rotate)fn render(&self, page: usize, opt: &RenderOptions) -> Result<gfx::Surface, Error>draw a page into a new surface (premultiplied ARGB, gfx::FMT_PARGB)