Does anyone know if it's possible, either natively or mathematically with JavaScript, to implement the evenodd
fill-rule
from SVG in the HTML5 canvas element? Links to projects that do this would be helpful.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
I asked myself the same question and came across this Mozilla Bugreport.
Seems as it gets proposed to the WHATWG (canvas specs) by the bugreporters:
Yes, it should be possible with
globalCompositeOperation
. If I'm not mistaken, default "source-over" value should correspond to SVG's "evenodd" (otherwise, try few others one and see if resulting image looks identical).By mathematically do you mean an algorithm implementation ? It is certainly possible, see http://gpolo.awardspace.info/fill/main.html. It is more a demo than anything, but it solves this issue "mathematically".
That's a really old question, so things must have been different at the time, but since a long time ago, you can pass an
fillrule
parameter to thefill()
method. Thisfillrule
can be either"nonzero"
, the default, or"evenodd"
.