Skip to main content

lightweight_pdf_layout/
geometry.rs

1#[derive(Clone, Copy, Debug)]
2pub struct Constraints {
3    pub max_width: f32,
4    pub max_height: f32,
5}
6
7#[derive(Clone, Copy, Debug, Default)]
8pub struct Size {
9    pub width: f32,
10    pub height: f32,
11}
12
13/// Coordinates are page-relative, top-down (x grows right, y grows down
14/// from the top of the body/header/footer band) — a purely internal layout
15/// convention. The facade converts to PDF's bottom-left origin only at the
16/// very end, when translating a `RenderNode` tree into content-stream ops.
17#[derive(Clone, Copy, Debug)]
18pub struct Rect {
19    pub x: f32,
20    pub y: f32,
21    pub width: f32,
22    pub height: f32,
23}
24
25impl Rect {
26    pub fn shrink(&self, amount: f32) -> Rect {
27        Rect {
28            x: self.x + amount,
29            y: self.y + amount,
30            width: (self.width - 2.0 * amount).max(0.0),
31            height: (self.height - 2.0 * amount).max(0.0),
32        }
33    }
34}