From c929bacde8e2c94c726ef7d33e3acc3431ace7c5 Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Thu, 24 Feb 2011 01:33:36 +0100 Subject: [PATCH] Clean up Group#draw and save/restore context state when drawing group with opacity. --- src/item/Group.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/item/Group.js b/src/item/Group.js index 9976cb68..552cd5c6 100644 --- a/src/item/Group.js +++ b/src/item/Group.js @@ -17,10 +17,10 @@ Group = Item.extend({ // If the group has an opacity of less then 1, draw its children on a // temporary canvas, and then draw that canvas onto ctx afterwards // with globalAlpha set. + var tempCanvas, originalCtx; if (this.opacity < 1) { var originalCtx = ctx; - var size = this.document.size; - var tempCanvas = CanvasProvider.getCanvas(size.width, size.height); + tempCanvas = CanvasProvider.getCanvas(this.document.size); ctx = tempCanvas.getContext('2d'); } for (var i = 0, l = this.children.length; i < l; i++) { @@ -29,8 +29,10 @@ Group = Item.extend({ ctx.clip(); } if (tempCanvas) { + originalCtx.save(); originalCtx.globalAlpha = this.opacity; originalCtx.drawImage(tempCanvas, 0, 0); + originalCtx.restore(); // Return the canvas, so it can be reused CanvasProvider.returnCanvas(tempCanvas); }