Merge branch 'refs/heads/tranek-master'

This commit is contained in:
Jürg Lehni 2013-05-28 08:06:06 -07:00
commit 277f7aabae

View file

@ -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);
@ -295,14 +295,21 @@ var Raster = Item.extend(/** @lends Raster# */{
} else if (!image.src) {
image.src = src;
}
/*#*/ } 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
this.setImage(image);
/*#*/ } else if (options.node) {
var image = new Image();
// If we're running on the server and it's a string,
// check if it is a data URL
if (/^data:/.test(src)) {
// Preserve the src in _src since canvas-node eats it.
image.src = image._src = src;
} else {
// Load it from disk:
// TODO: load images async, calling setImage once loaded as above.
image.src = fs.readFileSync(src);
}
this.setImage(image);
/*#*/ } // options.server
},
// DOCS: document Raster#getElement
@ -333,7 +340,11 @@ var Raster = Item.extend(/** @lends Raster# */{
toDataURL: function() {
// See if the linked image is base64 encoded already, if so reuse it,
// otherwise try using canvas.toDataURL()
/*#*/ if (options.node) {
var src = this._image && this._image._src;
/*#*/ } else {
var src = this._image && this._image.src;
/*#*/ }
if (/^data:/.test(src))
return src;
var canvas = this.getCanvas();
@ -374,7 +385,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