🐛 Use SrcIn only when there is only one inner stroke, otherwise use erode filter

This commit is contained in:
Elena Torro
2025-08-22 09:54:15 +02:00
parent 96a91dc710
commit 0b7444e8ff
3 changed files with 28 additions and 5 deletions

View File

@@ -520,6 +520,7 @@ impl RenderState {
shadows::render_text_drop_shadows(self, &shape, &mut paragraphs, antialias);
}
let count_inner_strokes = shape.count_visible_inner_strokes();
text::render(self, &shape, &mut paragraphs, None, None);
for stroke in shape.visible_strokes().rev() {
@@ -528,6 +529,7 @@ impl RenderState {
&shape.selrect(),
shape.image_filter(1.).as_ref(),
shape.mask_filter(1.).as_ref(),
count_inner_strokes,
);
shadows::render_text_drop_shadows(
self,

View File

@@ -1109,6 +1109,13 @@ impl Shape {
pub fn has_visible_inner_strokes(&self) -> bool {
self.visible_strokes().any(|s| s.kind == StrokeKind::Inner)
}
pub fn count_visible_inner_strokes(&self) -> usize {
self.visible_strokes()
.filter(|s| s.kind == StrokeKind::Inner)
.count()
}
/*
Returns the list of children taking into account the structure modifiers
*/

View File

@@ -124,6 +124,7 @@ impl TextContent {
bounds: &Rect,
blur: Option<&ImageFilter>,
blur_mask: Option<&MaskFilter>,
count_inner_strokes: usize,
) -> Vec<Vec<ParagraphBuilder>> {
let fallback_fonts = get_fallback_fonts();
let fonts = get_font_collection();
@@ -138,8 +139,14 @@ impl TextContent {
if let Some(blur_mask) = blur_mask {
text_paint.set_mask_filter(blur_mask.clone());
}
let stroke_paints =
get_text_stroke_paints(stroke, bounds, &text_paint, blur, blur_mask);
let stroke_paints = get_text_stroke_paints(
stroke,
bounds,
&text_paint,
blur,
blur_mask,
count_inner_strokes,
);
let text: String = leaf.apply_text_transform();
for (paint_idx, stroke_paint) in stroke_paints.iter().enumerate() {
@@ -198,8 +205,15 @@ impl TextContent {
bounds: &Rect,
blur: Option<&ImageFilter>,
blur_mask: Option<&MaskFilter>,
count_inner_strokes: usize,
) -> Vec<Vec<ParagraphBuilder>> {
self.collect_paragraphs(self.to_stroke_paragraphs(stroke, bounds, blur, blur_mask))
self.collect_paragraphs(self.to_stroke_paragraphs(
stroke,
bounds,
blur,
blur_mask,
count_inner_strokes,
))
}
pub fn grow_type(&self) -> GrowType {
@@ -751,6 +765,7 @@ fn get_text_stroke_paints(
text_paint: &Paint,
blur: Option<&ImageFilter>,
blur_mask: Option<&MaskFilter>,
count_inner_strokes: usize,
) -> Vec<Paint> {
let mut paints = Vec::new();
@@ -763,7 +778,7 @@ fn get_text_stroke_paints(
is_opaque = shader.unwrap().is_opaque();
}
if is_opaque {
if is_opaque && count_inner_strokes == 1 {
let mut paint = text_paint.clone();
paint.set_style(skia::PaintStyle::Fill);
paint.set_anti_alias(true);
@@ -771,7 +786,6 @@ fn get_text_stroke_paints(
paint.set_image_filter(blur.clone());
}
paints.push(paint);
let mut paint = skia::Paint::default();
paint.set_style(skia::PaintStyle::Stroke);
paint.set_blend_mode(skia::BlendMode::SrcIn);