From f39b7603de79209736dde2d142746317dfc60156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Thu, 15 May 2014 17:14:37 +0200 Subject: [PATCH] Remove pixelRatio handling from CanvasProvider and move it to Item#draw() --- src/canvas/CanvasProvider.js | 21 ++++++--------------- src/item/Item.js | 6 ++++-- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/canvas/CanvasProvider.js b/src/canvas/CanvasProvider.js index 04e8ed5f..4973f250 100644 --- a/src/canvas/CanvasProvider.js +++ b/src/canvas/CanvasProvider.js @@ -15,20 +15,13 @@ var CanvasProvider = { canvases: [], - getCanvas: function(width, height, pixelRatio) { + getCanvas: function(width, height) { var canvas, - init = true; + clear = true; if (typeof width === 'object') { - pixelRatio = height; height = width.height; width = width.width; } - if (!pixelRatio) { - pixelRatio = 1; - } else if (pixelRatio !== 1) { - width *= pixelRatio; - height *= pixelRatio; - } if (this.canvases.length) { canvas = this.canvases.pop(); } else { @@ -36,7 +29,7 @@ var CanvasProvider = { canvas = document.createElement('canvas'); /*#*/ } else { // __options.environment != 'browser' canvas = new Canvas(width, height); - init = false; // It's already initialized through constructor. + clear = false; // It's already cleared through constructor. /*#*/ } // __options.environment != 'browser' } var ctx = canvas.getContext('2d'); @@ -44,7 +37,7 @@ var CanvasProvider = { // using clearRect and visa versa. if (canvas.width === width && canvas.height === height) { // +1 is needed on some browsers to really clear the borders - if (init) + if (clear) ctx.clearRect(0, 0, width + 1, height + 1); } else { canvas.width = width; @@ -52,13 +45,11 @@ var CanvasProvider = { } // We save on retrieval and restore on release. ctx.save(); - if (pixelRatio !== 1) - ctx.scale(pixelRatio, pixelRatio); return canvas; }, - getContext: function(width, height, pixelRatio) { - return this.getCanvas(width, height, pixelRatio).getContext('2d'); + getContext: function(width, height) { + return this.getCanvas(width, height).getContext('2d'); }, // release can receive either a canvas or a context. diff --git a/src/item/Item.js b/src/item/Item.js index 66246bf9..28fe6358 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -3661,8 +3661,10 @@ var Item = Base.extend(Callback, /** @lends Item# */{ // Set ctx to the context of the temporary canvas, so we draw onto // it, instead of the mainCtx. mainCtx = ctx; - ctx = CanvasProvider.getContext( - bounds.getSize().ceil().add(new Size(1, 1)), pixelRatio); + ctx = CanvasProvider.getContext(bounds.getSize().ceil().add(1) + .multiply(pixelRatio)); + if (pixelRatio !== 1) + ctx.scale(pixelRatio, pixelRatio); } ctx.save(); // Get the transformation matrix for non-scaling strokes.