From d1c6b7134ff34e7bee82b7c1ecc0d1c57bea36aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Thu, 18 Apr 2013 16:50:18 -0700 Subject: [PATCH] Fix Raster#getAverageColor() to work with new transforms history code. --- src/item/Raster.js | 8 +++++--- test/tests/Raster.js | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/item/Raster.js b/src/item/Raster.js index 83601aef..6883d646 100644 --- a/src/item/Raster.js +++ b/src/item/Raster.js @@ -394,11 +394,13 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{ } ctx.save(); // Scale the context so that the bounds ends up at the given sample size - ctx.scale(width / bounds.width, height / bounds.height); - ctx.translate(-bounds.x, -bounds.y); + var matrix = new Matrix() + .scale(width / bounds.width, height / bounds.height) + .translate(-bounds.x, -bounds.y); + matrix.applyToContext(ctx); // If a path was passed, draw it as a clipping mask: if (path) - path.draw(ctx, { clip: true }); + Item.draw(path, ctx, { clip: true, transforms: [matrix] }); // Now draw the image clipped into it. this._matrix.applyToContext(ctx); ctx.drawImage(this.getElement(), diff --git a/test/tests/Raster.js b/test/tests/Raster.js index 32c39d7e..0331a2c8 100644 --- a/test/tests/Raster.js +++ b/test/tests/Raster.js @@ -119,19 +119,19 @@ asyncTest('Raster#getSubImage', function(callback) { }); test('Raster#getAverageColor(path)', function() { - new Path.Rectangle({ + var rect = new Path.Rectangle({ point: [0, 0], size: [100, 100], fillColor: new Color(0, 1, 0) }); - var path = new Path.Circle({ + var circle = new Path.Circle({ center: [50, 50], radius: 25, fillColor: new Color(1, 0, 0) }); var raster = paper.project.activeLayer.rasterize(); - path.scale(0.9); - compareColors(raster.getAverageColor(path), new Color(1, 0, 0), null, 3); + circle.scale(0.9); + compareColors(raster.getAverageColor(circle), circle.fillColor, null, 3); }); test('Raster#getAverageColor(path) with compound path', function() {