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) { equals: function(gradient) {
if (gradient.type != this.type)
return false;
if (this._stops.length == gradient._stops.length) { if (this._stops.length == gradient._stops.length) {
for (var i = 0, l = this._stops.length; i < l; i++) { for (var i = 0, l = this._stops.length; i < l; i++) {
if (!this._stops[i].equals(gradient._stops[i])) if (!this._stops[i].equals(gradient._stops[i]))

View file

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

View file

@ -35,8 +35,16 @@ var Raster = this.Raster = Item.extend({
}, },
clone: function() { clone: function() {
// TODO: Implement! var image = this._image;
return this.base(); 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'); (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) { function cloneAndCompare(item) {
var copy = item.clone(); var copy = item.clone();
equals(function() {
return item._parent == copy._parent;
}, true);
equals(function() {
return item.nextSibling == copy;
}, true);
compareItems(item, copy); compareItems(item, copy);
// Remove the cloned item to restore the document: // Remove the cloned item to restore the document:
copy.remove(); copy.remove();
@ -104,14 +120,13 @@ function compareItems(item, item2) {
return item.id != item2.id; return item.id != item2.id;
}, true); }, true);
var itemProperties = ['opacity', 'locked', 'visible', 'blendMode', 'name', Base.each(['opacity', 'locked', 'visible', 'blendMode', 'name', 'closed',
'closed', 'selected']; 'selected'], function(key) {
Base.each(itemProperties, function(key) {
equals(function() { equals(function() {
return item[key] == item2[key]; return item[key] == item2[key];
}, true); }, true, 'item.' + key + ' == item2.' + key);
}); });
if (item._matrix) { if (item._matrix) {
equals(function() { equals(function() {
return item._matrix != item2._matrix; return item._matrix != item2._matrix;
@ -133,30 +148,45 @@ function compareItems(item, item2) {
return item._clockwise == item2._clockwise; return item._clockwise == item2._clockwise;
}, true); }, true);
} }
// Group specific // Group specific
if (item instanceof Group) { if (item instanceof Group) {
equals(function() { equals(function() {
return item._clipped == item2._clipped; return item._clipped == item2._clipped;
}, true); }, true);
} }
// Layer specific // Layer specific
if (item instanceof Layer) { if (item instanceof Layer) {
equals(function() { equals(function() {
return item.project == item2.project; return item.project == item2.project;
}, true); }, true);
} }
// PlacedSymbol specific // PlacedSymbol specific
if (item instanceof PlacedSymbol) { if (item instanceof PlacedSymbol) {
equals(function() { equals(function() {
return item.symbol == item2.symbol; return item.symbol == item2.symbol;
}, true); }, 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: // TextItem specific:
if (item instanceof TextItem) { if (item instanceof TextItem) {
equals(function() { equals(function() {
@ -166,52 +196,59 @@ function compareItems(item, item2) {
Base.each(characterStyleKeys, function(key) { Base.each(characterStyleKeys, function(key) {
equals(function() { equals(function() {
return item.characterStyle[key] == item2.characterStyle[key]; return item.characterStyle[key] == item2.characterStyle[key];
}, true); }, true,
'item.characterStyle.' + key + ' == item2.characterStyle.' + key);
}); });
var paragraphStyleKeys = ['justification']; var paragraphStyleKeys = ['justification'];
Base.each(paragraphStyleKeys, function(key) { Base.each(paragraphStyleKeys, function(key) {
equals(function() { equals(function() {
return item.paragraphStyle[key] == item2.paragraphStyle[key]; return item.paragraphStyle[key] == item2.paragraphStyle[key];
}, true); }, true,
'item.paragraphStyle.' + key + ' == item2.paragraphStyle.' + key);
}); });
} }
// PointText specific: // PointText specific:
if (item instanceof PointText) { if (item instanceof PointText) {
equals(item.point.toString(), item2.point.toString()); equals(function() {
return item.point.toString() == item2.point.toString();
}, true);
} }
if (item._style) { if (item._style) {
// Path Style // Path Style
if (item.fillColor) { Base.each(['fillColor', 'strokeColor'], function(key) {
// The fillColor should not point to the same color object: if (item[key]) {
equals(function() { // The fillColor should not point to the same color object:
return item.fillColor != item2.fillColor; equals(function() {
}, true, 'The fillColor should not point to the same color object:'); return item[key] != item2[key];
if (item.fillColor instanceof GradientColor) { }, true, 'The ' + key
// TODO! + ' should not point to the same color object:');
} else { if (item[key] instanceof GradientColor) {
equals(item.fillColor.toString(), item2.fillColor.toString()); // 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', Base.each(['strokeCap', 'strokeJoin', 'dashOffset', 'miterLimit',
'strokeOverprint', 'fillOverprint'], function(key) { 'strokeOverprint', 'fillOverprint'], function(key) {
if (item[key]) { if (item[key]) {
equals(function() { equals(function() {
return item[key] == item2[key]; return item[key] == item2[key];
}, true); }, true, 'item.' + key + ' == item2.' + key);
} }
}); });

View file

@ -22,6 +22,17 @@ test('Path#clone()', function() {
cloneAndCompare(path); 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() { test('CompoundPath#clone()', function() {
var path1 = new Path.Rectangle([200, 200], [100, 100]); var path1 = new Path.Rectangle([200, 200], [100, 100]);
var path2 = new Path.Rectangle([50, 50], [200, 200]); var path2 = new Path.Rectangle([50, 50], [200, 200]);
@ -92,4 +103,15 @@ test('Symbol#clone()', function() {
equals(function() { equals(function() {
return paper.project.symbols.length == 2; return paper.project.symbols.length == 2;
}, true); }, 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);
}); });