Expand description
§pdfrum-anyrender
anyrender scenes written as vector PDF
pages through pdfrum-edit. Paths stay paths, gradients stay gradients, text
stays text in embedded, subsetted fonts, and images keep their source
encoding where PDF allows (a JPEG as-is, an opaque PNG’s compressed data
as-is).
A page is painted into anyrender’s recording Scene first, by whatever
renders through anyrender. write() then embeds every face and image the
scenes use and replays each scene onto a pdfrum canvas: anyrender’s push/pop
layers become nested saved graphics states, the only shape a pdfrum canvas
lets a content stream take.
use anyrender::Scene;
use pdfrum_anyrender::{GlyphArea, Page, Sources, write};
use peniko::kurbo::{Affine, Rect, Size};
let page = Page {
size: Size::new(200.0, 100.0),
scene: Scene::default(),
placement: Affine::IDENTITY,
clip: Rect::new(0.0, 0.0, 200.0, 100.0),
area: GlyphArea::Anywhere,
};
let written = write(&[page], &Sources::default())?;
assert!(written.bytes.starts_with(b"%PDF-"));anyrender’s glyph runs carry glyph ids, not the text they were shaped from.
Hand the text over in Sources::texts, keyed by the run as the scene holds
it (RunKey), to make words selectable; a run without an entry falls back
to the font’s own cmap, reversed (GlyphTally counts both).
§What is simplified
Box shadows are dropped; filters and backdrop filters are ignored; compositing operators other than source-over paint as source-over; a sweep gradient, and a gradient on a stroke or on text, paints as its stops’ average colour; gradients pad at their ends whatever extend mode they name, and interpolate in sRGB; an image brush draws once, clipped to its shape.
§Test font
tests/fixtures/noto-serif-latin.ttf is a Latin subset of Noto Serif,
licensed under the SIL Open Font License 1.1
(tests/fixtures/OFL-noto-serif.txt). It is a test fixture and is not part
of the published crate’s code.
Structs§
- Encoded
Image - An image’s bytes as they arrived, before anything decoded them.
- Glyph
Source - One glyph’s share of the source text: the cluster it belongs to (glyphs of one cluster share it) and that cluster’s text.
- Glyph
Tally - What the pages did with the glyphs they were given.
- Image
Sources - Encoded sources keyed by the id of the decoded blob a brush paints
(
peniko::Blob::id): a renderer decodes once and paints that blob wherever the image appears, so the id names the image across every draw. - Page
- One page: its sheet, what is painted on it, and where.
- RunKey
- A glyph run as the painter sees it: the font face, the size and every glyph’s id and position, bit for bit. Two runs with the same key draw the same thing.
- RunText
- The text of one run and, for each glyph in drawing order, the byte range of its cluster in
that text. Glyphs of one cluster share a range; pdfrum writes it once, as
/ActualTextwhen the glyphs cannot carry it in the font’s ToUnicode map. - RunTexts
- Run texts by key. When two runs share a key but not a text (only possible when two code points share a glyph and everything else about the runs matches), the first recorded wins: record in document order.
- Sources
- Everything a scene may look up while it paints; built once per document, shared by pages.
- Written
- A written PDF and what became of its glyphs.
Enums§
- Glyph
Area - Where a page’s glyphs may land, in its scene’s coordinates.
- Image
Codec - How an image’s source is encoded.
Functions§
- write
pagesas one PDF, their text and images looked up insources.