From 3e445586d970312988c7d11aa307e845d3dd01fd Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 11 Nov 2026 13:20:02 +0000 Subject: [PATCH] address review: stroke dash arrays in the tile copy weight --- crates/pdf/src/page.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/pdf/src/page.rs b/crates/pdf/src/page.rs index 04d8d3b71..7a3fbc4b0 100644 --- a/crates/pdf/src/page.rs +++ b/crates/pdf/src/page.rs @@ -273,6 +273,10 @@ fn copy_weight(nodes: &[Node]) -> usize { if let effectcraft_svg::Geom::Path(p) = &sh.geom { weight = weight.saturating_add(p.elements().len()); } + // A stroke's dash array is copied with it. + if let Some((dash, _)) = sh.stroke.as_ref().and_then(|s| s.dash.as_ref()) { + weight = weight.saturating_add(dash.len()); + } // A gradient paint is copied with its stops. for paint in [sh.fill.as_ref(), sh.stroke.as_ref().map(|s| &s.paint)].into_iter().flatten() { if let Paint::Gradient(g) = paint { @@ -1308,6 +1312,20 @@ mod weight_tests { }; assert_eq!(copy_weight(&[shape(Some(Paint::Color([0.0; 3])))]), 1); assert_eq!(copy_weight(&[shape(Some(gradient(500)))]), 501); + // A stroke's dash array counts too. + let mut stroked = shape(None); + if let Node::Shape(sh) = &mut stroked { + sh.stroke = Some(effectcraft_svg::Stroke { + paint: Paint::Color([0.0; 3]), + opacity: 1.0, + width: 1.0, + cap: Cap::Butt, + join: Join::Miter, + miter: 4.0, + dash: Some((vec![1.0; 256], 0.0)), + }); + } + assert_eq!(copy_weight(&[stroked]), 257); // A mask's content is counted with the group that holds it. let mut inner = Group::new("mask"); inner.children.push(shape(None));