Skip to content

Commit

Permalink
Handle drawing on to zero sized targets better
Browse files Browse the repository at this point in the history
Fixes #125
  • Loading branch information
jrmuizel committed Apr 7, 2020
1 parent 0c810a0 commit ca35017
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/draw_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,12 @@ impl DrawTarget {
}

fn apply_path(&mut self, path: &Path) {

// we have no height so there can be no edges
if self.height == 0 {
return;
}

for op in &path.ops {
match *op {
PathOp::MoveTo(pt) => {
Expand Down
14 changes: 14 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,4 +756,18 @@ mod tests {
dt.set_transform(&dt.get_transform().pre_translate(euclid::vec2(0., 1.)));
dt.fill_rect(0., -1., 100., 50., &img_src, &options);
}

#[test]
fn zero_sized_draw_target() {
let mut dt = DrawTarget::new(0, 0);
let mut pb = PathBuilder::new();
pb.line_to(0.5, 0.5);
pb.line_to(2.0, -2.0);
pb.line_to(2.0, 0.5);
dt.fill(
&pb.finish(),
&WHITE_SOURCE,
&DrawOptions::new(),
);
}
}

0 comments on commit ca35017

Please sign in to comment.