Skip to content

Commit

Permalink
Account for viewbox transform in draw_bboxes example.
Browse files Browse the repository at this point in the history
  • Loading branch information
RazrFalcon committed Mar 1, 2024
1 parent 1d06fc5 commit 4d27b8c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions crates/resvg/examples/draw_bboxes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,26 @@ fn main() {
let render_ts = tiny_skia::Transform::from_scale(zoom, zoom);
resvg::render(&tree, render_ts, &mut pixmap.as_mut());

let stroke = tiny_skia::Stroke::default();
let mut stroke = tiny_skia::Stroke::default();
stroke.width = 1.0 / zoom; // prevent stroke scaling as well

let mut paint1 = tiny_skia::Paint::default();
paint1.set_color_rgba8(255, 0, 0, 127);

let mut paint2 = tiny_skia::Paint::default();
paint2.set_color_rgba8(0, 200, 0, 127);

let root_ts = tree.view_box().to_transform(tree.size());
let bbox_ts = render_ts.pre_concat(root_ts);

for bbox in bboxes {
let path = tiny_skia::PathBuilder::from_rect(bbox);
pixmap.stroke_path(&path, &paint1, &stroke, render_ts, None);
pixmap.stroke_path(&path, &paint1, &stroke, bbox_ts, None);
}

for bbox in stroke_bboxes {
let path = tiny_skia::PathBuilder::from_rect(bbox);
pixmap.stroke_path(&path, &paint2, &stroke, render_ts, None);
pixmap.stroke_path(&path, &paint2, &stroke, bbox_ts, None);
}

pixmap.save_png(&args[2]).unwrap();
Expand Down

0 comments on commit 4d27b8c

Please sign in to comment.