I am trying to do hole in the polygon using fillRule = 'evenodd' in fabric.js
globalCompositeOperation won't work for me, because I need to see shape in the polygon hole like this
Here is my code: fiddle
There are 2 examples:
- Fabric.js 2 polygons (doesn't work)
- native html5 canvas 2 polygons (works)
When I set fillRule: 'evenodd' for fabric.js polygon, it is going to the fabric function and it's setting context fill to 'eveneodd'
_renderFill: function(ctx) {
...
if (this.fillRule === 'evenodd') {
ctx.fill('evenodd');
}
...
ctx.restore();
},
But still it doesn't work. Please, give my some idea how to use 'enevodd' if fabric.js
The 'evenodd' fill rule works fine with one fabric object. You cannot use this rule for separate objects and combine them together, even if you are using a group object. In a group rendering for the shapes happening separately, which means every object calls:
or
Using 'evenodd' rule for multiple objects is missing feature in the Fabric.js.
Here is some workaround how to use 'evenodd' rule for one subjects polygon and multiple subtracted polygons.
Steps:
Here is a fiddle.
This code needs to be improved. It gives an idea how to make holes in the polygon using 'evenodd' rule.