mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-22 07:19:57 -05:00
Fix issue in Item#rasterize() when resolution is not 72 DPI.
Closes #412.
This commit is contained in:
parent
2c16bd9eb1
commit
bf50bd649a
1 changed files with 5 additions and 3 deletions
|
@ -1525,12 +1525,12 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
rasterize: function(resolution) {
|
rasterize: function(resolution) {
|
||||||
var bounds = this.getStrokeBounds(),
|
var bounds = this.getStrokeBounds(),
|
||||||
scale = (resolution || 72) / 72,
|
scale = (resolution || 72) / 72,
|
||||||
// floor top-left corner and ceil bottom-right corner, to never
|
// Floor top-left corner and ceil bottom-right corner, to never
|
||||||
// blur or cut pixels.
|
// blur or cut pixels.
|
||||||
topLeft = bounds.getTopLeft().floor(),
|
topLeft = bounds.getTopLeft().floor(),
|
||||||
bottomRight = bounds.getBottomRight().ceil()
|
bottomRight = bounds.getBottomRight().ceil()
|
||||||
size = new Size(bottomRight.subtract(topLeft)),
|
size = new Size(bottomRight.subtract(topLeft)),
|
||||||
canvas = CanvasProvider.getCanvas(size),
|
canvas = CanvasProvider.getCanvas(size.multiply(scale)),
|
||||||
ctx = canvas.getContext('2d'),
|
ctx = canvas.getContext('2d'),
|
||||||
matrix = new Matrix().scale(scale).translate(topLeft.negate());
|
matrix = new Matrix().scale(scale).translate(topLeft.negate());
|
||||||
ctx.save();
|
ctx.save();
|
||||||
|
@ -1542,7 +1542,9 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
canvas: canvas,
|
canvas: canvas,
|
||||||
insert: false
|
insert: false
|
||||||
});
|
});
|
||||||
raster.setPosition(topLeft.add(size.divide(2)));
|
raster.transform(new Matrix().translate(topLeft.add(size.divide(2)))
|
||||||
|
// Take resolution into acocunt and scale back to original size.
|
||||||
|
.scale(1 / scale));
|
||||||
raster.insertAbove(this);
|
raster.insertAbove(this);
|
||||||
// NOTE: We don't need to release the canvas since it now belongs to the
|
// NOTE: We don't need to release the canvas since it now belongs to the
|
||||||
// Raster!
|
// Raster!
|
||||||
|
|
Loading…
Reference in a new issue