🎉 Add text solid strokes (#6384)

* 🎉 Add text strokes

* 🔧 Minor refactor
This commit is contained in:
Elena Torró 2025-05-07 17:28:36 +02:00 committed by GitHub
parent 44bf276c49
commit 61eb2f4a19
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 166 additions and 23 deletions

View file

@ -1,4 +1,4 @@
use skia_safe::{self as skia};
use skia_safe::{self as skia, paint::Paint};
use crate::render::BlendMode;
use crate::uuid::Uuid;
@ -811,6 +811,60 @@ impl Shape {
pub fn has_fills(&self) -> bool {
!self.fills.is_empty()
}
pub fn get_text_stroke_paint(&self, stroke: &Stroke) -> Vec<Paint> {
let mut paints = Vec::new();
match stroke.kind {
StrokeKind::InnerStroke => {
let mut paint = skia::Paint::default();
paint.set_blend_mode(skia::BlendMode::DstOver);
paint.set_anti_alias(true);
paints.push(paint);
let mut paint = skia::Paint::default();
paint.set_style(skia::PaintStyle::Stroke);
paint.set_blend_mode(skia::BlendMode::SrcATop);
paint.set_anti_alias(true);
paint.set_stroke_width(stroke.width * 2.0);
paint.set_color(match &stroke.fill {
Fill::Solid(color) => *color,
_ => Color::BLACK,
});
paints.push(paint);
}
StrokeKind::CenterStroke => {
let mut paint = skia::Paint::default();
paint.set_style(skia::PaintStyle::Stroke);
paint.set_anti_alias(true);
paint.set_stroke_width(stroke.width);
paint.set_color(match &stroke.fill {
Fill::Solid(color) => *color,
_ => Color::BLACK,
});
paints.push(paint);
}
StrokeKind::OuterStroke => {
let mut paint = skia::Paint::default();
paint.set_style(skia::PaintStyle::Stroke);
paint.set_blend_mode(skia::BlendMode::DstOver);
paint.set_anti_alias(true);
paint.set_stroke_width(stroke.width * 2.0);
paint.set_color(match &stroke.fill {
Fill::Solid(color) => *color,
_ => Color::BLACK,
});
paints.push(paint);
let mut paint = skia::Paint::default();
paint.set_blend_mode(skia::BlendMode::Clear);
paint.set_anti_alias(true);
paints.push(paint);
}
}
paints
}
}
/*