2013-01-28 21:03:27 -05:00
|
|
|
/*
|
|
|
|
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
|
|
|
* http://paperjs.org/
|
|
|
|
*
|
2014-01-03 19:47:16 -05:00
|
|
|
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
|
|
|
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
2013-01-28 21:03:27 -05:00
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2013-04-09 19:46:20 -04:00
|
|
|
module('Style');
|
2011-02-16 16:11:26 -05:00
|
|
|
|
2011-05-29 08:42:49 -04:00
|
|
|
test('style defaults', function() {
|
|
|
|
var path = new Path();
|
2011-05-29 16:35:57 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.strokeWidth;
|
|
|
|
}, 1);
|
2011-05-29 08:42:49 -04:00
|
|
|
equals(function() {
|
2011-05-29 16:23:16 -04:00
|
|
|
return path.strokeCap;
|
|
|
|
}, 'butt');
|
2011-05-29 08:42:49 -04:00
|
|
|
equals(function() {
|
2011-05-29 16:23:16 -04:00
|
|
|
return path.strokeJoin;
|
|
|
|
}, 'miter');
|
2011-05-29 08:42:49 -04:00
|
|
|
equals(function() {
|
2011-05-29 16:23:16 -04:00
|
|
|
return path.miterLimit;
|
|
|
|
}, 10);
|
2011-05-29 08:42:49 -04:00
|
|
|
equals(function() {
|
2011-05-29 16:35:57 -04:00
|
|
|
return path.dashOffset;
|
|
|
|
}, 0);
|
|
|
|
equals(function() {
|
|
|
|
return path.dashArray + '';
|
|
|
|
}, [] + '');
|
2011-05-29 08:42:49 -04:00
|
|
|
});
|
|
|
|
|
2011-02-16 16:11:26 -05:00
|
|
|
test('currentStyle', function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
paper.project.currentStyle.fillColor = 'black';
|
2011-02-16 16:11:26 -05:00
|
|
|
var path = new Path();
|
2013-04-08 03:19:47 -04:00
|
|
|
compareColors(path.fillColor, 'black', 'path.fillColor');
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-16 08:33:15 -04:00
|
|
|
// When changing the current style of the project, the style of
|
|
|
|
// paths created using project.currentStyle should not change.
|
|
|
|
paper.project.currentStyle.fillColor = 'red';
|
2013-04-08 03:19:47 -04:00
|
|
|
compareColors(path.fillColor, 'black', 'path.fillColor');
|
2011-02-16 16:11:26 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('setting currentStyle to an object', function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
paper.project.currentStyle = {
|
2011-02-16 16:11:26 -05:00
|
|
|
fillColor: 'red',
|
|
|
|
strokeColor: 'green'
|
|
|
|
};
|
|
|
|
var path = new Path();
|
2013-04-08 03:19:47 -04:00
|
|
|
compareColors(path.fillColor, 'red', 'path.fillColor');
|
|
|
|
compareColors(path.strokeColor, 'green', 'path.strokeColor');
|
2011-02-16 16:11:26 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('setting path styles to an object', function() {
|
|
|
|
var path = new Path();
|
|
|
|
path.style = {
|
|
|
|
fillColor: 'red',
|
|
|
|
strokeColor: 'green'
|
|
|
|
};
|
2013-04-08 03:19:47 -04:00
|
|
|
compareColors(path.fillColor, 'red', 'path.fillColor');
|
|
|
|
compareColors(path.strokeColor, 'green', 'path.strokeColor');
|
2011-02-16 16:11:26 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('setting group styles to an object', function() {
|
|
|
|
var group = new Group();
|
|
|
|
var path = new Path();
|
2011-06-17 10:58:22 -04:00
|
|
|
group.addChild(path);
|
2011-02-16 16:11:26 -05:00
|
|
|
group.style = {
|
|
|
|
fillColor: 'red',
|
|
|
|
strokeColor: 'green'
|
|
|
|
};
|
2013-04-08 03:19:47 -04:00
|
|
|
compareColors(path.fillColor, 'red', 'path.fillColor');
|
|
|
|
compareColors(path.strokeColor, 'green', 'path.strokeColor');
|
2011-02-16 16:11:26 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('getting group styles', function() {
|
|
|
|
var group = new Group();
|
|
|
|
var path = new Path();
|
|
|
|
path.fillColor = 'red';
|
2011-06-17 10:58:22 -04:00
|
|
|
group.addChild(path);
|
2011-02-16 16:11:26 -05:00
|
|
|
|
2013-04-08 03:19:47 -04:00
|
|
|
compareColors(group.fillColor, 'red', 'group.fillColor');
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-02-16 16:11:26 -05:00
|
|
|
var secondPath = new Path();
|
|
|
|
secondPath.fillColor = 'black';
|
2011-06-17 10:58:22 -04:00
|
|
|
group.addChild(secondPath);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-02-16 16:11:26 -05:00
|
|
|
// the group now contains two paths with different fillColors and therefore
|
2011-05-05 08:37:57 -04:00
|
|
|
// should return undefined:
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return group.fillColor;
|
|
|
|
}, undefined);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-02-16 16:11:26 -05:00
|
|
|
//If we remove the first path, it should now return 'black':
|
|
|
|
group.children[0].remove();
|
2013-04-08 03:19:47 -04:00
|
|
|
compareColors(group.fillColor, 'black', 'group.fillColor');
|
2011-02-16 16:11:26 -05:00
|
|
|
});
|
|
|
|
|
2013-06-11 16:44:00 -04:00
|
|
|
test('getting group styles 2', function() {
|
2013-06-11 16:44:42 -04:00
|
|
|
var star = new Path.Circle({
|
2013-06-11 16:44:00 -04:00
|
|
|
center: [100, 100],
|
2013-06-11 16:44:42 -04:00
|
|
|
radius: 40,
|
2013-06-11 16:44:00 -04:00
|
|
|
fillColor: 'red'
|
|
|
|
});
|
|
|
|
|
|
|
|
var circle = new Path.Circle({
|
|
|
|
center: [100, 100],
|
|
|
|
radius: 25,
|
|
|
|
strokeColor: 'black'
|
|
|
|
});
|
|
|
|
// Create a group of the two items and clip it:
|
|
|
|
var group = new Group(circle, star);
|
|
|
|
|
|
|
|
equals(function() {
|
|
|
|
return group.fillColor;
|
|
|
|
}, undefined);
|
|
|
|
});
|
|
|
|
|
2011-02-16 16:11:26 -05:00
|
|
|
test('setting group styles', function() {
|
|
|
|
var group = new Group();
|
|
|
|
var path = new Path();
|
|
|
|
path.fillColor = 'red';
|
2011-06-17 10:58:22 -04:00
|
|
|
group.addChild(path);
|
2011-02-16 16:11:26 -05:00
|
|
|
|
|
|
|
var secondPath = new Path();
|
|
|
|
secondPath.fillColor = 'blue';
|
|
|
|
secondPath.strokeColor = 'red';
|
2011-06-17 10:58:22 -04:00
|
|
|
group.addChild(secondPath);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-02-16 16:11:26 -05:00
|
|
|
// Change the fill color of the group:
|
|
|
|
group.fillColor = 'black';
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-02-16 16:11:26 -05:00
|
|
|
// the paths contained in the group should now both have their fillColor
|
|
|
|
// set to black:
|
2013-04-08 03:19:47 -04:00
|
|
|
compareColors(path.fillColor, 'black', 'path.fillColor');
|
|
|
|
compareColors(secondPath.fillColor, 'black', 'secondPath.fillColor');
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-02-16 16:11:26 -05:00
|
|
|
// The second path still has its strokeColor set to red:
|
2013-04-08 03:19:47 -04:00
|
|
|
compareColors(secondPath.strokeColor, 'red', 'secondPath.strokeColor');
|
2011-02-16 16:11:26 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('setting group styles 2', function() {
|
|
|
|
var group = new Group();
|
|
|
|
var path = new Path();
|
2013-06-11 16:58:04 -04:00
|
|
|
path.strokeColor = 'red';
|
2011-02-16 16:11:26 -05:00
|
|
|
path.fillColor = 'red';
|
2011-06-17 10:58:22 -04:00
|
|
|
group.addChild(path);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2013-04-08 03:19:47 -04:00
|
|
|
compareColors(group.fillColor, 'red', 'group.fillColor');
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-02-16 16:11:26 -05:00
|
|
|
var secondPath = new Path();
|
|
|
|
secondPath.fillColor = 'blue';
|
|
|
|
secondPath.strokeColor = 'red';
|
2011-06-17 10:58:22 -04:00
|
|
|
group.addChild(secondPath);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2013-04-08 03:19:47 -04:00
|
|
|
compareColors(secondPath.fillColor, 'blue', 'secondPath.fillColor');
|
|
|
|
compareColors(secondPath.strokeColor, 'red', 'secondPath.strokeColor');
|
2011-02-16 16:11:26 -05:00
|
|
|
|
|
|
|
// By appending a path with a different fillcolor,
|
2011-05-05 08:11:40 -04:00
|
|
|
// the group's fillColor should return undefined:
|
2013-06-11 16:53:48 -04:00
|
|
|
equals(group.fillColor, undefined, 'group.fillColor');
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-02-16 16:11:26 -05:00
|
|
|
// But, both paths have a red strokeColor, so:
|
2013-04-08 03:19:47 -04:00
|
|
|
compareColors(group.strokeColor, 'red', 'group.strokeColor');
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-02-16 16:11:26 -05:00
|
|
|
// Change the fill color of the group's style:
|
|
|
|
group.style.fillColor = 'black';
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-02-16 16:11:26 -05:00
|
|
|
// the paths contained in the group should now both have their fillColor
|
|
|
|
// set to black:
|
2013-04-08 03:19:47 -04:00
|
|
|
compareColors(path.fillColor, 'black', 'path.fillColor');
|
|
|
|
compareColors(secondPath.fillColor, 'black', 'secondPath.fillColor');
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-02-16 16:11:26 -05:00
|
|
|
// The second path still has its strokeColor set to red:
|
2013-04-08 03:19:47 -04:00
|
|
|
compareColors(secondPath.strokeColor, 'red', 'secondPath.strokeColor');
|
2011-02-16 16:11:26 -05:00
|
|
|
});
|