mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Implement item#rasterize(resolution).
This commit is contained in:
parent
014d1053a7
commit
d77741db4f
1 changed files with 20 additions and 5 deletions
|
@ -509,14 +509,29 @@ Item = Base.extend({
|
||||||
* Rasterizes the item into a newly created Raster object. The item itself
|
* Rasterizes the item into a newly created Raster object. The item itself
|
||||||
* is not removed after rasterization.
|
* is not removed after rasterization.
|
||||||
*
|
*
|
||||||
* @param type the color mode of the raster {@default same as document}
|
|
||||||
* @param resolution the resolution of the raster in dpi {@default 72}
|
* @param resolution the resolution of the raster in dpi {@default 72}
|
||||||
* @param antialiasing the amount of anti-aliasing {@default 4}
|
|
||||||
* @param width {@default automatic}
|
|
||||||
* @param height {@default automatic}
|
|
||||||
* @return the newly created Raster item
|
* @return the newly created Raster item
|
||||||
*/
|
*/
|
||||||
// TODO: rasterize
|
rasterize: function(resolution) {
|
||||||
|
// TODO: why would we want to pass a size to rasterize? Seems to produce
|
||||||
|
// weird results on Scriptographer. Also we can't use antialiasing, since
|
||||||
|
// Canvas doesn't support it yet. Document colorMode is also out of the
|
||||||
|
// question for now.
|
||||||
|
if(!resolution)
|
||||||
|
resolution = 72;
|
||||||
|
// TODO: use strokebounds for this:
|
||||||
|
var bounds = this.bounds;
|
||||||
|
var scale = resolution / 72;
|
||||||
|
var canvas = CanvasProvider.getCanvas(bounds.size.multiply(scale));
|
||||||
|
var context = canvas.getContext('2d');
|
||||||
|
var matrix = new Matrix().scale(scale).translate(-bounds.x, -bounds.y);
|
||||||
|
matrix.applyToContext(context);
|
||||||
|
this.draw(context);
|
||||||
|
var raster = new Raster(canvas);
|
||||||
|
raster.position = this.bounds.center;
|
||||||
|
raster.scale(1 / scale);
|
||||||
|
return raster;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The item's position within the art board. This is the
|
* The item's position within the art board. This is the
|
||||||
|
|
Loading…
Reference in a new issue