pdf/src/geom.rs#
Source: lib/pdf/src/geom.rs
geom -- matrices, colours, paths and the stroke parameters of a canvas
struct Matrixan affine matrix as PDF writes it (a b c d e f cm): x' = a x + c y + e, y' = b x + d y + fa: f64b: f64c: f64d: f64e: f64f: f64
impl Matrix
const IDENTITY: Matrix = Matrix { a: 1.0, b: 0.0, c: 0.0, d: 1.0, e: 0.0, f: 0.0 }const fn new(a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) -> Matrixconst fn translate(tx: f64, ty: f64) -> Matrixconst fn scale(sx: f64, sy: f64) -> Matrixfn rotate(angle: f64) -> Matrixa rotation byangleradians: counter-clockwise where y points up, clockwise on a canvas whose y points downfn then(&self, next: &Matrix) -> Matrixself first, thennext(PDF's self × next)fn apply(&self, x: f64, y: f64) -> (f64, f64)fn det(&self) -> f64fn invert(&self) -> Option<Matrix>the inverse; None when the matrix is singular or not finitestruct Rgban RGB colour, each part 0 to 1 (DeviceRGB)r: f64g: f64b: f64
impl Rgb
const BLACK: Rgb = Rgb { r: 0.0, g: 0.0, b: 0.0 }const WHITE: Rgb = Rgb { r: 1.0, g: 1.0, b: 1.0 }const fn new(r: f64, g: f64, b: f64) -> Rgbfn from_u8(r: u8, g: u8, b: u8) -> Rgbfrom 0..255 partsfn hex(rgb: u32) -> Rgbfrom 0xRRGGBBenum FillRulewhich parts of a path a fill covers (PDFf/f*)NonZeroEvenOdd
enum LineCapthe ends of open subpaths and dashes (PDFJ)ButtRoundSquare
enum LineJointhe corners of a stroke (PDFj)MiterRoundBevel
enum TextModehow text is painted (PDFTr)FillStrokeFillStrokeInvisible-- not painted, but found by search and copied (e.g. text over a scanned page)
struct Patha path: subpaths of lines and cubic curves, built once and drawn on any canvas (Canvas::append_path) or built on the canvas itself (its move_to, line_to, ...)
impl Path
fn new() -> Pathfn is_empty(&self) -> boolfn clear(&mut self)fn current(&self) -> Option<(f64, f64)>the current point (None before the first move_to and after clear)fn move_to(&mut self, x: f64, y: f64) -> &mut Pathstarts a subpathfn line_to(&mut self, x: f64, y: f64) -> &mut Patha straight line from the current point (without one: a move_to)fn curve_to(&mut self, x1: f64, y1: f64, x2: f64, y2: f64, x: f64, y: f64) -> &mut Patha cubic Bézier curve with control points (x1, y1) and (x2, y2) to (x, y)fn quad_to(&mut self, x1: f64, y1: f64, x: f64, y: f64) -> &mut Patha quadratic Bézier curve (written as the same cubic)fn close(&mut self) -> &mut Pathcloses the subpath with a line to its startfn rect(&mut self, x: f64, y: f64, w: f64, h: f64) -> &mut Patha closed rectangle as its own subpath (PDFre)fn ellipse(&mut self, cx: f64, cy: f64, rx: f64, ry: f64) -> &mut Patha closed ellipse around (cx, cy) as four cubic curvesfn circle(&mut self, cx: f64, cy: f64, r: f64) -> &mut Pathfn rounded_rect(&mut self, x: f64, y: f64, w: f64, h: f64, r: f64) -> &mut Patha closed rectangle with corners rounded by r (at most half the shorter side)fn arc(&mut self, cx: f64, cy: f64, rx: f64, ry: f64, start: f64, sweep: f64) -> &mut Pathan elliptical arc around (cx, cy) from anglestartoversweepradians (positive: from +x towards +y), as cubic curves of at most 90 degrees; it continues the subpath with a line to its start, or starts onefn append(&mut self, other: &Path) -> &mut Pathappends another path's subpathsfn transform(&mut self, m: &Matrix)every point mapped by m (a rectangle becomes four lines when m turns it)