Fix paths with negative coordinates in iced_tiny_skia

This commit is contained in:
Héctor Ramón Jiménez 2024-01-17 15:31:29 +01:00
parent 4cb53a6e22
commit acee3b030b
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
3 changed files with 21 additions and 18 deletions

View file

@ -543,7 +543,6 @@ impl Backend {
path, path,
paint, paint,
rule, rule,
transform,
}) => { }) => {
let bounds = path.bounds(); let bounds = path.bounds();
@ -566,9 +565,11 @@ impl Backend {
path, path,
paint, paint,
*rule, *rule,
transform tiny_skia::Transform::from_translate(
.post_translate(translation.x, translation.y) translation.x,
.post_scale(scale_factor, scale_factor), translation.y,
)
.post_scale(scale_factor, scale_factor),
clip_mask, clip_mask,
); );
} }
@ -576,7 +577,6 @@ impl Backend {
path, path,
paint, paint,
stroke, stroke,
transform,
}) => { }) => {
let bounds = path.bounds(); let bounds = path.bounds();
@ -599,9 +599,11 @@ impl Backend {
path, path,
paint, paint,
stroke, stroke,
transform tiny_skia::Transform::from_translate(
.post_translate(translation.x, translation.y) translation.x,
.post_scale(scale_factor, scale_factor), translation.y,
)
.post_scale(scale_factor, scale_factor),
clip_mask, clip_mask,
); );
} }

View file

@ -40,9 +40,12 @@ impl Frame {
} }
pub fn fill(&mut self, path: &Path, fill: impl Into<Fill>) { 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; return;
}; };
let fill = fill.into(); let fill = fill.into();
self.primitives self.primitives
@ -50,7 +53,6 @@ impl Frame {
path, path,
paint: into_paint(fill.style), paint: into_paint(fill.style),
rule: into_fill_rule(fill.rule), rule: into_fill_rule(fill.rule),
transform: self.transform,
})); }));
} }
@ -60,9 +62,12 @@ impl Frame {
size: Size, size: Size,
fill: impl Into<Fill>, 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; return;
}; };
let fill = fill.into(); let fill = fill.into();
self.primitives self.primitives
@ -73,12 +78,13 @@ impl Frame {
..into_paint(fill.style) ..into_paint(fill.style)
}, },
rule: into_fill_rule(fill.rule), rule: into_fill_rule(fill.rule),
transform: self.transform,
})); }));
} }
pub fn stroke<'a>(&mut self, path: &Path, stroke: impl Into<Stroke<'a>>) { 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; return;
}; };
@ -90,7 +96,6 @@ impl Frame {
path, path,
paint: into_paint(stroke.style), paint: into_paint(stroke.style),
stroke: skia_stroke, stroke: skia_stroke,
transform: self.transform,
})); }));
} }

View file

@ -13,8 +13,6 @@ pub enum Custom {
paint: tiny_skia::Paint<'static>, paint: tiny_skia::Paint<'static>,
/// The fill rule to follow. /// The fill rule to follow.
rule: tiny_skia::FillRule, rule: tiny_skia::FillRule,
/// The transform to apply to the path.
transform: tiny_skia::Transform,
}, },
/// A path stroked with some paint. /// A path stroked with some paint.
Stroke { Stroke {
@ -24,8 +22,6 @@ pub enum Custom {
paint: tiny_skia::Paint<'static>, paint: tiny_skia::Paint<'static>,
/// The stroke settings. /// The stroke settings.
stroke: tiny_skia::Stroke, stroke: tiny_skia::Stroke,
/// The transform to apply to the path.
transform: tiny_skia::Transform,
}, },
} }