-
-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It seems that fill-rule="evenodd" does not works correctly #62
Comments
No idea to be honnest. I guess i'll need to dive into SVG specs to get the shape of the amount of work required. It could bz fasr if it only requires path transformations but the name of the peoperty is more about path merge/combination which is new to me. There maybe are some libs to do that already. But you have to know i am not so active on those projects since i do not use icon fonts anymore so this may never happen. That said i'm open to add new collaborators that may want to help maintaining this project. |
Thank you Nicolas. I just wanted to know whether it's easy or not. |
No problem. I'll just leave this issue open for others being aware of the problem. |
@nfroidure It looks like this is an essential feature for compound paths. Here's a doc: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule And here's an example svg I've been having trouble with:
I tried both Affinity Designer and Gravit for making this icon and exporting it and in both cases ran into issues. FontForge has a tool for "Correct Direction" which appears to convert "evenodd" paths to "nonzero" if that helps you figure out how to implement this. edit: here is the code behind that "Correct Direction" tool: https://github.com/fontforge/fontforge/blob/ae2f40b2f213b2d645d5a9f1e7a55475cbfe84ea/fontforge/scripting.c#L5505 (line 5505) |
facing the same issue, any updates? |
@Coding-Kiwi No, this still seems to be an issue. I have stopped using SVGO and instead opted for -- get this -- uploading svgs to the icomoon App and then re-downloading them. It does a fairly decent job of flattening the image and dealing with winding order issues. I don't think they've open sourced whatever they're using to clean svgs, but I wish they would. |
@jwilson8767 guess who is currently reading through obfuscated icomoon app javascript lol |
I uhm.. researched a bit, like totally not reverse engineering icomoon code because that would be against their terms.. and I found out that one solution would be:
I spent some time on this and for now I can say that the pure node implementation of canvg (the one backed by canvas / cairo) fails to correctly draw an evenodd svg.. just like this package here so basically we're back at the beginning |
Wow! That's actually a really crazy approach! I love it. I did some googling (mostly focused on github) to try to find literally anyone else that had implemented an evenodd "cleaner" or anything similar, but I actually...ended up getting linked back to my own issue over here: svg/svgo#1092 Kind of weird to realize how poor support for evenodd really is. So the algorithm you mentioned really does depend on being able to render / rasterize svgs at some level. One interesting thing that I note is that this algorithm would not handle cases where the same path crosses back over itself creating a void (as is seen in the first example here). I wonder if doing a series of split operations on each path, we could end up at a point where all possible insides / outsides exist as separate paths -- but we would still need to figure out which ones were which. So yeah, back where we started -- basically browsers support evenodd because they're processing it as they rasterize the image. Any other approach will require understanding how the paths affect one another better. |
@jwilson8767 Judging from the code I have to say I'm impressed, icomoon is a great piece of software, sadly not very automatable in the free version (except things like headless browser solutions that break after each update of icomoon). Furthermore, I can confirm that even icomoon is unable to fix paths that cross back over themselves, I threw the evenodd star from the example you listed into it and it resulted in a filled out star. In my personal opinion: most icons that you would convert to a font dont have these crossing paths so it could work most of the time.. If you have an icon with inner subpaths you can autmatically, or manually with tools like Affinity Designer, fix them by changing the fillrule and reversing subpaths until everything looks fine, but crossing paths have to be fixed by adding new subpaths which would require complex detection of path overlapping in the overall context of the svg or equally expensive manual work. For anyone that is looking for a solution now:
non-selfcrossing paths only:
If I find a solution that at least fixed the non-selfcrossing ones automatically, I'll post a link here. |
You might also look into paper.js and their source code.
http://paperjs.org/reference/compoundpath/#reorient |
That's interesting, I'll have to check that out. |
I tried out to use paperjs' |
try to export for web via illustrator (AI), it works for me |
If you're using Figma, you can use the Fill Rule Editor plugin to reverse paths. Here's how to use it: https://youtu.be/j6dZw3K_E3M |
If someone else needs clear details on how to fix it, this post explains it also https://hinty.io/brucehardywald/how-to-generate-a-webfont-automated-setup/ |
That's actually the solution for us! |
I used picosvg to circumvent this problem, just simplify the SVG by running picosvg on it, and then use the simplified version. https://github.com/googlefonts/picosvg
|
fwiw, picosvg uses skia |
I have the following SVG:
The result is:
It seems that a property fill-rule="evenodd" does not used in converted font. Is it possible to convert it correctly, or it requires a lot of work?
PS: Thank you for the awesome library.
The text was updated successfully, but these errors were encountered: