JFLib

pdf/src/geom.rs#

Source: lib/pdf/src/geom.rs

geom -- matrices, colours, paths and the stroke parameters of a canvas
  • struct Matrix an affine matrix as PDF writes it (a b c d e f cm): x' = a x + c y + e, y' = b x + d y + f
    • a: f64
    • b: f64
    • c: f64
    • d: f64
    • e: f64
    • f: 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) -> Matrix

  • const fn translate(tx: f64, ty: f64) -> Matrix

  • const fn scale(sx: f64, sy: f64) -> Matrix

  • fn rotate(angle: f64) -> Matrix a rotation by angle radians: counter-clockwise where y points up, clockwise on a canvas whose y points down

  • fn then(&self, next: &Matrix) -> Matrix self first, then next (PDF's self × next)

  • fn apply(&self, x: f64, y: f64) -> (f64, f64)

  • fn det(&self) -> f64

  • fn invert(&self) -> Option<Matrix> the inverse; None when the matrix is singular or not finite

  • struct Rgb an RGB colour, each part 0 to 1 (DeviceRGB)

    • r: f64
    • g: f64
    • b: 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) -> Rgb

  • fn from_u8(r: u8, g: u8, b: u8) -> Rgb from 0..255 parts

  • fn hex(rgb: u32) -> Rgb from 0xRRGGBB

  • enum FillRule which parts of a path a fill covers (PDF f / f*)

    • NonZero
    • EvenOdd
  • enum LineCap the ends of open subpaths and dashes (PDF J)

    • Butt
    • Round
    • Square
  • enum LineJoin the corners of a stroke (PDF j)

    • Miter
    • Round
    • Bevel
  • enum TextMode how text is painted (PDF Tr)

    • Fill
    • Stroke
    • FillStroke
    • Invisible -- not painted, but found by search and copied (e.g. text over a scanned page)
  • struct Path a 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() -> Path
  • fn is_empty(&self) -> bool
  • fn 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 Path starts a subpath
  • fn line_to(&mut self, x: f64, y: f64) -> &mut Path a 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 Path a 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 Path a quadratic Bézier curve (written as the same cubic)
  • fn close(&mut self) -> &mut Path closes the subpath with a line to its start
  • fn rect(&mut self, x: f64, y: f64, w: f64, h: f64) -> &mut Path a closed rectangle as its own subpath (PDF re)
  • fn ellipse(&mut self, cx: f64, cy: f64, rx: f64, ry: f64) -> &mut Path a closed ellipse around (cx, cy) as four cubic curves
  • fn circle(&mut self, cx: f64, cy: f64, r: f64) -> &mut Path
  • fn rounded_rect(&mut self, x: f64, y: f64, w: f64, h: f64, r: f64) -> &mut Path a 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 Path an elliptical arc around (cx, cy) from angle start over sweep radians (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 one
  • fn append(&mut self, other: &Path) -> &mut Path appends another path's subpaths
  • fn transform(&mut self, m: &Matrix) every point mapped by m (a rectangle becomes four lines when m turns it)

Source: docs/API.md in the JFLib repository.