Skip to content

Commit

Permalink
Fix Item#rasterize() bounds cache when reusing raster
Browse files Browse the repository at this point in the history
  • Loading branch information
lehni committed Mar 17, 2021
1 parent 5e488d9 commit fc5b7fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/item/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -1796,9 +1796,7 @@ new function() { // Injection scope for various item event handlers
resolution = arg0;
insert = arg1;
}
if (raster) {
raster.matrix.reset(true);
} else {
if (!raster) {
raster = new Raster(Item.NO_INSERT);
}
var bounds = this.getStrokeBounds(),
Expand All @@ -1821,7 +1819,7 @@ new function() { // Injection scope for various item event handlers
this.draw(ctx, new Base({ matrices: [matrix] }));
ctx.restore();
}
raster.transform(
raster._matrix.set(
new Matrix()
.translate(topLeft.add(boundsSize.divide(2)))
// Take resolution into account and scale back to original size.
Expand Down
5 changes: 5 additions & 0 deletions test/tests/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,11 @@ test('Item#rasterize() bounds', function() {
equals(function() {
return circle.rasterize({ resolution: 1000 }).bounds;
}, new Rectangle({ x: 45.032, y: 45.032, width: 9.936, height: 9.936 }));
equals(function() {
var raster = circle.rasterize({ resolution: 1000 });
// Reusing the raster for a 2nd rasterization should leave it in place.
return circle.rasterize({ resolution: 1000, raster }).bounds;
}, new Rectangle({ x: 45.032, y: 45.032, width: 9.936, height: 9.936 }));
});

test('Item#draw() with CompoundPath as clip item', function() {
Expand Down

0 comments on commit fc5b7fe

Please sign in to comment.