diff --git a/crates/svg/src/paths.rs b/crates/svg/src/paths.rs index c165884541..013c6a252b 100644 --- a/crates/svg/src/paths.rs +++ b/crates/svg/src/paths.rs @@ -684,12 +684,12 @@ fn import_node<'a, 'input, K: Kind>( } if !state.display_none && !state.visibility_hidden - && let Some(path) = geometry_for(node, context.path_name)? + && let Some((path, drawable)) = geometry_for(node, context.path_name)? { context.charge_segments(&path)?; let transformed = transform_path(&path, state.transform); validate_import_path(&transformed, context.path_name)?; - context.shapes.push(Shape { + context.shapes.extend(drawable.then(|| Shape { path: transformed, kind: state.kind.clone(), label: label(node), @@ -699,7 +699,7 @@ fn import_node<'a, 'input, K: Kind>( fill_rule: if style.get("fill-rule").is_some_and(|value| value == "evenodd") { FillRule::EvenOdd } else { FillRule::NonZero }, clips: state.clips.clone(), layer: state.layer.as_deref().map(str::to_string), - }); + })); } for child in node.children().filter(|n| n.is_element()) { import_node(child, state.clone(), depth + 1, context)?; @@ -891,7 +891,7 @@ fn clip_region( } continue; } - let Some(path) = geometry_for(child, context.path_name)? else { + let Some((path, drawable)) = geometry_for(child, context.path_name)? else { continue; }; let mut child_space = space; @@ -908,13 +908,13 @@ fn clip_region( if context.clip_pieces > MAX_SVG_CLIP_PIECES { return Err(svg_error(context.path_name, "SVG clip paths exceed the 100,000-piece limit")); } - pieces.push((path, rule)); + pieces.extend(drawable.then_some((path, rule))); } context.clips.push(Clip { pieces }); Ok(Some(context.clips.len() - 1)) } -fn geometry_for(node: roxmltree::Node<'_, '_>, path_name: &str) -> Result, Error> { +fn geometry_for(node: roxmltree::Node<'_, '_>, path_name: &str) -> Result, Error> { let tag = node.tag_name().name(); let number = |name: &str, default: f64| -> Result { match node.attribute(name) { @@ -922,6 +922,8 @@ fn geometry_for(node: roxmltree::Node<'_, '_>, path_name: &str) -> Result