Skip to content

Commit

Permalink
Fix masking not taking effect for SVG paths
Browse files Browse the repository at this point in the history
Due to the fact that in the process of restoring the translation of the
path, we were also restoring any applied masks before they could be used.
  • Loading branch information
caleb531 committed Apr 26, 2024
1 parent 460d28a commit 8fcb4bd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/jcanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -3450,9 +3450,10 @@ $.fn.drawPath = function drawPath(args) {
params = new jCanvasObject(args);
if (params.d) {
// The only way to offset an SVG path drawn with Path2D() is to
// translate it (making sure we restore it at the end of the
// method)
ctx.save();
// translate it (making sure we undo the translation it at the
// end of the method); note that we cannot use ctx.save() and
// ctx.restore() because it would cause any masking to be undone
// at the end of the drawPath() code
ctx.translate(params.x, params.y);
params._path = caches.pathCache[params.d] || new Path2D(params.d);
caches.pathCache[params.d] = params._path;
Expand Down Expand Up @@ -3495,7 +3496,7 @@ $.fn.drawPath = function drawPath(args) {

// Remember to restore the earlier translation
if (params.d) {
ctx.restore();
ctx.translate(-params.x, -params.y);
}

}
Expand Down

0 comments on commit 8fcb4bd

Please sign in to comment.