mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Add optional insert
parameter to #rasterize()
This commit is contained in:
parent
62a23662fa
commit
2596b81616
1 changed files with 6 additions and 2 deletions
|
@ -1540,6 +1540,9 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
|
||||||
* @param {Number} [resolution=view.resolution] the resolution of the raster
|
* @param {Number} [resolution=view.resolution] the resolution of the raster
|
||||||
* in pixels per inch (DPI). If not specified, the value of
|
* in pixels per inch (DPI). If not specified, the value of
|
||||||
* `view.resolution` is used.
|
* `view.resolution` is used.
|
||||||
|
* @param {Boolean} [insert=true] specifies whether the raster should be
|
||||||
|
* inserted into the scene graph. When set to `true`, it is inserted
|
||||||
|
* above the original
|
||||||
* @return {Raster} the newly created raster item
|
* @return {Raster} the newly created raster item
|
||||||
*
|
*
|
||||||
* @example {@paperscript}
|
* @example {@paperscript}
|
||||||
|
@ -1560,7 +1563,7 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
|
||||||
* circle.scale(5);
|
* circle.scale(5);
|
||||||
* raster.scale(5);
|
* raster.scale(5);
|
||||||
*/
|
*/
|
||||||
rasterize: function(resolution) {
|
rasterize: function(resolution, insert) {
|
||||||
var bounds = this.getStrokeBounds(),
|
var bounds = 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
|
||||||
|
@ -1585,7 +1588,8 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
|
||||||
raster.transform(new Matrix().translate(topLeft.add(size.divide(2)))
|
raster.transform(new Matrix().translate(topLeft.add(size.divide(2)))
|
||||||
// Take resolution into account and scale back to original size.
|
// Take resolution into account and scale back to original size.
|
||||||
.scale(1 / scale));
|
.scale(1 / scale));
|
||||||
raster.insertAbove(this);
|
if (insert != false) // No double-equal!
|
||||||
|
raster.insertAbove(this);
|
||||||
return raster;
|
return raster;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue