0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-07 15:39:42 -05:00
This commit is contained in:
Alejandro Alonso 2025-01-02 08:45:32 +01:00
parent f2619461bc
commit a2c5160a11
2 changed files with 52 additions and 55 deletions

View file

@ -40,10 +40,6 @@ impl Renderable for Shape {
); );
} }
let mut paint = skia::Paint::default();
paint.set_blend_mode(self.blend_mode.into());
paint.set_alpha_f(self.opacity);
Ok(()) Ok(())
} }
@ -146,29 +142,51 @@ fn render_stroke(
.draw_oval(&stroke_rect, &stroke.to_paint(&selrect)); .draw_oval(&stroke_rect, &stroke.to_paint(&selrect));
} }
Kind::Path(path) => { Kind::Path(path) => {
//TODO match stroke {
surface.canvas().save(); Stroke::InnerStroke(attrs) => {
let mut stroke_rect = stroke.clone().outer_rect(&selrect); surface.canvas().clip_path(
let mut fill_paint = skia::Paint::default();
fill_paint.set_blend_mode(skia::BlendMode::SrcOver);
fill_paint.set_anti_alias(true);
surface.canvas().draw_path(
&path.to_skia_path().transform(path_transform.unwrap()), &path.to_skia_path().transform(path_transform.unwrap()),
&fill_paint, skia::ClipOp::Intersect,
true,
); );
let mut path_paint = skia::Paint::default();
path_paint.set_blend_mode(skia::BlendMode::SrcOut); let mut paint_stroke = stroke.to_paint(&selrect);
path_paint.set_style(skia::PaintStyle::Stroke); paint_stroke.set_stroke_width(attrs.width * 2.);
path_paint.set_stroke_width(2. * stroke.clone().width());
path_paint.set_anti_alias(true);
surface.canvas().draw_path( surface.canvas().draw_path(
&path.to_skia_path().transform(path_transform.unwrap()), &path.to_skia_path().transform(path_transform.unwrap()),
&path_paint, &paint_stroke,
);
}
Stroke::CenterStroke(_) => {
surface.canvas().draw_path(
&path.to_skia_path().transform(path_transform.unwrap()),
&stroke.to_paint(&selrect),
);
}
Stroke::OuterStroke(attrs) => {
surface.canvas().save();
let mut paint_stroke = stroke.to_paint(&selrect);
paint_stroke.set_stroke_width(attrs.width * 2.);
surface.canvas().draw_path(
&path.to_skia_path().transform(path_transform.unwrap()),
&paint_stroke,
);
let mut clear_paint = skia::Paint::default();
clear_paint.set_blend_mode(skia::BlendMode::Clear);
clear_paint.set_anti_alias(true);
surface.canvas().draw_path(
&path.to_skia_path().transform(path_transform.unwrap()),
&clear_paint,
); );
surface.canvas().restore(); surface.canvas().restore();
} }
} }
} }
}
}
} }
pub fn draw_image_fill_in_container( pub fn draw_image_fill_in_container(

View file

@ -87,7 +87,7 @@ impl Stroke {
rect.width() - attrs.width, rect.width() - attrs.width,
rect.height() - attrs.width, rect.height() - attrs.width,
), ),
Stroke::CenterStroke(attrs) => { Stroke::CenterStroke(_) => {
math::Rect::from_xywh(rect.left, rect.top, rect.width(), rect.height()) math::Rect::from_xywh(rect.left, rect.top, rect.width(), rect.height())
} }
Stroke::OuterStroke(attrs) => math::Rect::from_xywh( Stroke::OuterStroke(attrs) => math::Rect::from_xywh(
@ -99,27 +99,6 @@ impl Stroke {
} }
} }
pub fn outer_path(self, path: &skia::Path) -> skia::Path {
// match self {
// Stroke::InnerStroke(attrs) => math::Rect::from_xywh(
// rect.left + (attrs.width / 2.),
// rect.top + (attrs.width / 2.),
// rect.width() - attrs.width,
// rect.height() - attrs.width,
// ),
// Stroke::CenterStroke(attrs) => {
// math::Rect::from_xywh(rect.left, rect.top, rect.width(), rect.height())
// }
// Stroke::OuterStroke(attrs) => math::Rect::from_xywh(
// rect.left - (attrs.width / 2.),
// rect.top - (attrs.width / 2.),
// rect.width() + attrs.width,
// rect.height() + attrs.width,
// ),
// }
path.clone()
}
pub fn fill_mut(&mut self) -> &mut Fill { pub fn fill_mut(&mut self) -> &mut Fill {
match self { match self {
Stroke::InnerStroke(attrs) => &mut attrs.fill, Stroke::InnerStroke(attrs) => &mut attrs.fill,