Skip to content

Commit

Permalink
Fix y coordinate
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed Nov 2, 2024
1 parent 26f3cee commit 4f5ff7e
Show file tree
Hide file tree
Showing 3 changed files with 468 additions and 42 deletions.
6 changes: 3 additions & 3 deletions examples/html.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use printpdf::*;

const HTML_STRINGS: &[&str;2] = &[
"<p>Hello!</p>",
"<p style='color:red;font-family:sans-serif'>Hello!</p>",
const HTML_STRINGS: &[&str;1] = &[
"<div style='background:red;padding:10px;'><div style='background:yellow;padding:20px;'></div></div>",
// "<p style='color:red;font-family:sans-serif'>Hello!</p>",
];

fn main() -> Result<(), String>{
Expand Down
36 changes: 36 additions & 0 deletions src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,42 @@ impl Rect {
height,
}
}

pub fn to_polygon(&self) -> Polygon {
Polygon {
rings: vec![self.gen_points()],
mode: PaintMode::Fill,
winding_order: WindingOrder::NonZero
}
}

pub fn to_line(&self) -> Line {
Line {
points: self.gen_points(),
is_closed: true,
}
}

fn gen_points(&self) -> Vec<(Point, bool)> {

let top = self.y;
let bottom = Pt(self.y.0 - self.height.0);
let left = self.x;
let right = Pt(self.x.0 + self.width.0);

let tl = Point { x: left, y: top };
let tr = Point { x: right, y: top };
let br = Point { x: right, y: bottom };
let bl = Point { x: left, y: bottom };

vec![
(tl, false),
(tr, false),
(br, false),
(bl, false),
]
}

pub fn to_array(&self) -> Vec<lopdf::Object> {
vec![
(self.x.0.round() as i64).into(),
Expand Down
Loading

0 comments on commit 4f5ff7e

Please sign in to comment.