2011-07-01 06:17:45 -04:00
|
|
|
/*
|
2013-01-28 21:03:27 -05:00
|
|
|
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
2011-07-01 06:17:45 -04:00
|
|
|
* http://paperjs.org/
|
|
|
|
*
|
2015-12-27 12:09:25 -05:00
|
|
|
* Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
|
2014-01-03 19:47:16 -05:00
|
|
|
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
2011-07-01 06:17:45 -04:00
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2011-05-26 04:19:51 -04:00
|
|
|
function cloneAndCompare(item) {
|
2014-08-16 13:24:54 -04:00
|
|
|
var copy = item.clone();
|
|
|
|
equals(function() {
|
|
|
|
return item.parent == copy.parent;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
// Cloned items appear above the original.
|
|
|
|
return item.nextSibling == copy;
|
|
|
|
}, true);
|
|
|
|
if (item.name) {
|
|
|
|
equals(function() {
|
|
|
|
return copy.parent.children[copy.name] == copy;
|
|
|
|
}, true);
|
|
|
|
}
|
2015-12-26 15:46:36 -05:00
|
|
|
equals(copy, item, 'item.clone()', { cloned: true });
|
2014-08-16 13:24:54 -04:00
|
|
|
// Remove the cloned item to restore the document:
|
|
|
|
copy.remove();
|
2011-05-26 04:19:51 -04:00
|
|
|
}
|
|
|
|
|
2011-05-20 13:40:07 -04:00
|
|
|
test('Path#clone()', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var path = new Path([10, 20], [30, 40]);
|
|
|
|
path.closed = true;
|
|
|
|
path.name = 'test';
|
|
|
|
path.style = {
|
|
|
|
strokeCap: 'round',
|
|
|
|
strokeJoin: 'round',
|
|
|
|
dashOffset: 10,
|
|
|
|
dashArray: [10, 2, 10],
|
|
|
|
fillColor: new Color(0, 0, 1),
|
|
|
|
strokeColor: new Color(0, 0, 1),
|
|
|
|
miterLimit: 5
|
|
|
|
};
|
|
|
|
path.clockwise = false;
|
|
|
|
path.opacity = 0.5;
|
|
|
|
path.locked = true;
|
|
|
|
path.visible = false;
|
|
|
|
path.blendMode = 'multiply';
|
|
|
|
path.clipMask = true;
|
|
|
|
path.selected = true;
|
|
|
|
cloneAndCompare(path);
|
2011-05-20 13:40:07 -04:00
|
|
|
});
|
|
|
|
|
2013-04-09 11:36:17 -04:00
|
|
|
test('Path#clone() with gradient Color', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var colors = ['red', 'green', 'black'];
|
|
|
|
var gradient = new Gradient(colors, true);
|
|
|
|
var color = new Color(gradient, [0, 0], [20, 20], [10, 10]);
|
|
|
|
var path = new Path([10, 20], [30, 40]);
|
|
|
|
path.fillColor = color;
|
|
|
|
cloneAndCompare(path);
|
2011-05-21 06:11:44 -04:00
|
|
|
});
|
|
|
|
|
2011-05-20 13:40:07 -04:00
|
|
|
test('CompoundPath#clone()', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var path1 = new Path.Rectangle([200, 200], [100, 100]);
|
|
|
|
var path2 = new Path.Rectangle([50, 50], [200, 200]);
|
|
|
|
var compound = new CompoundPath(path1, path2);
|
|
|
|
cloneAndCompare(compound);
|
2011-05-20 13:40:07 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Layer#clone()', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var path = new Path.Rectangle([200, 200], [100, 100]);
|
|
|
|
cloneAndCompare(paper.project.activeLayer);
|
2011-05-20 13:40:07 -04:00
|
|
|
});
|
|
|
|
|
2011-05-21 14:35:45 -04:00
|
|
|
test('Layer#clone() - check activeLayer', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var project = paper.project,
|
|
|
|
activeLayer = project.activeLayer,
|
|
|
|
layer = activeLayer.clone();
|
|
|
|
// The active layer should not change when cloning layers.
|
|
|
|
equals(function() {
|
|
|
|
return activeLayer == project.activeLayer;
|
|
|
|
}, true);
|
2011-05-21 14:35:45 -04:00
|
|
|
});
|
|
|
|
|
2011-05-20 13:40:07 -04:00
|
|
|
test('Group#clone()', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var path = new Path.Circle([150, 150], 60);
|
|
|
|
path.style = {
|
|
|
|
strokeCap: 'round',
|
|
|
|
strokeJoin: 'round',
|
|
|
|
dashOffset: 10,
|
|
|
|
dashArray: [10, 2, 10],
|
|
|
|
fillColor: new Color(0, 0, 1),
|
|
|
|
strokeColor: new Color(0, 0, 1),
|
|
|
|
miterLimit: 5
|
|
|
|
};
|
|
|
|
var secondPath = new Path.Circle([175, 175], 85);
|
|
|
|
var group = new Group([path, secondPath]);
|
|
|
|
cloneAndCompare(group);
|
2011-05-20 13:40:07 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('PointText#clone()', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var pointText = new PointText(new Point(50, 50));
|
|
|
|
pointText.content = 'test';
|
|
|
|
pointText.position = pointText.position.add(100);
|
|
|
|
pointText.style = {
|
|
|
|
fontFamily: 'serif',
|
|
|
|
fontSize: 20
|
|
|
|
};
|
|
|
|
pointText.justification = 'center';
|
|
|
|
cloneAndCompare(pointText);
|
2011-05-20 13:40:07 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('PlacedSymbol#clone()', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var path = new Path.Circle([150, 150], 60);
|
|
|
|
var symbol = new Symbol(path);
|
|
|
|
var placedSymbol = new PlacedSymbol(symbol);
|
|
|
|
placedSymbol.position = [100, 100];
|
|
|
|
placedSymbol.rotate(90);
|
|
|
|
cloneAndCompare(placedSymbol);
|
2011-05-20 13:40:07 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Symbol#clone()', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var path = new Path.Circle([150, 150], 60);
|
|
|
|
path.style = {
|
|
|
|
strokeCap: 'round',
|
|
|
|
strokeJoin: 'round',
|
|
|
|
dashOffset: 10,
|
|
|
|
dashArray: [10, 2, 10],
|
|
|
|
fillColor: new Color(0, 0, 1),
|
|
|
|
strokeColor: new Color(0, 0, 1),
|
|
|
|
miterLimit: 5
|
|
|
|
};
|
|
|
|
path.selected = true;
|
|
|
|
var symbol = new Symbol(path);
|
|
|
|
var copy = symbol.clone();
|
2014-12-28 12:10:53 -05:00
|
|
|
equals(symbol.definition, copy.definition, 'symbol.definition');
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
|
|
|
return symbol.project == copy.project;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return paper.project.symbols.length == 2;
|
|
|
|
}, true);
|
2011-05-21 06:50:36 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Raster#clone()', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var path = new Path.Circle([150, 150], 60);
|
|
|
|
path.style = {
|
|
|
|
fillColor: new Color(0, 0, 1),
|
|
|
|
strokeColor: new Color(0, 0, 1)
|
|
|
|
};
|
|
|
|
var raster = path.rasterize(72);
|
|
|
|
raster.opacity = 0.5;
|
|
|
|
raster.locked = true;
|
|
|
|
raster.visible = false;
|
|
|
|
raster.blendMode = 'multiply';
|
|
|
|
raster.rotate(20).translate(100);
|
|
|
|
cloneAndCompare(raster);
|
2011-05-21 14:35:13 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Group with clipmask', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var path = new Path.Circle([100, 100], 30),
|
|
|
|
path2 = new Path.Circle([100, 100], 20),
|
|
|
|
group = new Group([path, path2]);
|
|
|
|
group.clipped = true;
|
|
|
|
cloneAndCompare(group);
|
2013-07-19 21:10:58 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Item#clone() Hierarchy', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var path1 = new Path.Circle([150, 150], 60);
|
|
|
|
var path2 = new Path.Circle([150, 150], 60);
|
|
|
|
var clone = path1.clone();
|
|
|
|
equals(function() {
|
|
|
|
return path2.isAbove(path1);
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return clone.isAbove(path1);
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return clone.isBelow(path2);
|
|
|
|
}, true);
|
2013-07-19 21:10:58 -04:00
|
|
|
});
|