I have had a fight, trying to figure out how to get
subtract
two paths from eath other. I needed the part which was cut out, not the overlapping part. Raphael.js have a function which came to my rescue:
pathInterSection(path1, path2)
.
Update
: Please see
A native better solution
below.
Paths:
sec
and
pri
Raphael.pathIntersection(sec, pri)
Reset
sec
This is
sec
subtracted
pri
.
mask
I discovered some problem with the above method. It is not bullit proof. I found a bettes solution which uses native SVG
mask
tag.
I create a
mask
which is a
p
(ath) element. It is a combination of a path based rectangle which fills out the whole canvas. I is then added the
pri
element which I want to mask out on
sec
element.
For this to work the mask needs to use the
fill-rule
"
evenodd
". Look inside the
HTML
to see the trick.