pdf/src/shading.rs#
Source: lib/pdf/src/shading.rs
shading -- gradients (axial and radial shadings, ISO 32000-1 8.7.4.5) and hatches for
Canvas::shade, fill_shading and fill_hatch
A gradient becomes a shading dictionary of type 2 (axial) or 3 (radial) in DeviceRGB. Its
colour function: one Type 2 function (exponential, N 1) from colour to colour, or for more stops
a Type 3 stitching function of such pieces, one per stretch between two stops; stops at the same
t (a hard edge) leave out the empty stretch between them, so Bounds always rise. Before the
first stop and after the last the colour stays the first / last stop's. The stops' alpha:
all the same -> the constant fill alpha (ExtGState ca); different -> a luminosity soft mask whose
group paints the same geometry as a DeviceGray shading of the alphas (Canvas builds it).
Hatches are stroked lines, not tiling patterns: pdfium draws the cells of a rotated tiling
pattern with hairline gaps and one-pixel steps where they meet, and both pdfium and Poppler round
the cell step to whole device pixels, so the lines drift from where they belong. A hatch clips
to the path and strokes parallel lines over its bounding box in one path (one `S`, so a hatch's
alpha applies once).
enum ShadingKindthe geometry of a gradient, in the user space of the canvas at the time it is paintedAxial { from: [f64; 2], to: [f64; 2] }-- colour runs fromfrom(t = 0) toto(t = 1), constant across (PDF type 2)Radial { from: [f64; 2], r0: f64, to: [f64; 2], r1: f64 }-- circles from (from, r0) at t = 0 to (to, r1) at t = 1 (PDF type 3); radii >= 0
struct Shadinga gradient for Canvas::shade and Canvas::fill_shadingkind: ShadingKindstops: Vec<(f64, Rgb, f64)>-- (t in 0..=1 ascending, colour, alpha 0..=1); at least one stop. Stops with a NaN t are dropped, t is clamped to 0..=1 and the stops sorted by it (stable: two stops at the same t make a hard edge); a NaN alpha is opaqueextend: (bool, bool)-- paint beyond t < 0 / t > 1 with the end colours (PDF /Extend), default (true, true)
impl Shading
fn axial(from: [f64; 2], to: [f64; 2], stops: &[(f64, Rgb, f64)]) -> Shadingan axial gradient fromfromtoto, extended at both endsfn radial(from: [f64; 2], r0: f64, to: [f64; 2], r1: f64, stops: &[(f64, Rgb, f64)]) -> Shadinga radial gradient from the circle (from, r0) to (to, r1), extended at both endsstruct Hatchparallel lines for Canvas::fill_hatch; two hatches over the same path crossangle: f64-- direction of the lines in the canvas's user space, radians from +x towards +y: counter- clockwise on the page where y points up (Origin::BottomLeft), clockwise where it points down (Origin::TopLeft, as Canvas::rotate)spacing: f64-- distance between neighbouring lines (user space units), > 0width: f64-- line width (user space units), > 0; at leastspacingfills the path solidcolor: Rgbalpha: f64-- 0 to 1, times the canvas's fill alphaorigin: [f64; 2]-- a point one of the lines runs through (user space)
impl Hatch
fn new(angle: f64, spacing: f64, width: f64, color: Rgb) -> Hatchopaque lines through (0, 0)