Skip to content

Commit 26efbdb

Browse files
committed
Implement argument reading for Gradient objects.
1 parent b9532f6 commit 26efbdb

3 files changed

Lines changed: 14 additions & 9 deletions

File tree

examples/JSON/Gradients.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
<script type="text/javascript" src="../../dist/paper.js"></script>
88
<script type="text/paperscript" canvas="canvas1">
99
var path = new Path.Circle(view.center, view.bounds.height * 0.4);
10-
var gradient = new Gradient(['yellow', 'red', 'black'], true);
11-
var from = path.position;
12-
var to = path.bounds.rightCenter;
13-
var gradientColor = new Color(gradient, from, to);
14-
path.fillColor = gradientColor;
10+
path.fillColor = {
11+
gradient: [['yellow', 'red', 'black'], true],
12+
origin: path.position,
13+
destination: path.bounds.rightCenter
14+
}
1515
path.strokeColor = 'black';
1616
window._json = project.exportJson();
1717
console.log(window._json);

src/color/Color.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ var Color = this.Color = Base.extend(new function() {
226226
parser = parsers[type][index] = name === 'gradient'
227227
? function(value) {
228228
var current = this._components[0];
229+
value = Gradient.read(
230+
Array.isArray(value) ? value : arguments,
231+
0, 0, false, true); // readNull
229232
if (current !== value) {
230233
if (current)
231234
current._removeOwner(this);

src/color/Gradient.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ var Gradient = this.Gradient = Base.extend(/** @lends Gradient# */{
2121
initialize: function(stops, radial) {
2222
// Define this Gradient's unique id.
2323
this._id = ++Base._uid;
24-
this.setStops(stops || ['white', 'black']);
25-
// Support old version of string type argument and new radial boolean.
26-
this.setRadial(typeof radial === 'string' && radial === 'radial'
27-
|| radial || false);
24+
if (!stops || !this._set(stops)) {
25+
this.setStops(stops || ['white', 'black']);
26+
// Support old string type argument and new radial boolean.
27+
this.setRadial(typeof radial === 'string' && radial === 'radial'
28+
|| radial || false);
29+
}
2830
},
2931

3032
_serialize: function(options, dictionary) {

0 commit comments

Comments
 (0)