2011-02-16 16:11:26 -05:00
|
|
|
module('Path Style');
|
|
|
|
|
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();
|
2011-11-10 13:16:34 -05:00
|
|
|
compareRgbColors(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';
|
2011-11-10 13:16:34 -05:00
|
|
|
compareRgbColors(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();
|
2011-11-10 13:16:34 -05:00
|
|
|
compareRgbColors(path.fillColor, 'red', 'path.fillColor');
|
|
|
|
compareRgbColors(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'
|
|
|
|
};
|
2011-11-10 13:16:34 -05:00
|
|
|
compareRgbColors(path.fillColor, 'red', 'path.fillColor');
|
|
|
|
compareRgbColors(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'
|
|
|
|
};
|
2011-11-10 13:16:34 -05:00
|
|
|
compareRgbColors(path.fillColor, 'red', 'path.fillColor');
|
|
|
|
compareRgbColors(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
|
|
|
|
2011-11-10 13:16:34 -05:00
|
|
|
compareRgbColors(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();
|
2011-11-10 13:16:34 -05:00
|
|
|
compareRgbColors(group.fillColor, 'black', 'group.fillColor');
|
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:
|
2011-11-10 13:16:34 -05:00
|
|
|
compareRgbColors(path.fillColor, 'black', 'path.fillColor');
|
|
|
|
compareRgbColors(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:
|
2011-11-10 13:16:34 -05:00
|
|
|
compareRgbColors(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();
|
|
|
|
path.fillColor = 'red';
|
2011-06-17 10:58:22 -04:00
|
|
|
group.addChild(path);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-11-10 13:16:34 -05:00
|
|
|
compareRgbColors(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
|
|
|
|
2011-11-10 13:16:34 -05:00
|
|
|
compareRgbColors(secondPath.fillColor, 'blue', 'secondPath.fillColor');
|
|
|
|
compareRgbColors(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:
|
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
|
|
|
// But, both paths have a red strokeColor, so:
|
2011-11-10 13:16:34 -05:00
|
|
|
compareRgbColors(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:
|
2011-11-10 13:16:34 -05:00
|
|
|
compareRgbColors(path.fillColor, 'black', 'path.fillColor');
|
|
|
|
compareRgbColors(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:
|
2011-11-10 13:16:34 -05:00
|
|
|
compareRgbColors(secondPath.strokeColor, 'red', 'secondPath.strokeColor');
|
2011-02-16 16:11:26 -05:00
|
|
|
});
|