mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-24 09:46:59 -06:00
Merge pull request #3708 from Taha-Mahmoodi/fix/2788-dashed-brush
Render: a dashed brush stroke keeps the layered path for object opacity
This commit is contained in:
@@ -2231,14 +2231,15 @@ fn single_plain_fill(n: &Node) -> bool {
|
||||
|
||||
/// Number of visible painted fill/stroke items (opacity folding is exact only for one). A dashed
|
||||
/// stroke is one paint: its dashes are outlined into one path and filled once, so overlapping
|
||||
/// dashes don't darken where they overlap.
|
||||
/// dashes don't darken where they overlap. A dashed brush stroke isn't: its pieces are drawn one
|
||||
/// by one.
|
||||
fn painted_items(n: &Node) -> usize {
|
||||
n.appearance
|
||||
.items
|
||||
.iter()
|
||||
.filter(|i| match i {
|
||||
AppearanceItem::Fill(f) => f.visible && !f.paint.is_none() && matches!(f.paint, vectorcraft_color::Paint::Solid { .. }),
|
||||
AppearanceItem::Stroke(s) => s.visible && !s.paint.is_none() && s.width > 0.0 && matches!(s.paint, vectorcraft_color::Paint::Solid { .. }),
|
||||
AppearanceItem::Stroke(s) => s.visible && !s.paint.is_none() && s.width > 0.0 && matches!(s.paint, vectorcraft_color::Paint::Solid { .. }) && (s.dash.is_none() || s.brush.is_none()),
|
||||
})
|
||||
.count()
|
||||
.max(if n.appearance.items.iter().any(|i| matches!(i, AppearanceItem::Fill(f) if f.visible && !matches!(f.paint, vectorcraft_color::Paint::Solid { .. } | vectorcraft_color::Paint::None)) || matches!(i, AppearanceItem::Stroke(s) if s.visible && !matches!(s.paint, vectorcraft_color::Paint::Solid { .. } | vectorcraft_color::Paint::None))) { 2 } else { 0 })
|
||||
|
||||
@@ -980,6 +980,9 @@ fn dashed_stroke_opacity_folds_into_its_colour() {
|
||||
};
|
||||
let mut d = Document::new(100.0, 100.0);
|
||||
assert_eq!(painted_items(&dashed(&mut d, 0.6, 1.0)), 1, "a dashed stroke takes the folded fast path");
|
||||
let mut brushed = dashed(&mut d, 0.6, 1.0);
|
||||
brushed.appearance.stroke_mut().unwrap().brush = Some("Calligraphic".into());
|
||||
assert_ne!(painted_items(&brushed), 1, "a dashed brush stroke draws its pieces one by one: no folding");
|
||||
let folded = render(&doc(0.6, 1.0));
|
||||
let layered = render(&doc(1.0, 0.6));
|
||||
assert_ne!(folded.pixel(20, 40), [255, 255, 255, 255], "the stroke is drawn");
|
||||
|
||||
Reference in New Issue
Block a user