Skip to content

Commit

Permalink
(usvg-cli) Fix feImage writing.
Browse files Browse the repository at this point in the history
  • Loading branch information
RazrFalcon committed Dec 16, 2023
1 parent 5dc9648 commit ec819c7
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 6 deletions.
16 changes: 16 additions & 0 deletions crates/usvg-parser/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,22 @@ fn convert_image(fe: SvgNode, state: &converter::State, cache: &mut converter::C
crate::converter::convert_element(node, &state, cache, &mut root);
return if let Some(node) = root.first_child() {
node.detach(); // drops `root` node

// Transfer node id from group's child to the group itself if needed.
let mut id = String::new();
if let Some(child) = node.first_child() {
id = child.borrow().id().to_string();
match *child.borrow_mut() {
NodeKind::Group(ref mut g) => g.id.clear(),
NodeKind::Path(ref mut path) => path.id.clear(),
NodeKind::Image(ref mut image) => image.id.clear(),
NodeKind::Text(ref mut text) => text.id.clear(),
}
}
if let NodeKind::Group(ref mut g) = *node.borrow_mut() {
g.id = id;
}

Kind::Image(Image {
aspect,
rendering_mode,
Expand Down
12 changes: 12 additions & 0 deletions crates/usvg/tests/files/preserve-id-fe-image-expected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions crates/usvg/tests/files/preserve-id-fe-image-with-opacity.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions crates/usvg/tests/files/preserve-id-fe-image.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 9 additions & 4 deletions crates/usvg/tests/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,15 @@ fn preserve_id_filter() {
resave("preserve-id-filter");
}

// #[test]
// fn preserve_id_fe_image() {
// resave("preserve-id-fe-image");
// }
#[test]
fn preserve_id_fe_image() {
resave("preserve-id-fe-image");
}

#[test]
fn preserve_id_fe_image_with_opacity() {
resave("preserve-id-fe-image-with-opacity");
}

#[test]
fn generate_filter_id_function_v1() {
Expand Down

0 comments on commit ec819c7

Please sign in to comment.