Skip to content

Commit

Permalink
Fix context paint on shape with zero-size bbox.
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV committed Mar 19, 2024
1 parent 25fd250 commit 5b97397
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 16 additions & 15 deletions crates/usvg/src/parser/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ fn convert_path(
&mut fill.paint,
true,
context_transform,
Some(context_bbox.to_rect()),
context_bbox.map(|r| r.to_rect()),
path_transform,
tiny_skia_path.bounds(),
cache,
Expand All @@ -790,7 +790,7 @@ fn convert_path(
&mut stroke.paint,
true,
context_transform,
Some(context_bbox.to_rect()),
context_bbox.map(|r| r.to_rect()),
path_transform,
tiny_skia_path.bounds(),
cache,
Expand All @@ -804,21 +804,22 @@ fn convert_path(
let mut marker_group = Group::empty();
let mut marker_state = state.clone();

if let Some(bounding_box) = tiny_skia_path.compute_tight_bounds().and_then(|r| r.to_non_zero_rect()) {
let fill = fill.clone().map(|mut f| {
f.context_element =
Some(ContextElement::PathNode(path_transform, bounding_box));
f
});
let bbox = tiny_skia_path.compute_tight_bounds().and_then(|r| r.to_non_zero_rect());

let stroke = stroke.clone().map(|mut s| {
s.context_element =
Some(ContextElement::PathNode(path_transform, bounding_box));
s
});
let fill = fill.clone().map(|mut f| {
f.context_element =
Some(ContextElement::PathNode(path_transform, bbox));
f
});

let stroke = stroke.clone().map(|mut s| {
s.context_element =
Some(ContextElement::PathNode(path_transform, bbox));
s
});

marker_state.context_element = Some((fill, stroke));

marker_state.context_element = Some((fill, stroke))
}
marker::convert(
node,
&tiny_skia_path,
Expand Down
2 changes: 1 addition & 1 deletion crates/usvg/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ pub(crate) enum ContextElement {
/// if we draw the marker of a path). Since we already know the bounding
/// box of the path when rendering the markers, we can convert them directly,
/// so we do it while parsing.
PathNode(Transform, NonZeroRect),
PathNode(Transform, Option<NonZeroRect>),
}

/// A fill style.
Expand Down

0 comments on commit 5b97397

Please sign in to comment.