Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ This changelog also contains important changes in dependencies.
- Incorrect transform order on the outermost `svg` element with a `viewBox`. (#899)
- Relative positioning of right-to-left text with `dx` and `dy`, including text on a path and text decorations. (#1093)
- `text-anchor` now uses the actual extent of a text chunk, which `dx` and `textLength` can change. (#1145)
- Filters inside rotated or skewed groups are now applied in the user space of the group.
This fixes the clipping to filter regions and subregions, as well as the direction of
offsets, blurs, turbulence and tiles, and the rendering of `feImage`. (#949)

## [0.48.1] 2026-08-02

Expand Down
61 changes: 45 additions & 16 deletions crates/resvg/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,50 @@ fn render_group(
return Some(());
}

let rest = if group.filters().is_empty() {
tiny_skia::Transform::identity()
} else {
let sx = transform.sx.hypot(transform.ky);
let sy = transform.kx.hypot(transform.sy);
tiny_skia::Transform::from_row(
transform.sx / sx,
transform.ky / sx,
transform.kx / sy,
transform.sy / sy,
0.0,
0.0,
)
};
let inv_rest = rest.invert()?;

let max_bbox = ctx.max_bbox.to_rect().transform(inv_rest)?.round_out()?;
let (layer, ibbox) =
render_layer(group, &Context { max_bbox }, inv_rest.pre_concat(transform))?;

let paint = tiny_skia::Paint {
shader: tiny_skia::Pattern::new(
layer.as_ref(),
tiny_skia::SpreadMode::Pad,
tiny_skia::FilterQuality::Bilinear,
group.opacity().get(),
tiny_skia::Transform::from_translate(ibbox.x() as f32, ibbox.y() as f32),
),
blend_mode: convert_blend_mode(group.blend_mode()),
anti_alias: true,
..tiny_skia::Paint::default()
};
let path = tiny_skia::PathBuilder::from_rect(ibbox.to_rect());
pixmap.fill_path(&path, &paint, tiny_skia::FillRule::Winding, rest, None);

Some(())
}

/// Renders an isolated group into a new layer, returning it and its position.
fn render_layer(
group: &usvg::Group,
ctx: &Context,
transform: tiny_skia::Transform,
) -> Option<(tiny_skia::Pixmap, tiny_skia::IntRect)> {
let bbox = group.layer_bounding_box().transform(transform)?;

let mut ibbox = if group.filters().is_empty() {
Expand Down Expand Up @@ -124,22 +168,7 @@ fn render_group(
crate::mask::apply(mask, ctx, transform, &mut sub_pixmap);
}

let paint = tiny_skia::PixmapPaint {
opacity: group.opacity().get(),
blend_mode: convert_blend_mode(group.blend_mode()),
quality: tiny_skia::FilterQuality::Nearest,
};

pixmap.draw_pixmap(
ibbox.x(),
ibbox.y(),
sub_pixmap.as_ref(),
&paint,
tiny_skia::Transform::identity(),
None,
);

Some(())
Some((sub_pixmap, ibbox))
}

pub fn convert_blend_mode(mode: usvg::BlendMode) -> tiny_skia::BlendMode {
Expand Down
Binary file modified crates/resvg/tests/extra/filter-with-transform-on-shape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions crates/resvg/tests/integration/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,15 @@ use crate::render;
#[test] fn filters_filter_with_multiple_transforms_1() { assert_eq!(render("tests/filters/filter/with-multiple-transforms-1"), 0); }
#[test] fn filters_filter_with_multiple_transforms_2() { assert_eq!(render("tests/filters/filter/with-multiple-transforms-2"), 0); }
#[test] fn filters_filter_with_region_and_filterUnits_eq_userSpaceOnUse() { assert_eq!(render("tests/filters/filter/with-region-and-filterUnits=userSpaceOnUse"), 0); }
#[test] fn filters_filter_with_region_and_skew_on_intermediate_result() { assert_eq!(render("tests/filters/filter/with-region-and-skew-on-intermediate-result"), 0); }
#[test] fn filters_filter_with_region_and_subregion() { assert_eq!(render("tests/filters/filter/with-region-and-subregion"), 0); }
#[test] fn filters_filter_with_region_outside_the_canvas() { assert_eq!(render("tests/filters/filter/with-region-outside-the-canvas"), 0); }
#[test] fn filters_filter_with_region_outside_the_viewbox() { assert_eq!(render("tests/filters/filter/with-region-outside-the-viewbox"), 0); }
#[test] fn filters_filter_with_region() { assert_eq!(render("tests/filters/filter/with-region"), 0); }
#[test] fn filters_filter_with_subregion_1() { assert_eq!(render("tests/filters/filter/with-subregion-1"), 0); }
#[test] fn filters_filter_with_subregion_2() { assert_eq!(render("tests/filters/filter/with-subregion-2"), 0); }
#[test] fn filters_filter_with_subregion_3() { assert_eq!(render("tests/filters/filter/with-subregion-3"), 0); }
#[test] fn filters_filter_with_subregion_and_rotation() { assert_eq!(render("tests/filters/filter/with-subregion-and-rotation"), 0); }
#[test] fn filters_filter_with_transform_outside_of_canvas() { assert_eq!(render("tests/filters/filter/with-transform-outside-of-canvas"), 0); }
#[test] fn filters_filter_without_region_and_filterUnits_eq_userSpaceOnUse() { assert_eq!(render("tests/filters/filter/without-region-and-filterUnits=userSpaceOnUse"), 0); }
#[test] fn filters_filter_zero_sized_subregion() { assert_eq!(render("tests/filters/filter/zero-sized-subregion"), 0); }
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/resvg/tests/tests/filters/feFlood/complex-transform.png
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/resvg/tests/tests/filters/feImage/with-subregion-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/resvg/tests/tests/filters/feMerge/complex-transform.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/resvg/tests/tests/filters/feOffset/complex-transform.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/resvg/tests/tests/filters/fePointLight/complex-transform.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/resvg/tests/tests/filters/feSpotLight/complex-transform.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/resvg/tests/tests/filters/feTile/complex-transform.png

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

Chrome looks a bit different, the bottom row seems to be cut off? But the skewing itself matches now.

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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/resvg/tests/tests/filters/filter/transform-on-shape.png
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.
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.
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.
Loading