Merge remote-tracking branch 'origin/master'

Conflicts:
	test/lib/helpers.js
This commit is contained in:
Jürg Lehni 2011-05-21 14:41:08 +01:00
commit 816424a9c5
5 changed files with 110 additions and 41 deletions

View file

@ -49,6 +49,8 @@ var Gradient = this.Gradient = Base.extend({
},
equals: function(gradient) {
if (gradient.type != this.type)
return false;
if (this._stops.length == gradient._stops.length) {
for (var i = 0, l = this._stops.length; i < l; i++) {
if (!this._stops[i].equals(gradient._stops[i]))

View file

@ -26,7 +26,7 @@ var GradientColor = this.GradientColor = Color.extend({
},
clone: function() {
return new GradientColor(thisgradient, this._origin, this._destination,
return new GradientColor(this.gradient, this._origin, this._destination,
this._hilite);
},

View file

@ -35,8 +35,16 @@ var Raster = this.Raster = Item.extend({
},
clone: function() {
// TODO: Implement!
return this.base();
var image = this._image;
if (!image) {
// If the Raster contains a Canvas object, we need to create
// a new one and draw this raster's canvas on it.
image = CanvasProvider.getCanvas(this._size);
image.getContext('2d').drawImage(this._canvas, 0, 0);
}
var raster = new Raster(image);
raster.matrix = this.matrix.clone();
return raster;
},
/**

View file

@ -88,8 +88,24 @@ function compareGrayColors(color1, color2, message) {
(message || '') + ' gray');
}
function compareGradientColors(color1, color2) {
Base.each(['origin', 'destination', 'hilite'], function(key) {
equals(color1[key].toString(), color2[key].toString(),
'color1.' + key + '.toString() == color2.' + key + '.toString()');
});
equals(function() {
return color1.gradient.equals(color2.gradient);
}, true);
}
function cloneAndCompare(item) {
var copy = item.clone();
equals(function() {
return item._parent == copy._parent;
}, true);
equals(function() {
return item.nextSibling == copy;
}, true);
compareItems(item, copy);
// Remove the cloned item to restore the document:
copy.remove();
@ -104,14 +120,13 @@ function compareItems(item, item2) {
return item.id != item2.id;
}, true);
var itemProperties = ['opacity', 'locked', 'visible', 'blendMode', 'name',
'closed', 'selected'];
Base.each(itemProperties, function(key) {
Base.each(['opacity', 'locked', 'visible', 'blendMode', 'name', 'closed',
'selected'], function(key) {
equals(function() {
return item[key] == item2[key];
}, true);
}, true, 'item.' + key + ' == item2.' + key);
});
if (item._matrix) {
equals(function() {
return item._matrix != item2._matrix;
@ -133,30 +148,45 @@ function compareItems(item, item2) {
return item._clockwise == item2._clockwise;
}, true);
}
// Group specific
if (item instanceof Group) {
equals(function() {
return item._clipped == item2._clipped;
}, true);
}
// Layer specific
if (item instanceof Layer) {
equals(function() {
return item.project == item2.project;
}, true);
}
// PlacedSymbol specific
if (item instanceof PlacedSymbol) {
equals(function() {
return item.symbol == item2.symbol;
}, true);
}
// TODO: Raster specific
// Raster specific
if (item instanceof Raster) {
if (item._canvas) {
equals(function() {
return item._canvas != item2._canvas;
}, true);
}
if (item._image) {
equals(function() {
return item._image = item2._image;
}, true);
}
equals(function() {
return item._size.toString() == item2._size.toString();
}, true);
}
// TextItem specific:
if (item instanceof TextItem) {
equals(function() {
@ -166,52 +196,59 @@ function compareItems(item, item2) {
Base.each(characterStyleKeys, function(key) {
equals(function() {
return item.characterStyle[key] == item2.characterStyle[key];
}, true);
}, true,
'item.characterStyle.' + key + ' == item2.characterStyle.' + key);
});
var paragraphStyleKeys = ['justification'];
Base.each(paragraphStyleKeys, function(key) {
equals(function() {
return item.paragraphStyle[key] == item2.paragraphStyle[key];
}, true);
}, true,
'item.paragraphStyle.' + key + ' == item2.paragraphStyle.' + key);
});
}
// PointText specific:
if (item instanceof PointText) {
equals(item.point.toString(), item2.point.toString());
equals(function() {
return item.point.toString() == item2.point.toString();
}, true);
}
if (item._style) {
// Path Style
if (item.fillColor) {
// The fillColor should not point to the same color object:
equals(function() {
return item.fillColor != item2.fillColor;
}, true, 'The fillColor should not point to the same color object:');
if (item.fillColor instanceof GradientColor) {
// TODO!
} else {
equals(item.fillColor.toString(), item2.fillColor.toString());
Base.each(['fillColor', 'strokeColor'], function(key) {
if (item[key]) {
// The fillColor should not point to the same color object:
equals(function() {
return item[key] != item2[key];
}, true, 'The ' + key
+ ' should not point to the same color object:');
if (item[key] instanceof GradientColor) {
// TODO!
equals(function() {
return item[key].gradient == item2[key].gradient;
}, true,
'The ' + key
+ '.gradient should point to the same object:');
compareGradientColors(item[key], item2[key],
'Compare item.' + key + ' and item2.' + key);
} else {
equals(function() {
return item[key].toString() == item2[key].toString();
}, true,
'item.' + key + '.toString() == item2.' + key
+ '.toString()');
}
}
}
if (item.strokeColor) {
equals(function() {
return item.strokeColor != item2.strokeColor;
}, true, 'The strokeColor should not point to the same color object:');
if (item.strokeColor instanceof GradientColor) {
// TODO
} else {
equals(item.strokeColor.toString(), item2.strokeColor.toString());
}
}
});
Base.each(['strokeCap', 'strokeJoin', 'dashOffset', 'miterLimit',
'strokeOverprint', 'fillOverprint'], function(key) {
if (item[key]) {
equals(function() {
return item[key] == item2[key];
}, true);
}, true, 'item.' + key + ' == item2.' + key);
}
});

View file

@ -22,6 +22,17 @@ test('Path#clone()', function() {
cloneAndCompare(path);
});
test('Path#clone() with GradientColor', function() {
var colors = ['red', 'green', 'black'];
var gradient = new Gradient(colors, 'radial');
var color = new GradientColor(gradient, [0, 0], [20, 20], [10, 10]);
var proj = paper.project;
var path = new Path([10, 20], [30, 40]);
path.fillColor = color;
cloneAndCompare(path);
});
test('CompoundPath#clone()', function() {
var path1 = new Path.Rectangle([200, 200], [100, 100]);
var path2 = new Path.Rectangle([50, 50], [200, 200]);
@ -92,4 +103,15 @@ test('Symbol#clone()', function() {
equals(function() {
return paper.project.symbols.length == 2;
}, true);
});
test('Raster#clone()', function() {
var path = new Path.Circle([150, 150], 60);
path.style = {
fillColor: new RGBColor(0, 0, 1),
strokeColor: new RGBColor(0, 0, 1)
};
var raster = path.rasterize();
raster.rotate(20).translate(100);
cloneAndCompare(raster);
});