From 93bc80f11ea65e4945cc26b1ac61396bd980b2aa Mon Sep 17 00:00:00 2001 From: n4n5 Date: Sun, 14 Dec 2025 12:58:54 -0700 Subject: [PATCH 1/3] fix https://github.com/linebender/resvg/issues/921 --- crates/usvg/src/writer.rs | 27 ++++++++++++------- .../tests/files/rect-clip-path-expected.svg | 10 +++++++ crates/usvg/tests/files/rect-clip-path.svg | 9 +++++++ crates/usvg/tests/write.rs | 5 ++++ 4 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 crates/usvg/tests/files/rect-clip-path-expected.svg create mode 100755 crates/usvg/tests/files/rect-clip-path.svg diff --git a/crates/usvg/src/writer.rs b/crates/usvg/src/writer.rs index 2c455cbc1..d240d3cf1 100644 --- a/crates/usvg/src/writer.rs +++ b/crates/usvg/src/writer.rs @@ -831,16 +831,23 @@ fn write_group_element(g: &Group, is_clip_path: bool, opt: &WriteOptions, xml: & // Same with text. Text elements will be converted into groups, // but only the group's children should be written. for child in &g.children { - if let Node::Path(ref path) = child { - let clip_id = g.clip_path.as_ref().map(|cp| cp.id().to_string()); - write_path( - path, - is_clip_path, - g.transform, - clip_id.as_deref(), - opt, - xml, - ); + match child { + Node::Group(ref child_group) => { + write_group_element(child_group, is_clip_path, opt, xml); + continue; + } + Node::Path(child_path) => { + let clip_id = g.clip_path.as_ref().map(|cp| cp.id().to_string()); + write_path( + child_path, + is_clip_path, + g.transform, + clip_id.as_deref(), + opt, + xml, + ); + } + _ => {} } } return; diff --git a/crates/usvg/tests/files/rect-clip-path-expected.svg b/crates/usvg/tests/files/rect-clip-path-expected.svg new file mode 100644 index 000000000..c6afc3d45 --- /dev/null +++ b/crates/usvg/tests/files/rect-clip-path-expected.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/crates/usvg/tests/files/rect-clip-path.svg b/crates/usvg/tests/files/rect-clip-path.svg new file mode 100755 index 000000000..f3467d4de --- /dev/null +++ b/crates/usvg/tests/files/rect-clip-path.svg @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/crates/usvg/tests/write.rs b/crates/usvg/tests/write.rs index 14edfbb92..e5416d325 100644 --- a/crates/usvg/tests/write.rs +++ b/crates/usvg/tests/write.rs @@ -77,6 +77,11 @@ fn text_simple_case() { resave("text-simple-case"); } +#[test] +fn text_rect_clip_path() { + resave("rect-clip-path"); +} + #[test] fn preserve_id_filter() { resave("preserve-id-filter"); From e3b2b945c88cf4a29f32348214d47a14d82b0d57 Mon Sep 17 00:00:00 2001 From: n4n5 Date: Sun, 14 Dec 2025 13:07:27 -0700 Subject: [PATCH 2/3] fmt --- crates/usvg/src/writer.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/usvg/src/writer.rs b/crates/usvg/src/writer.rs index d240d3cf1..afacefcb8 100644 --- a/crates/usvg/src/writer.rs +++ b/crates/usvg/src/writer.rs @@ -832,9 +832,8 @@ fn write_group_element(g: &Group, is_clip_path: bool, opt: &WriteOptions, xml: & // but only the group's children should be written. for child in &g.children { match child { - Node::Group(ref child_group) => { + Node::Group(child_group) => { write_group_element(child_group, is_clip_path, opt, xml); - continue; } Node::Path(child_path) => { let clip_id = g.clip_path.as_ref().map(|cp| cp.id().to_string()); From a93d27a6d9f58a563bf55cba9fa800c97a21166f Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl Date: Tue, 6 Jan 2026 19:16:10 +0100 Subject: [PATCH 3/3] Rename test --- ...ath-expected.svg => clip-path-with-transform-expected.svg} | 0 .../{rect-clip-path.svg => clip-path-with-transform.svg} | 0 crates/usvg/tests/write.rs | 4 ++-- 3 files changed, 2 insertions(+), 2 deletions(-) rename crates/usvg/tests/files/{rect-clip-path-expected.svg => clip-path-with-transform-expected.svg} (100%) rename crates/usvg/tests/files/{rect-clip-path.svg => clip-path-with-transform.svg} (100%) diff --git a/crates/usvg/tests/files/rect-clip-path-expected.svg b/crates/usvg/tests/files/clip-path-with-transform-expected.svg similarity index 100% rename from crates/usvg/tests/files/rect-clip-path-expected.svg rename to crates/usvg/tests/files/clip-path-with-transform-expected.svg diff --git a/crates/usvg/tests/files/rect-clip-path.svg b/crates/usvg/tests/files/clip-path-with-transform.svg similarity index 100% rename from crates/usvg/tests/files/rect-clip-path.svg rename to crates/usvg/tests/files/clip-path-with-transform.svg diff --git a/crates/usvg/tests/write.rs b/crates/usvg/tests/write.rs index e5416d325..4cd69d033 100644 --- a/crates/usvg/tests/write.rs +++ b/crates/usvg/tests/write.rs @@ -78,8 +78,8 @@ fn text_simple_case() { } #[test] -fn text_rect_clip_path() { - resave("rect-clip-path"); +fn clip_path_with_transform() { + resave("clip-path-with-transform"); } #[test]