forked from paperjs/paper.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStyle.js
More file actions
180 lines (151 loc) · 4.82 KB
/
Copy pathStyle.js
File metadata and controls
180 lines (151 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
module('Style');
test('style defaults', function() {
var path = new Path();
equals(function() {
return path.strokeWidth;
}, 1);
equals(function() {
return path.strokeCap;
}, 'butt');
equals(function() {
return path.strokeJoin;
}, 'miter');
equals(function() {
return path.miterLimit;
}, 10);
equals(function() {
return path.dashOffset;
}, 0);
equals(function() {
return path.dashArray + '';
}, [] + '');
});
test('currentStyle', function() {
paper.project.currentStyle.fillColor = 'black';
var path = new Path();
compareColors(path.fillColor, 'black', 'path.fillColor');
// When changing the current style of the project, the style of
// paths created using project.currentStyle should not change.
paper.project.currentStyle.fillColor = 'red';
compareColors(path.fillColor, 'black', 'path.fillColor');
});
test('setting currentStyle to an object', function() {
paper.project.currentStyle = {
fillColor: 'red',
strokeColor: 'green'
};
var path = new Path();
compareColors(path.fillColor, 'red', 'path.fillColor');
compareColors(path.strokeColor, 'green', 'path.strokeColor');
});
test('setting path styles to an object', function() {
var path = new Path();
path.style = {
fillColor: 'red',
strokeColor: 'green'
};
compareColors(path.fillColor, 'red', 'path.fillColor');
compareColors(path.strokeColor, 'green', 'path.strokeColor');
});
test('setting group styles to an object', function() {
var group = new Group();
var path = new Path();
group.addChild(path);
group.style = {
fillColor: 'red',
strokeColor: 'green'
};
compareColors(path.fillColor, 'red', 'path.fillColor');
compareColors(path.strokeColor, 'green', 'path.strokeColor');
});
test('getting group styles', function() {
var group = new Group();
var path = new Path();
path.fillColor = 'red';
group.addChild(path);
compareColors(group.fillColor, 'red', 'group.fillColor');
var secondPath = new Path();
secondPath.fillColor = 'black';
group.addChild(secondPath);
// the group now contains two paths with different fillColors and therefore
// should return undefined:
equals(function() {
return group.fillColor;
}, undefined);
//If we remove the first path, it should now return 'black':
group.children[0].remove();
compareColors(group.fillColor, 'black', 'group.fillColor');
});
test('getting group styles 2', function() {
var star = new Path.Circle({
center: [100, 100],
radius: 40,
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);
});
test('setting group styles', function() {
var group = new Group();
var path = new Path();
path.fillColor = 'red';
group.addChild(path);
var secondPath = new Path();
secondPath.fillColor = 'blue';
secondPath.strokeColor = 'red';
group.addChild(secondPath);
// Change the fill color of the group:
group.fillColor = 'black';
// the paths contained in the group should now both have their fillColor
// set to black:
compareColors(path.fillColor, 'black', 'path.fillColor');
compareColors(secondPath.fillColor, 'black', 'secondPath.fillColor');
// The second path still has its strokeColor set to red:
compareColors(secondPath.strokeColor, 'red', 'secondPath.strokeColor');
});
test('setting group styles 2', function() {
var group = new Group();
var path = new Path();
path.strokeColor = 'red';
path.fillColor = 'red';
group.addChild(path);
compareColors(group.fillColor, 'red', 'group.fillColor');
var secondPath = new Path();
secondPath.fillColor = 'blue';
secondPath.strokeColor = 'red';
group.addChild(secondPath);
compareColors(secondPath.fillColor, 'blue', 'secondPath.fillColor');
compareColors(secondPath.strokeColor, 'red', 'secondPath.strokeColor');
// By appending a path with a different fillcolor,
// the group's fillColor should return undefined:
equals(group.fillColor, undefined, 'group.fillColor');
// But, both paths have a red strokeColor, so:
compareColors(group.strokeColor, 'red', 'group.strokeColor');
// Change the fill color of the group's style:
group.style.fillColor = 'black';
// the paths contained in the group should now both have their fillColor
// set to black:
compareColors(path.fillColor, 'black', 'path.fillColor');
compareColors(secondPath.fillColor, 'black', 'secondPath.fillColor');
// The second path still has its strokeColor set to red:
compareColors(secondPath.strokeColor, 'red', 'secondPath.strokeColor');
});