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();
// 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(),

View file

@ -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() {