Skip to content

Commit

Permalink
Optimize paths without markers
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV committed Feb 25, 2025
1 parent f4188dd commit dd44be3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
24 changes: 7 additions & 17 deletions crates/usvg/src/parser/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -931,29 +931,19 @@ fn convert_path(
None => return,
};

match raw_paint_order.order {
[PaintOrderKind::Markers, _, _] => {
if let Some(markers_node) = marker {
parent.children.push(Node::Group(Box::new(markers_node)));
}

match (raw_paint_order.order, marker) {
([PaintOrderKind::Markers, _, _], Some(markers_node)) => {
parent.children.push(Node::Group(Box::new(markers_node)));
parent.children.push(Node::Path(Box::new(path.clone())));
}
[first, PaintOrderKind::Markers, last] => {
([first, PaintOrderKind::Markers, last], Some(markers_node)) => {
append_single_paint_path(first, &path, parent);

if let Some(markers_node) = marker {
parent.children.push(Node::Group(Box::new(markers_node)));
}

parent.children.push(Node::Group(Box::new(markers_node)));
append_single_paint_path(last, &path, parent);
}
[_, _, PaintOrderKind::Markers] => {
([_, _, PaintOrderKind::Markers], Some(markers_node)) => {
parent.children.push(Node::Path(Box::new(path.clone())));

if let Some(markers_node) = marker {
parent.children.push(Node::Group(Box::new(markers_node)));
}
parent.children.push(Node::Group(Box::new(markers_node)));
}
_ => parent.children.push(Node::Path(Box::new(path.clone()))),
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions crates/usvg/tests/files/optimize-paths-without-markers.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions crates/usvg/tests/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,8 @@ fn preserve_text_with_complex_text_decoration() {
fn preserve_text_with_nested_baseline_shift() {
resave_with_text("preserve-text-with-nested-baseline-shift");
}

#[test]
fn optimize_paths_without_markers() {
resave("optimize-paths-without-markers");
}

0 comments on commit dd44be3

Please sign in to comment.