mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Merge pull request #17 from fsih/rasterizeOptions
Allow user to set bounds in Item.rasterize
This commit is contained in:
commit
f255218f36
1 changed files with 5 additions and 2 deletions
|
@ -1666,6 +1666,8 @@ new function() { // Injection scope for various item event handlers
|
||||||
* @param {Boolean} [insert=true] specifies whether the raster should be
|
* @param {Boolean} [insert=true] specifies whether the raster should be
|
||||||
* inserted into the scene graph. When set to `true`, it is inserted
|
* inserted into the scene graph. When set to `true`, it is inserted
|
||||||
* above the original
|
* above the original
|
||||||
|
* @param {Rectangle} [boundRect] bounds within which to rasterize. Defaults
|
||||||
|
* to stroke bounds.
|
||||||
* @return {Raster} the newly created raster item
|
* @return {Raster} the newly created raster item
|
||||||
*
|
*
|
||||||
* @example {@paperscript}
|
* @example {@paperscript}
|
||||||
|
@ -1686,9 +1688,9 @@ new function() { // Injection scope for various item event handlers
|
||||||
* circle.scale(5);
|
* circle.scale(5);
|
||||||
* raster.scale(5);
|
* raster.scale(5);
|
||||||
*/
|
*/
|
||||||
rasterize: function(resolution, insert) {
|
rasterize: function(resolution, insert, boundRect) {
|
||||||
// TODO: Switch to options object for more descriptive call signature.
|
// TODO: Switch to options object for more descriptive call signature.
|
||||||
var bounds = this.getStrokeBounds(),
|
var bounds = boundRect ? boundRect : this.getStrokeBounds(),
|
||||||
scale = (resolution || this.getView().getResolution()) / 72,
|
scale = (resolution || this.getView().getResolution()) / 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.
|
||||||
|
@ -1700,6 +1702,7 @@ new function() { // Injection scope for various item event handlers
|
||||||
var canvas = CanvasProvider.getCanvas(size.multiply(scale)),
|
var 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.imageSmoothingEnabled = false;
|
||||||
ctx.save();
|
ctx.save();
|
||||||
matrix.applyToContext(ctx);
|
matrix.applyToContext(ctx);
|
||||||
// See Project#draw() for an explanation of new Base()
|
// See Project#draw() for an explanation of new Base()
|
||||||
|
|
Loading…
Reference in a new issue