mirror of
https://github.com/penpot/penpot.git
synced 2025-01-04 13:50:12 -05:00
wip
This commit is contained in:
parent
f2619461bc
commit
a2c5160a11
2 changed files with 52 additions and 55 deletions
|
@ -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(())
|
||||
}
|
||||
|
||||
|
@ -146,26 +142,48 @@ fn render_stroke(
|
|||
.draw_oval(&stroke_rect, &stroke.to_paint(&selrect));
|
||||
}
|
||||
Kind::Path(path) => {
|
||||
//TODO
|
||||
surface.canvas().save();
|
||||
let mut stroke_rect = stroke.clone().outer_rect(&selrect);
|
||||
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()),
|
||||
&fill_paint,
|
||||
);
|
||||
let mut path_paint = skia::Paint::default();
|
||||
path_paint.set_blend_mode(skia::BlendMode::SrcOut);
|
||||
path_paint.set_style(skia::PaintStyle::Stroke);
|
||||
path_paint.set_stroke_width(2. * stroke.clone().width());
|
||||
path_paint.set_anti_alias(true);
|
||||
surface.canvas().draw_path(
|
||||
&path.to_skia_path().transform(path_transform.unwrap()),
|
||||
&path_paint,
|
||||
);
|
||||
surface.canvas().restore();
|
||||
match stroke {
|
||||
Stroke::InnerStroke(attrs) => {
|
||||
surface.canvas().clip_path(
|
||||
&path.to_skia_path().transform(path_transform.unwrap()),
|
||||
skia::ClipOp::Intersect,
|
||||
true,
|
||||
);
|
||||
|
||||
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,
|
||||
);
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ impl Stroke {
|
|||
rect.width() - attrs.width,
|
||||
rect.height() - attrs.width,
|
||||
),
|
||||
Stroke::CenterStroke(attrs) => {
|
||||
Stroke::CenterStroke(_) => {
|
||||
math::Rect::from_xywh(rect.left, rect.top, rect.width(), rect.height())
|
||||
}
|
||||
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 {
|
||||
match self {
|
||||
Stroke::InnerStroke(attrs) => &mut attrs.fill,
|
||||
|
@ -151,15 +130,15 @@ impl Stroke {
|
|||
}
|
||||
|
||||
Stroke::CenterStroke(attrs) => {
|
||||
let mut paint = attrs.fill.to_paint(rect);
|
||||
paint.set_style(skia::PaintStyle::Stroke);
|
||||
paint.set_stroke_width(attrs.width);
|
||||
paint.set_blend_mode(skia::BlendMode::SrcOver);
|
||||
paint.set_stroke_join(skia::paint::Join::Miter); // Unión en pico
|
||||
paint.set_stroke_miter(10.0); // Longitud de la muesca para picos más pronunciados
|
||||
paint.set_stroke_cap(skia::paint::Cap::Butt); // Termina la línea sin agregar espacio adicional
|
||||
paint
|
||||
}
|
||||
let mut paint = attrs.fill.to_paint(rect);
|
||||
paint.set_style(skia::PaintStyle::Stroke);
|
||||
paint.set_stroke_width(attrs.width);
|
||||
paint.set_blend_mode(skia::BlendMode::SrcOver);
|
||||
paint.set_stroke_join(skia::paint::Join::Miter); // Unión en pico
|
||||
paint.set_stroke_miter(10.0); // Longitud de la muesca para picos más pronunciados
|
||||
paint.set_stroke_cap(skia::paint::Cap::Butt); // Termina la línea sin agregar espacio adicional
|
||||
paint
|
||||
}
|
||||
Stroke::OuterStroke(attrs) => {
|
||||
let mut paint = attrs.fill.to_paint(rect);
|
||||
paint.set_style(skia::PaintStyle::Stroke);
|
||||
|
|
Loading…
Reference in a new issue