mirror of
https://github.com/penpot/penpot.git
synced 2025-01-06 14:50:20 -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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,26 +142,48 @@ 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();
|
&path.to_skia_path().transform(path_transform.unwrap()),
|
||||||
fill_paint.set_blend_mode(skia::BlendMode::SrcOver);
|
skia::ClipOp::Intersect,
|
||||||
fill_paint.set_anti_alias(true);
|
true,
|
||||||
surface.canvas().draw_path(
|
);
|
||||||
&path.to_skia_path().transform(path_transform.unwrap()),
|
|
||||||
&fill_paint,
|
let mut paint_stroke = stroke.to_paint(&selrect);
|
||||||
);
|
paint_stroke.set_stroke_width(attrs.width * 2.);
|
||||||
let mut path_paint = skia::Paint::default();
|
surface.canvas().draw_path(
|
||||||
path_paint.set_blend_mode(skia::BlendMode::SrcOut);
|
&path.to_skia_path().transform(path_transform.unwrap()),
|
||||||
path_paint.set_style(skia::PaintStyle::Stroke);
|
&paint_stroke,
|
||||||
path_paint.set_stroke_width(2. * stroke.clone().width());
|
);
|
||||||
path_paint.set_anti_alias(true);
|
}
|
||||||
surface.canvas().draw_path(
|
Stroke::CenterStroke(_) => {
|
||||||
&path.to_skia_path().transform(path_transform.unwrap()),
|
surface.canvas().draw_path(
|
||||||
&path_paint,
|
&path.to_skia_path().transform(path_transform.unwrap()),
|
||||||
);
|
&stroke.to_paint(&selrect),
|
||||||
surface.canvas().restore();
|
);
|
||||||
|
}
|
||||||
|
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.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,
|
||||||
|
@ -151,15 +130,15 @@ impl Stroke {
|
||||||
}
|
}
|
||||||
|
|
||||||
Stroke::CenterStroke(attrs) => {
|
Stroke::CenterStroke(attrs) => {
|
||||||
let mut paint = attrs.fill.to_paint(rect);
|
let mut paint = attrs.fill.to_paint(rect);
|
||||||
paint.set_style(skia::PaintStyle::Stroke);
|
paint.set_style(skia::PaintStyle::Stroke);
|
||||||
paint.set_stroke_width(attrs.width);
|
paint.set_stroke_width(attrs.width);
|
||||||
paint.set_blend_mode(skia::BlendMode::SrcOver);
|
paint.set_blend_mode(skia::BlendMode::SrcOver);
|
||||||
paint.set_stroke_join(skia::paint::Join::Miter); // Unión en pico
|
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_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.set_stroke_cap(skia::paint::Cap::Butt); // Termina la línea sin agregar espacio adicional
|
||||||
paint
|
paint
|
||||||
}
|
}
|
||||||
Stroke::OuterStroke(attrs) => {
|
Stroke::OuterStroke(attrs) => {
|
||||||
let mut paint = attrs.fill.to_paint(rect);
|
let mut paint = attrs.fill.to_paint(rect);
|
||||||
paint.set_style(skia::PaintStyle::Stroke);
|
paint.set_style(skia::PaintStyle::Stroke);
|
||||||
|
|
Loading…
Reference in a new issue