linebender / linebender/resvg

clip paths are incorrect with transform

Open
#642 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Rust
Stars
4.1k
Forks
348
Avg merge
1d 14h
Merged PRs (30d)
3

Description

I'm trying to render tiles of the full SVG. It works fine for many files but breaks for files with clip paths. Try the attached SVG with a modified version of the cairo example:

```
diff --git a/crates/c-api/examples/cairo/example.c b/crates/c-api/examples/cairo/example.c
index 23a3b45a..ab3bc558 100644
--- a/crates/c-api/examples/cairo/example.c
+++ b/crates/c-api/examples/cairo/example.c
@@ -29,6 +29,7 @@ int main(int argc, char **argv)
resvg_size size = resvg_get_image_size(tree);
int width = (int)size.width;
int height = (int)size.height;
+ height = 270;

cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);

@@ -37,7 +38,9 @@ int main(int argc, char **argv)

unsigned char *surface_data = cairo_image_surface_get_data(surface);

- resvg_render(tree, resvg_transform_identity(), width, height, (char*)surface_data);
+ resvg_transform transform = resvg_transform_identity();
+ transform.f = -height * 3;
+ resvg_render(tree, transform, width, height, (char*)surface_data);

/* RGBA -> BGRA */
for (int i = 0; i < width * height * 4; i += 4)
```
```
make
LD_LIBRARY_PATH=../../../../target/debug ./example clipPath.svg clipPath.png
```
This still works if the offset is 0 or if the full height is used, but the combination of offset, crop, and clip path cause most of the image to disappear.

![clipPath](https://github.com/RazrFalcon/resvg/assets/6538028/d6badd3d-d85c-49c0-b408-8f6e473f92cd)
![clipPath](https://github.com/RazrFalcon/resvg/assets/6538028/c8ac3a42-f27a-4058-8155-ebc14a481359)

It seems to be an old bug (at least present in 0.33.0).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with crates/c-api/examples/cairo/example.c, the modified transform, and the supplied clipPath.svg using the shown make and LD_LIBRARY_PATH commands. Start at the resvg_render entry point and trace transformed clip-path handling. Done means the cropped render preserves the clipped image when a nonzero transform offset is used.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.