Fix Raster#getAverageColor() to work with new transforms history code.

This commit is contained in:
Jürg Lehni 2013-04-18 16:50:18 -07:00
parent c50b940ff3
commit d1c6b7134f
2 changed files with 9 additions and 7 deletions

View file

@ -394,11 +394,13 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
} }
ctx.save(); ctx.save();
// Scale the context so that the bounds ends up at the given sample size // Scale the context so that the bounds ends up at the given sample size
ctx.scale(width / bounds.width, height / bounds.height); var matrix = new Matrix()
ctx.translate(-bounds.x, -bounds.y); .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 a path was passed, draw it as a clipping mask:
if (path) if (path)
path.draw(ctx, { clip: true }); Item.draw(path, ctx, { clip: true, transforms: [matrix] });
// Now draw the image clipped into it. // Now draw the image clipped into it.
this._matrix.applyToContext(ctx); this._matrix.applyToContext(ctx);
ctx.drawImage(this.getElement(), ctx.drawImage(this.getElement(),

View file

@ -119,19 +119,19 @@ asyncTest('Raster#getSubImage', function(callback) {
}); });
test('Raster#getAverageColor(path)', function() { test('Raster#getAverageColor(path)', function() {
new Path.Rectangle({ var rect = new Path.Rectangle({
point: [0, 0], point: [0, 0],
size: [100, 100], size: [100, 100],
fillColor: new Color(0, 1, 0) fillColor: new Color(0, 1, 0)
}); });
var path = new Path.Circle({ var circle = new Path.Circle({
center: [50, 50], center: [50, 50],
radius: 25, radius: 25,
fillColor: new Color(1, 0, 0) fillColor: new Color(1, 0, 0)
}); });
var raster = paper.project.activeLayer.rasterize(); var raster = paper.project.activeLayer.rasterize();
path.scale(0.9); circle.scale(0.9);
compareColors(raster.getAverageColor(path), new Color(1, 0, 0), null, 3); compareColors(raster.getAverageColor(circle), circle.fillColor, null, 3);
}); });
test('Raster#getAverageColor(path) with compound path', function() { test('Raster#getAverageColor(path) with compound path', function() {