From 769f20b0e18864fbe2583d4654c58fd958c1df14 Mon Sep 17 00:00:00 2001 From: Jan Potoms Date: Sat, 16 Apr 2016 22:06:25 +0200 Subject: [PATCH] .clip was not working, the path never made it to the clip area --- canvas2svg.js | 1 + test/unit.spec.js | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/canvas2svg.js b/canvas2svg.js index e02d1b7..ce3b056 100644 --- a/canvas2svg.js +++ b/canvas2svg.js @@ -1029,6 +1029,7 @@ id = randomString(this.__ids), newGroup = this.__createElement("g"); + this.__applyCurrentDefaultPath(); group.removeChild(this.__currentElement); clipPath.setAttribute("id", id); clipPath.appendChild(this.__currentElement); diff --git a/test/unit.spec.js b/test/unit.spec.js index bcafbd1..44f74db 100644 --- a/test/unit.spec.js +++ b/test/unit.spec.js @@ -332,4 +332,16 @@ describe('canvas2svg', function() { expect(svg.querySelector("path").getAttribute("stroke-opacity")).to.equal(''+0.8*0.5); }); }); + + describe("supports clip", function() { + it("adds clippath", function() { + var ctx = new C2S(); + ctx.rect(200, 200, 400, 400); + ctx.clip(); + ctx.fillStyle = "#000000"; + ctx.rect(100, 100, 300, 300); + var svg = ctx.getSvg(); + expect(svg.querySelector("clipPath > path").getAttribute("d")).to.not.equal(null); + }); + }); });