mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 14:10:14 -05:00
parent
6e1c89234d
commit
47768779b7
1 changed files with 8 additions and 3 deletions
|
@ -1271,15 +1271,20 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
rasterize: function(resolution) {
|
||||
var bounds = this.getStrokeBounds(),
|
||||
scale = (resolution || 72) / 72,
|
||||
canvas = CanvasProvider.getCanvas(bounds.getSize().multiply(scale)),
|
||||
// floor top-left corner and ceil bottom-right corner, to never
|
||||
// blur or cut pixels.
|
||||
topLeft = bounds.getTopLeft().floor(),
|
||||
bottomRight = bounds.getBottomRight().ceil()
|
||||
size = new Size(bottomRight.subtract(topLeft)),
|
||||
canvas = CanvasProvider.getCanvas(size),
|
||||
ctx = canvas.getContext('2d'),
|
||||
matrix = new Matrix().scale(scale).translate(-bounds.x, -bounds.y);
|
||||
matrix = new Matrix().scale(scale).translate(topLeft.negate());
|
||||
ctx.save();
|
||||
matrix.applyToContext(ctx);
|
||||
// See Project#draw() for an explanation of Base.merge()
|
||||
this.draw(ctx, Base.merge({ transforms: [matrix] }));
|
||||
var raster = new Raster(canvas);
|
||||
raster.setBounds(bounds);
|
||||
raster.setPosition(topLeft.add(size.divide(2)));
|
||||
ctx.restore();
|
||||
// NOTE: We don't need to release the canvas since it now belongs to the
|
||||
// Raster!
|
||||
|
|
Loading…
Reference in a new issue