mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Merge branch 'master' of https://github.com/tranek/paper.js into tranek-master
Conflicts: src/item/Raster.js
This commit is contained in:
commit
e0856a0d31
1 changed files with 23 additions and 14 deletions
|
@ -71,11 +71,11 @@ var Raster = Item.extend(/** @lends Raster# */{
|
|||
* raster.scale(0.5);
|
||||
* raster.rotate(10);
|
||||
*/
|
||||
initialize: function Raster(object, position) {
|
||||
initialize: function(object, position) {
|
||||
// Support two forms of item initialization: Passing one object literal
|
||||
// describing all the different properties to be set, or an image
|
||||
// (object) and a point where it should be placed (point).
|
||||
Item.call(this, position !== undefined && Point.read(arguments, 1));
|
||||
this.base(position !== undefined && Point.read(arguments, 1));
|
||||
// If we can handle setting properties through object literal, we're all
|
||||
// set. Otherwise we need to check the type of object:
|
||||
if (object && !this._set(object)) {
|
||||
|
@ -163,7 +163,7 @@ var Raster = Item.extend(/** @lends Raster# */{
|
|||
orig = new Point(0, 0).transform(matrix),
|
||||
u = new Point(1, 0).transform(matrix).subtract(orig),
|
||||
v = new Point(0, 1).transform(matrix).subtract(orig);
|
||||
return new Size(
|
||||
return Size.create(
|
||||
72 / u.getLength(),
|
||||
72 / v.getLength()
|
||||
);
|
||||
|
@ -217,7 +217,7 @@ var Raster = Item.extend(/** @lends Raster# */{
|
|||
if (this._canvas)
|
||||
CanvasProvider.release(this._canvas);
|
||||
this._canvas = canvas;
|
||||
this._size = new Size(canvas.width, canvas.height);
|
||||
this._size = Size.create(canvas.width, canvas.height);
|
||||
this._image = null;
|
||||
this._context = null;
|
||||
this._changed(/*#=*/ Change.GEOMETRY | /*#=*/ Change.PIXELS);
|
||||
|
@ -238,10 +238,10 @@ var Raster = Item.extend(/** @lends Raster# */{
|
|||
CanvasProvider.release(this._canvas);
|
||||
this._image = image;
|
||||
/*#*/ if (options.browser) {
|
||||
this._size = new Size(image.naturalWidth, image.naturalHeight);
|
||||
/*#*/ } else if (options.node) {
|
||||
this._size = new Size(image.width, image.height);
|
||||
/*#*/ } // options.node
|
||||
this._size = Size.create(image.naturalWidth, image.naturalHeight);
|
||||
/*#*/ } else if (options.server) {
|
||||
this._size = Size.create(image.width, image.height);
|
||||
/*#*/ } // options.server
|
||||
this._canvas = null;
|
||||
this._context = null;
|
||||
this._changed(/*#=*/ Change.GEOMETRY);
|
||||
|
@ -297,11 +297,17 @@ var Raster = Item.extend(/** @lends Raster# */{
|
|||
}
|
||||
/*#*/ } else if (options.node) {
|
||||
// If we're running on the server and it's a string,
|
||||
// load it from disk:
|
||||
// TODO: load images async, calling setImage once loaded as above
|
||||
var image = new Image();
|
||||
image.src = fs.readFileSync(src);
|
||||
/*#*/ } // options.node
|
||||
// check if it is a data URL
|
||||
if (src.indexOf('data:') == 0) {
|
||||
image.src = src;
|
||||
// Preserve the src as canvas-node eats it
|
||||
image._src = src;
|
||||
} else {
|
||||
// load it from disk:
|
||||
// TODO: load images async, calling setImage once loaded as above
|
||||
image.src = fs.readFileSync(src);
|
||||
}
|
||||
/*#*/ } // options.server
|
||||
this.setImage(image);
|
||||
},
|
||||
|
||||
|
@ -334,6 +340,9 @@ var Raster = Item.extend(/** @lends Raster# */{
|
|||
// See if the linked image is base64 encoded already, if so reuse it,
|
||||
// otherwise try using canvas.toDataURL()
|
||||
var src = this._image && this._image.src;
|
||||
/*#*/ if (options.node) {
|
||||
src = this._image._src;
|
||||
}
|
||||
if (/^data:/.test(src))
|
||||
return src;
|
||||
var canvas = this.getCanvas();
|
||||
|
@ -374,7 +383,7 @@ var Raster = Item.extend(/** @lends Raster# */{
|
|||
bounds = new Rectangle(object);
|
||||
} else if (object.x) {
|
||||
// Create a rectangle of 1px size around the specified coordinates
|
||||
bounds = new Rectangle(object.x - 0.5, object.y - 0.5, 1, 1);
|
||||
bounds = Rectangle.create(object.x - 0.5, object.y - 0.5, 1, 1);
|
||||
}
|
||||
// Use a sample size of max 32 x 32 pixels, into which the path is
|
||||
// scaled as a clipping path, and then the actual image is drawn in and
|
||||
|
|
Loading…
Reference in a new issue