paperjs / paper.js

The Swiss Army Knife of Vector Graphics Scripting – Scriptographer ported to JavaScript and the browser, using HTML5 Canvas. Created by @lehni & @puckey
http://paperjs.org
Other
14.46k stars 1.22k forks source link

Preview not matching the export with clipped group #1618

Open OriginalEXE opened 5 years ago

OriginalEXE commented 5 years ago

Description/Steps to reproduce

Hello, I am using your library and it has been serving me great so far, thanks!

I believe I ran into another interesting bug. On some shapes (not all of them) it looks like the clipping group is "leaking" its contents. The interesting thing is that when I export the SVG, it looks great, so this issue only affects the canvas.

NOTE: When you are testing the export of an SVG, make sure to open the clipPath inside the defs and remove the group that wraps one of the paths, that's a bug from my other issue.

Link to reproduction test-case

Sketch

Expected result

The canvas clipped group should not "leak" its contents and should match the exported SVG appearance

sasensi commented 5 years ago

Hi, thanks for the report, just to clarify the bug:

OriginalEXE commented 5 years ago

Correct. It only happens with some butterfly shapes, for others it works as expected. Very weird.

sasensi commented 5 years ago

The reason behind this bug is that you are clipping with a group which is itself clipped. If you look closer at what is imported in your svgClipItem variable, you'll see that what is imported is a group containing the butterfly path which is clipped by a rectangle shape. This is due to the presence of a viewBox attribute on your <svg> tag. Here is the code that makes the group clipped in this case: https://github.com/paperjs/paper.js/blob/b1705f628b829fe296d8191adbb8016fea09dc49/src/svg/SvgImport.js#L483-L488 So you can easily workaround this issue:

Here is a sketch reducing the bug to a simple case.

OriginalEXE commented 5 years ago

Oh wow, thank you for a detailed explanation, it makes sense! I will try it in a few hours and will report back, but I expect that that's it, thank you very much for your continued support, very appreciated!

sasensi commented 5 years ago

This seems more generally related to the fact that we only support path as clip item and should be solved by something like #59.

OriginalEXE commented 5 years ago

I used the lastChild cloning method, and it works flawlessly, thanks again, Samuel!