mirror of
https://github.com/penpot/penpot.git
synced 2025-05-29 18:46:11 +02:00
Merge pull request #6437 from penpot/elenatorro-add-fill-text-strokes
🎉 Add text stroke fills
This commit is contained in:
commit
23bde76192
3 changed files with 54 additions and 15 deletions
|
@ -1,3 +1,4 @@
|
|||
use skia_safe::Image;
|
||||
use skia_safe::{self as skia, paint::Paint};
|
||||
|
||||
use crate::render::BlendMode;
|
||||
|
@ -812,7 +813,37 @@ impl Shape {
|
|||
!self.fills.is_empty()
|
||||
}
|
||||
|
||||
pub fn get_text_stroke_paint(&self, stroke: &Stroke) -> Vec<Paint> {
|
||||
fn set_paint_fill(&self, paint: &mut Paint, fill: &Fill, image: Option<Image>) {
|
||||
match fill {
|
||||
Fill::Solid(SolidColor(color)) => {
|
||||
paint.set_color(*color);
|
||||
}
|
||||
Fill::LinearGradient(gradient) => {
|
||||
paint.set_shader(gradient.to_linear_shader(&self.selrect()));
|
||||
}
|
||||
Fill::RadialGradient(gradient) => {
|
||||
paint.set_shader(gradient.to_radial_shader(&self.selrect()));
|
||||
}
|
||||
Fill::Image(image_fill) => {
|
||||
if let Some(image) = image {
|
||||
let position = (self.selrect().x(), self.selrect().y());
|
||||
let sampling_options = skia::SamplingOptions::new(
|
||||
skia::FilterMode::Linear,
|
||||
skia::MipmapMode::Nearest,
|
||||
);
|
||||
let tile_modes = (skia::TileMode::Clamp, skia::TileMode::Clamp);
|
||||
let mut matrix = skia::Matrix::default();
|
||||
matrix.set_translate(position);
|
||||
|
||||
let shader = image.to_shader(tile_modes, sampling_options, &matrix);
|
||||
paint.set_shader(shader);
|
||||
paint.set_alpha(image_fill.opacity());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_text_stroke_paint(&self, stroke: &Stroke, image: Option<&Image>) -> Vec<Paint> {
|
||||
let mut paints = Vec::new();
|
||||
|
||||
match stroke.kind {
|
||||
|
@ -827,9 +858,9 @@ impl Shape {
|
|||
paint.set_blend_mode(skia::BlendMode::SrcATop);
|
||||
paint.set_anti_alias(true);
|
||||
paint.set_stroke_width(stroke.width * 2.0);
|
||||
if let Fill::Solid(SolidColor(color)) = stroke.fill {
|
||||
paint.set_color(color);
|
||||
}
|
||||
|
||||
self.set_paint_fill(&mut paint, &stroke.fill, image.cloned());
|
||||
|
||||
paints.push(paint);
|
||||
}
|
||||
StrokeKind::CenterStroke => {
|
||||
|
@ -837,9 +868,9 @@ impl Shape {
|
|||
paint.set_style(skia::PaintStyle::Stroke);
|
||||
paint.set_anti_alias(true);
|
||||
paint.set_stroke_width(stroke.width);
|
||||
if let Fill::Solid(SolidColor(color)) = stroke.fill {
|
||||
paint.set_color(color);
|
||||
}
|
||||
|
||||
self.set_paint_fill(&mut paint, &stroke.fill, image.cloned());
|
||||
|
||||
paints.push(paint);
|
||||
}
|
||||
StrokeKind::OuterStroke => {
|
||||
|
@ -848,9 +879,9 @@ impl Shape {
|
|||
paint.set_blend_mode(skia::BlendMode::DstOver);
|
||||
paint.set_anti_alias(true);
|
||||
paint.set_stroke_width(stroke.width * 2.0);
|
||||
if let Fill::Solid(SolidColor(color)) = stroke.fill {
|
||||
paint.set_color(color);
|
||||
}
|
||||
|
||||
self.set_paint_fill(&mut paint, &stroke.fill, image.cloned());
|
||||
|
||||
paints.push(paint);
|
||||
|
||||
let mut paint = skia::Paint::default();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue