Skip to content

Commit

Permalink
Fix paths with negative coordinates in iced_tiny_skia
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Jan 17, 2024
1 parent 4cb53a6 commit acee3b0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
18 changes: 10 additions & 8 deletions tiny_skia/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ impl Backend {
path,
paint,
rule,
transform,
}) => {
let bounds = path.bounds();

Expand All @@ -566,17 +565,18 @@ impl Backend {
path,
paint,
*rule,
transform
.post_translate(translation.x, translation.y)
.post_scale(scale_factor, scale_factor),
tiny_skia::Transform::from_translate(
translation.x,
translation.y,
)
.post_scale(scale_factor, scale_factor),
clip_mask,
);
}
Primitive::Custom(primitive::Custom::Stroke {
path,
paint,
stroke,
transform,
}) => {
let bounds = path.bounds();

Expand All @@ -599,9 +599,11 @@ impl Backend {
path,
paint,
stroke,
transform
.post_translate(translation.x, translation.y)
.post_scale(scale_factor, scale_factor),
tiny_skia::Transform::from_translate(
translation.x,
translation.y,
)
.post_scale(scale_factor, scale_factor),
clip_mask,
);
}
Expand Down
17 changes: 11 additions & 6 deletions tiny_skia/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,19 @@ impl Frame {
}

pub fn fill(&mut self, path: &Path, fill: impl Into<Fill>) {
let Some(path) = convert_path(path) else {
let Some(path) =
convert_path(path).and_then(|path| path.transform(self.transform))
else {
return;
};

let fill = fill.into();

self.primitives
.push(Primitive::Custom(primitive::Custom::Fill {
path,
paint: into_paint(fill.style),
rule: into_fill_rule(fill.rule),
transform: self.transform,
}));
}

Expand All @@ -60,9 +62,12 @@ impl Frame {
size: Size,
fill: impl Into<Fill>,
) {
let Some(path) = convert_path(&Path::rectangle(top_left, size)) else {
let Some(path) = convert_path(&Path::rectangle(top_left, size))
.and_then(|path| path.transform(self.transform))
else {
return;
};

let fill = fill.into();

self.primitives
Expand All @@ -73,12 +78,13 @@ impl Frame {
..into_paint(fill.style)
},
rule: into_fill_rule(fill.rule),
transform: self.transform,
}));
}

pub fn stroke<'a>(&mut self, path: &Path, stroke: impl Into<Stroke<'a>>) {
let Some(path) = convert_path(path) else {
let Some(path) =
convert_path(path).and_then(|path| path.transform(self.transform))
else {
return;
};

Expand All @@ -90,7 +96,6 @@ impl Frame {
path,
paint: into_paint(stroke.style),
stroke: skia_stroke,
transform: self.transform,
}));
}

Expand Down
4 changes: 0 additions & 4 deletions tiny_skia/src/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ pub enum Custom {
paint: tiny_skia::Paint<'static>,
/// The fill rule to follow.
rule: tiny_skia::FillRule,
/// The transform to apply to the path.
transform: tiny_skia::Transform,
},
/// A path stroked with some paint.
Stroke {
Expand All @@ -24,8 +22,6 @@ pub enum Custom {
paint: tiny_skia::Paint<'static>,
/// The stroke settings.
stroke: tiny_skia::Stroke,
/// The transform to apply to the path.
transform: tiny_skia::Transform,
},
}

Expand Down

0 comments on commit acee3b0

Please sign in to comment.