fabric-rails 1.0.12.1 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/fabric/rails/version.rb +2 -2
- data/vendor/assets/javascripts/cufon.js +1226 -0
- data/vendor/assets/javascripts/event.js +20 -20
- data/vendor/assets/javascripts/excanvas.js +1464 -0
- data/vendor/assets/javascripts/fabric.js +56 -33
- data/vendor/assets/javascripts/fabric/HEADER.js +2 -4
- data/vendor/assets/javascripts/fabric/brushes/base_brush.class.js +96 -0
- data/vendor/assets/javascripts/fabric/brushes/circle_brush.class.js +99 -0
- data/vendor/assets/javascripts/fabric/brushes/pattern_brush.class.js +55 -0
- data/vendor/assets/javascripts/fabric/{freedrawing.class.js → brushes/pencil_brush.class.js} +73 -65
- data/vendor/assets/javascripts/fabric/brushes/spray_brush.class.js +157 -0
- data/vendor/assets/javascripts/fabric/canvas.class.js +154 -135
- data/vendor/assets/javascripts/fabric/color.class.js +195 -29
- data/vendor/assets/javascripts/fabric/filters/brightness_filter.class.js +70 -0
- data/vendor/assets/javascripts/fabric/filters/convolute_filter.class.js +122 -0
- data/vendor/assets/javascripts/fabric/filters/gradienttransparency_filter.class.js +69 -0
- data/vendor/assets/javascripts/fabric/filters/grayscale_filter.class.js +61 -0
- data/vendor/assets/javascripts/fabric/filters/invert_filter.class.js +57 -0
- data/vendor/assets/javascripts/fabric/filters/noise_filter.class.js +73 -0
- data/vendor/assets/javascripts/fabric/filters/pixelate_filter.class.js +98 -0
- data/vendor/assets/javascripts/fabric/filters/removewhite_filter.class.js +86 -0
- data/vendor/assets/javascripts/fabric/filters/sepia2_filter.class.js +61 -0
- data/vendor/assets/javascripts/fabric/filters/sepia_filter.class.js +58 -0
- data/vendor/assets/javascripts/fabric/filters/tint_filter.class.js +80 -0
- data/vendor/assets/javascripts/fabric/gradient.class.js +232 -80
- data/vendor/assets/javascripts/fabric/intersection.class.js +10 -28
- data/vendor/assets/javascripts/fabric/log.js +0 -2
- data/vendor/assets/javascripts/fabric/{canvas_animation.mixin.js → mixins/canvas_animation.mixin.js} +3 -6
- data/vendor/assets/javascripts/fabric/mixins/canvas_dataurl_exporter.mixin.js +137 -0
- data/vendor/assets/javascripts/fabric/{canvas_events.mixin.js → mixins/canvas_events.mixin.js} +97 -144
- data/vendor/assets/javascripts/fabric/{canvas_gestures.mixin.js → mixins/canvas_gestures.mixin.js} +4 -8
- data/vendor/assets/javascripts/fabric/{canvas_serialization.mixin.js → mixins/canvas_serialization.mixin.js} +19 -14
- data/vendor/assets/javascripts/fabric/mixins/collection.mixin.js +137 -0
- data/vendor/assets/javascripts/fabric/{object_geometry.mixin.js → mixins/object_geometry.mixin.js} +130 -47
- data/vendor/assets/javascripts/fabric/{object_interactivity.mixin.js → mixins/object_interactivity.mixin.js} +21 -102
- data/vendor/assets/javascripts/fabric/{object_origin.mixin.js → mixins/object_origin.mixin.js} +36 -26
- data/vendor/assets/javascripts/fabric/{object_straightening.mixin.js → mixins/object_straightening.mixin.js} +4 -9
- data/vendor/assets/javascripts/fabric/{observable.mixin.js → mixins/observable.mixin.js} +27 -35
- data/vendor/assets/javascripts/fabric/mixins/stateful.mixin.js +45 -0
- data/vendor/assets/javascripts/fabric/node.js +62 -26
- data/vendor/assets/javascripts/fabric/parser.js +181 -58
- data/vendor/assets/javascripts/fabric/pattern.class.js +43 -14
- data/vendor/assets/javascripts/fabric/point.class.js +4 -43
- data/vendor/assets/javascripts/fabric/shadow.class.js +19 -19
- data/vendor/assets/javascripts/fabric/{circle.class.js → shapes/circle.class.js} +32 -29
- data/vendor/assets/javascripts/fabric/{ellipse.class.js → shapes/ellipse.class.js} +45 -27
- data/vendor/assets/javascripts/fabric/{group.class.js → shapes/group.class.js} +67 -169
- data/vendor/assets/javascripts/fabric/{image.class.js → shapes/image.class.js} +134 -72
- data/vendor/assets/javascripts/fabric/{line.class.js → shapes/line.class.js} +67 -36
- data/vendor/assets/javascripts/fabric/{object.class.js → shapes/object.class.js} +394 -252
- data/vendor/assets/javascripts/fabric/{path.class.js → shapes/path.class.js} +89 -174
- data/vendor/assets/javascripts/fabric/{path_group.class.js → shapes/path_group.class.js} +12 -18
- data/vendor/assets/javascripts/fabric/{polygon.class.js → shapes/polygon.class.js} +64 -38
- data/vendor/assets/javascripts/fabric/{polyline.class.js → shapes/polyline.class.js} +64 -39
- data/vendor/assets/javascripts/fabric/{rect.class.js → shapes/rect.class.js} +78 -112
- data/vendor/assets/javascripts/fabric/{text.class.js → shapes/text.class.js} +264 -270
- data/vendor/assets/javascripts/fabric/shapes/text.cufon.js +79 -0
- data/vendor/assets/javascripts/fabric/{triangle.class.js → shapes/triangle.class.js} +46 -26
- data/vendor/assets/javascripts/fabric/static_canvas.class.js +134 -358
- data/vendor/assets/javascripts/fabric/util/anim_ease.js +2 -31
- data/vendor/assets/javascripts/fabric/util/dom_event.js +21 -7
- data/vendor/assets/javascripts/fabric/util/dom_misc.js +49 -39
- data/vendor/assets/javascripts/fabric/util/dom_request.js +1 -2
- data/vendor/assets/javascripts/fabric/util/dom_style.js +1 -2
- data/vendor/assets/javascripts/fabric/util/lang_array.js +19 -13
- data/vendor/assets/javascripts/fabric/util/lang_class.js +1 -2
- data/vendor/assets/javascripts/fabric/util/lang_function.js +3 -1
- data/vendor/assets/javascripts/fabric/util/lang_object.js +5 -5
- data/vendor/assets/javascripts/fabric/util/lang_string.js +7 -5
- data/vendor/assets/javascripts/fabric/util/misc.js +207 -42
- metadata +47 -29
- data/vendor/assets/javascripts/fabric/image_filters.js +0 -809
- data/vendor/assets/javascripts/fabric/scout.js +0 -45
- data/vendor/assets/javascripts/fabric/stateful.js +0 -88
@@ -16,28 +16,27 @@
|
|
16
16
|
|
17
17
|
/**
|
18
18
|
* Path group class
|
19
|
-
* @class PathGroup
|
19
|
+
* @class fabric.PathGroup
|
20
20
|
* @extends fabric.Path
|
21
21
|
*/
|
22
|
-
fabric.PathGroup = fabric.util.createClass(fabric.Path, /** @
|
22
|
+
fabric.PathGroup = fabric.util.createClass(fabric.Path, /** @lends fabric.PathGroup.prototype */ {
|
23
23
|
|
24
24
|
/**
|
25
25
|
* Type of an object
|
26
|
-
* @property
|
27
26
|
* @type String
|
27
|
+
* @default
|
28
28
|
*/
|
29
29
|
type: 'path-group',
|
30
30
|
|
31
31
|
/**
|
32
32
|
* Fill value
|
33
|
-
* @property
|
34
33
|
* @type String
|
34
|
+
* @default
|
35
35
|
*/
|
36
36
|
fill: '',
|
37
37
|
|
38
38
|
/**
|
39
39
|
* Constructor
|
40
|
-
* @method initialize
|
41
40
|
* @param {Array} paths
|
42
41
|
* @param {Object} [options] Options object
|
43
42
|
* @return {fabric.PathGroup} thisArg
|
@@ -61,10 +60,12 @@
|
|
61
60
|
|
62
61
|
/**
|
63
62
|
* Renders this group on a specified context
|
64
|
-
* @method render
|
65
63
|
* @param {CanvasRenderingContext2D} ctx Context to render this instance on
|
66
64
|
*/
|
67
65
|
render: function(ctx) {
|
66
|
+
// do not render if object is not visible
|
67
|
+
if (!this.visible) return;
|
68
|
+
|
68
69
|
ctx.save();
|
69
70
|
|
70
71
|
var m = this.transformMatrix;
|
@@ -75,9 +76,11 @@
|
|
75
76
|
this.transform(ctx);
|
76
77
|
|
77
78
|
this._setShadow(ctx);
|
79
|
+
this.clipTo && fabric.util.clipContext(this, ctx);
|
78
80
|
for (var i = 0, l = this.paths.length; i < l; ++i) {
|
79
81
|
this.paths[i].render(ctx, true);
|
80
82
|
}
|
83
|
+
this.clipTo && ctx.restore();
|
81
84
|
this._removeShadow(ctx);
|
82
85
|
|
83
86
|
if (this.active) {
|
@@ -89,7 +92,6 @@
|
|
89
92
|
|
90
93
|
/**
|
91
94
|
* Sets certain property to a certain value
|
92
|
-
* @method _set
|
93
95
|
* @param {String} prop
|
94
96
|
* @param {Any} value
|
95
97
|
* @return {fabric.PathGroup} thisArg
|
@@ -108,7 +110,6 @@
|
|
108
110
|
|
109
111
|
/**
|
110
112
|
* Returns object representation of this path group
|
111
|
-
* @method toObject
|
112
113
|
* @param {Array} [propertiesToInclude]
|
113
114
|
* @return {Object} object representation of an instance
|
114
115
|
*/
|
@@ -121,7 +122,6 @@
|
|
121
122
|
|
122
123
|
/**
|
123
124
|
* Returns dataless object representation of this path group
|
124
|
-
* @method toDatalessObject
|
125
125
|
* @param {Array} [propertiesToInclude]
|
126
126
|
* @return {Object} dataless object representation of an instance
|
127
127
|
*/
|
@@ -133,9 +133,9 @@
|
|
133
133
|
return o;
|
134
134
|
},
|
135
135
|
|
136
|
+
/* _TO_SVG_START_ */
|
136
137
|
/**
|
137
138
|
* Returns svg representation of an instance
|
138
|
-
* @method toSVG
|
139
139
|
* @return {String} svg representation of an instance
|
140
140
|
*/
|
141
141
|
toSVG: function() {
|
@@ -154,10 +154,10 @@
|
|
154
154
|
|
155
155
|
return markup.join('');
|
156
156
|
},
|
157
|
+
/* _TO_SVG_END_ */
|
157
158
|
|
158
159
|
/**
|
159
160
|
* Returns a string representation of this path group
|
160
|
-
* @method toString
|
161
161
|
* @return {String} string representation of an object
|
162
162
|
*/
|
163
163
|
toString: function() {
|
@@ -167,7 +167,6 @@
|
|
167
167
|
|
168
168
|
/**
|
169
169
|
* Returns true if all paths in this group are of same color
|
170
|
-
* @method isSameColor
|
171
170
|
* @return {Boolean} true if all paths are of the same color (`fill`)
|
172
171
|
*/
|
173
172
|
isSameColor: function() {
|
@@ -179,7 +178,6 @@
|
|
179
178
|
|
180
179
|
/**
|
181
180
|
* Returns number representation of object's complexity
|
182
|
-
* @method complexity
|
183
181
|
* @return {Number} complexity
|
184
182
|
*/
|
185
183
|
complexity: function() {
|
@@ -190,7 +188,6 @@
|
|
190
188
|
|
191
189
|
/**
|
192
190
|
* Makes path group grayscale
|
193
|
-
* @method toGrayscale
|
194
191
|
* @return {fabric.PathGroup} thisArg
|
195
192
|
*/
|
196
193
|
toGrayscale: function() {
|
@@ -203,7 +200,6 @@
|
|
203
200
|
|
204
201
|
/**
|
205
202
|
* Returns all paths in this path group
|
206
|
-
* @method getObjects
|
207
203
|
* @return {Array} array of path objects included in this path group
|
208
204
|
*/
|
209
205
|
getObjects: function() {
|
@@ -213,7 +209,6 @@
|
|
213
209
|
|
214
210
|
/**
|
215
211
|
* @private
|
216
|
-
* @method instantiatePaths
|
217
212
|
*/
|
218
213
|
function instantiatePaths(paths) {
|
219
214
|
for (var i = 0, len = paths.length; i < len; i++) {
|
@@ -228,7 +223,6 @@
|
|
228
223
|
/**
|
229
224
|
* Creates fabric.PathGroup instance from an object representation
|
230
225
|
* @static
|
231
|
-
* @method fabric.PathGroup.fromObject
|
232
226
|
* @param {Object} object
|
233
227
|
* @return {fabric.PathGroup}
|
234
228
|
*/
|
@@ -237,4 +231,4 @@
|
|
237
231
|
return new fabric.PathGroup(paths, object);
|
238
232
|
};
|
239
233
|
|
240
|
-
})(typeof exports !== 'undefined' ? exports : this);
|
234
|
+
})(typeof exports !== 'undefined' ? exports : this);
|
@@ -15,24 +15,23 @@
|
|
15
15
|
|
16
16
|
/**
|
17
17
|
* Polygon class
|
18
|
-
* @class Polygon
|
18
|
+
* @class fabric.Polygon
|
19
19
|
* @extends fabric.Object
|
20
20
|
*/
|
21
|
-
fabric.Polygon = fabric.util.createClass(fabric.Object, /** @
|
21
|
+
fabric.Polygon = fabric.util.createClass(fabric.Object, /** @lends fabric.Polygon.prototype */ {
|
22
22
|
|
23
23
|
/**
|
24
24
|
* Type of an object
|
25
|
-
* @property
|
26
25
|
* @type String
|
26
|
+
* @default
|
27
27
|
*/
|
28
28
|
type: 'polygon',
|
29
29
|
|
30
30
|
/**
|
31
31
|
* Constructor
|
32
|
-
* @method initialize
|
33
32
|
* @param {Array} points Array of points
|
34
33
|
* @param {Object} [options] Options object
|
35
|
-
* @param {Boolean} Whether points offsetting should be skipped
|
34
|
+
* @param {Boolean} [skipOffset] Whether points offsetting should be skipped
|
36
35
|
* @return {fabric.Polygon} thisArg
|
37
36
|
*/
|
38
37
|
initialize: function(points, options, skipOffset) {
|
@@ -44,7 +43,7 @@
|
|
44
43
|
|
45
44
|
/**
|
46
45
|
* @private
|
47
|
-
* @
|
46
|
+
* @param {Boolean} [skipOffset] Whether points offsetting should be skipped
|
48
47
|
*/
|
49
48
|
_calcDimensions: function(skipOffset) {
|
50
49
|
|
@@ -62,8 +61,8 @@
|
|
62
61
|
|
63
62
|
if (skipOffset) return;
|
64
63
|
|
65
|
-
var halfWidth = this.width / 2,
|
66
|
-
halfHeight = this.height / 2;
|
64
|
+
var halfWidth = this.width / 2 + this.minX,
|
65
|
+
halfHeight = this.height / 2 + this.minY;
|
67
66
|
|
68
67
|
// change points to offset polygon into a bounding box
|
69
68
|
this.points.forEach(function(p) {
|
@@ -74,9 +73,8 @@
|
|
74
73
|
|
75
74
|
/**
|
76
75
|
* Returns object representation of an instance
|
77
|
-
* @
|
78
|
-
* @
|
79
|
-
* @return {Object} object representation of an instance
|
76
|
+
* @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
|
77
|
+
* @return {Object} Object representation of an instance
|
80
78
|
*/
|
81
79
|
toObject: function(propertiesToInclude) {
|
82
80
|
return extend(this.callSuper('toObject', propertiesToInclude), {
|
@@ -84,30 +82,41 @@
|
|
84
82
|
});
|
85
83
|
},
|
86
84
|
|
85
|
+
/* _TO_SVG_START_ */
|
87
86
|
/**
|
88
87
|
* Returns svg representation of an instance
|
89
|
-
* @method toSVG
|
90
88
|
* @return {String} svg representation of an instance
|
91
89
|
*/
|
92
90
|
toSVG: function() {
|
93
|
-
var points = []
|
91
|
+
var points = [],
|
92
|
+
markup = [];
|
93
|
+
|
94
94
|
for (var i = 0, len = this.points.length; i < len; i++) {
|
95
95
|
points.push(toFixed(this.points[i].x, 2), ',', toFixed(this.points[i].y, 2), ' ');
|
96
96
|
}
|
97
97
|
|
98
|
-
|
98
|
+
if (this.fill && this.fill.toLive) {
|
99
|
+
markup.push(this.fill.toSVG(this, false));
|
100
|
+
}
|
101
|
+
if (this.stroke && this.stroke.toLive) {
|
102
|
+
markup.push(this.stroke.toSVG(this, false));
|
103
|
+
}
|
104
|
+
|
105
|
+
markup.push(
|
99
106
|
'<polygon ',
|
100
|
-
'points="', points.join(''),
|
101
|
-
'style="', this.getSvgStyles(),
|
102
|
-
'transform="', this.getSvgTransform(),
|
103
|
-
'/>'
|
104
|
-
|
107
|
+
'points="', points.join(''),
|
108
|
+
'" style="', this.getSvgStyles(),
|
109
|
+
'" transform="', this.getSvgTransform(),
|
110
|
+
'"/>'
|
111
|
+
);
|
112
|
+
|
113
|
+
return markup.join('');
|
105
114
|
},
|
115
|
+
/* _TO_SVG_END_ */
|
106
116
|
|
107
117
|
/**
|
108
118
|
* @private
|
109
|
-
* @
|
110
|
-
* @param ctx {CanvasRenderingContext2D} context to render on
|
119
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
111
120
|
*/
|
112
121
|
_render: function(ctx) {
|
113
122
|
var point;
|
@@ -117,19 +126,31 @@
|
|
117
126
|
point = this.points[i];
|
118
127
|
ctx.lineTo(point.x, point.y);
|
119
128
|
}
|
120
|
-
|
121
|
-
|
122
|
-
}
|
123
|
-
this._removeShadow(ctx);
|
124
|
-
if (this.stroke) {
|
129
|
+
this._renderFill(ctx);
|
130
|
+
if (this.stroke || this.strokeDashArray) {
|
125
131
|
ctx.closePath();
|
126
|
-
|
132
|
+
this._renderStroke(ctx);
|
133
|
+
}
|
134
|
+
},
|
135
|
+
|
136
|
+
/**
|
137
|
+
* @private
|
138
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
139
|
+
*/
|
140
|
+
_renderDashedStroke: function(ctx) {
|
141
|
+
var p1, p2;
|
142
|
+
|
143
|
+
ctx.beginPath();
|
144
|
+
for (var i = 0, len = this.points.length; i < len; i++) {
|
145
|
+
p1 = this.points[i];
|
146
|
+
p2 = this.points[i+1] || this.points[0];
|
147
|
+
fabric.util.drawDashedLine(ctx, p1.x, p1.y, p2.x, p2.y, this.strokeDashArray);
|
127
148
|
}
|
149
|
+
ctx.closePath();
|
128
150
|
},
|
129
151
|
|
130
152
|
/**
|
131
153
|
* Returns complexity of an instance
|
132
|
-
* @method complexity
|
133
154
|
* @return {Number} complexity of this instance
|
134
155
|
*/
|
135
156
|
complexity: function() {
|
@@ -137,20 +158,20 @@
|
|
137
158
|
}
|
138
159
|
});
|
139
160
|
|
161
|
+
/* _FROM_SVG_START_ */
|
140
162
|
/**
|
141
163
|
* List of attribute names to account for when parsing SVG element (used by `fabric.Polygon.fromElement`)
|
142
164
|
* @static
|
143
165
|
* @see: http://www.w3.org/TR/SVG/shapes.html#PolygonElement
|
144
166
|
*/
|
145
|
-
fabric.Polygon.ATTRIBUTE_NAMES =
|
167
|
+
fabric.Polygon.ATTRIBUTE_NAMES = fabric.SHARED_ATTRIBUTES.concat();
|
146
168
|
|
147
169
|
/**
|
148
170
|
* Returns {@link fabric.Polygon} instance from an SVG element
|
149
171
|
* @static
|
150
|
-
* @method fabric.Polygon.fromElement
|
151
172
|
* @param {SVGElement} element Element to parse
|
152
173
|
* @param {Object} [options] Options object
|
153
|
-
* @return {fabric.Polygon}
|
174
|
+
* @return {fabric.Polygon} Instance of fabric.Polygon
|
154
175
|
*/
|
155
176
|
fabric.Polygon.fromElement = function(element, options) {
|
156
177
|
if (!element) {
|
@@ -159,26 +180,31 @@
|
|
159
180
|
options || (options = { });
|
160
181
|
|
161
182
|
var points = fabric.parsePointsAttribute(element.getAttribute('points')),
|
162
|
-
parsedAttributes = fabric.parseAttributes(element, fabric.Polygon.ATTRIBUTE_NAMES)
|
183
|
+
parsedAttributes = fabric.parseAttributes(element, fabric.Polygon.ATTRIBUTE_NAMES),
|
184
|
+
minX = min(points, 'x'),
|
185
|
+
minY = min(points, 'y');
|
186
|
+
|
187
|
+
minX = minX < 0 ? minX : 0;
|
188
|
+
minY = minX < 0 ? minY : 0;
|
163
189
|
|
164
190
|
for (var i = 0, len = points.length; i < len; i++) {
|
165
191
|
// normalize coordinates, according to containing box (dimensions of which are passed via `options`)
|
166
|
-
points[i].x -= (options.width / 2) || 0;
|
167
|
-
points[i].y -= (options.height / 2) || 0;
|
192
|
+
points[i].x -= (options.width / 2 + minX) || 0;
|
193
|
+
points[i].y -= (options.height / 2 + minY) || 0;
|
168
194
|
}
|
169
195
|
|
170
196
|
return new fabric.Polygon(points, extend(parsedAttributes, options), true);
|
171
197
|
};
|
198
|
+
/* _FROM_SVG_END_ */
|
172
199
|
|
173
200
|
/**
|
174
201
|
* Returns fabric.Polygon instance from an object representation
|
175
202
|
* @static
|
176
|
-
* @
|
177
|
-
* @
|
178
|
-
* @return {fabric.Polygon}
|
203
|
+
* @param object {Object} object Object to create an instance from
|
204
|
+
* @return {fabric.Polygon} Instance of fabric.Polygon
|
179
205
|
*/
|
180
206
|
fabric.Polygon.fromObject = function(object) {
|
181
207
|
return new fabric.Polygon(object.points, object, true);
|
182
208
|
};
|
183
209
|
|
184
|
-
})(typeof exports !== 'undefined' ? exports : this);
|
210
|
+
})(typeof exports !== 'undefined' ? exports : this);
|
@@ -3,7 +3,8 @@
|
|
3
3
|
"use strict";
|
4
4
|
|
5
5
|
var fabric = global.fabric || (global.fabric = { }),
|
6
|
-
toFixed = fabric.util.toFixed
|
6
|
+
toFixed = fabric.util.toFixed,
|
7
|
+
min = fabric.util.array.min;
|
7
8
|
|
8
9
|
if (fabric.Polyline) {
|
9
10
|
fabric.warn('fabric.Polyline is already defined');
|
@@ -12,25 +13,24 @@
|
|
12
13
|
|
13
14
|
/**
|
14
15
|
* Polyline class
|
15
|
-
* @class Polyline
|
16
|
+
* @class fabric.Polyline
|
16
17
|
* @extends fabric.Object
|
17
18
|
*/
|
18
|
-
fabric.Polyline = fabric.util.createClass(fabric.Object, /** @
|
19
|
+
fabric.Polyline = fabric.util.createClass(fabric.Object, /** @lends fabric.Polyline.prototype */ {
|
19
20
|
|
20
21
|
/**
|
21
22
|
* Type of an object
|
22
|
-
* @property
|
23
23
|
* @type String
|
24
|
+
* @default
|
24
25
|
*/
|
25
26
|
type: 'polyline',
|
26
27
|
|
27
28
|
/**
|
28
29
|
* Constructor
|
29
|
-
* @
|
30
|
-
* @param {Array} points array of points
|
30
|
+
* @param {Array} points Array of points
|
31
31
|
* @param {Object} [options] Options object
|
32
|
-
* @param {Boolean} Whether points offsetting should be skipped
|
33
|
-
* @return {
|
32
|
+
* @param {Boolean} [skipOffset] Whether points offsetting should be skipped
|
33
|
+
* @return {fabric.Polyline} thisArg
|
34
34
|
*/
|
35
35
|
initialize: function(points, options, skipOffset) {
|
36
36
|
options = options || { };
|
@@ -41,7 +41,7 @@
|
|
41
41
|
|
42
42
|
/**
|
43
43
|
* @private
|
44
|
-
* @
|
44
|
+
* @param {Boolean} [skipOffset] Whether points offsetting should be skipped
|
45
45
|
*/
|
46
46
|
_calcDimensions: function(skipOffset) {
|
47
47
|
return fabric.Polygon.prototype._calcDimensions.call(this, skipOffset);
|
@@ -49,37 +49,47 @@
|
|
49
49
|
|
50
50
|
/**
|
51
51
|
* Returns object representation of an instance
|
52
|
-
* @
|
53
|
-
* @
|
54
|
-
* @return {Object} object representation of an instance
|
52
|
+
* @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
|
53
|
+
* @return {Object} Object representation of an instance
|
55
54
|
*/
|
56
55
|
toObject: function(propertiesToInclude) {
|
57
56
|
return fabric.Polygon.prototype.toObject.call(this, propertiesToInclude);
|
58
57
|
},
|
59
58
|
|
59
|
+
/* _TO_SVG_START_ */
|
60
60
|
/**
|
61
61
|
* Returns SVG representation of an instance
|
62
|
-
* @method toSVG
|
63
62
|
* @return {String} svg representation of an instance
|
64
63
|
*/
|
65
64
|
toSVG: function() {
|
66
|
-
var points = []
|
65
|
+
var points = [],
|
66
|
+
markup = [];
|
67
|
+
|
67
68
|
for (var i = 0, len = this.points.length; i < len; i++) {
|
68
69
|
points.push(toFixed(this.points[i].x, 2), ',', toFixed(this.points[i].y, 2), ' ');
|
69
70
|
}
|
70
71
|
|
71
|
-
|
72
|
+
if (this.fill && this.fill.toLive) {
|
73
|
+
markup.push(this.fill.toSVG(this, false));
|
74
|
+
}
|
75
|
+
if (this.stroke && this.stroke.toLive) {
|
76
|
+
markup.push(this.stroke.toSVG(this, false));
|
77
|
+
}
|
78
|
+
|
79
|
+
markup.push(
|
72
80
|
'<polyline ',
|
73
|
-
'points="', points.join(''),
|
74
|
-
'style="', this.getSvgStyles(),
|
75
|
-
'transform="', this.getSvgTransform(),
|
76
|
-
'/>'
|
77
|
-
|
81
|
+
'points="', points.join(''),
|
82
|
+
'" style="', this.getSvgStyles(),
|
83
|
+
'" transform="', this.getSvgTransform(),
|
84
|
+
'"/>'
|
85
|
+
);
|
86
|
+
|
87
|
+
return markup.join('');
|
78
88
|
},
|
89
|
+
/* _TO_SVG_END_ */
|
79
90
|
|
80
91
|
/**
|
81
92
|
* @private
|
82
|
-
* @method _render
|
83
93
|
* @param {CanvasRenderingContext2D} ctx Context to render on
|
84
94
|
*/
|
85
95
|
_render: function(ctx) {
|
@@ -90,39 +100,49 @@
|
|
90
100
|
point = this.points[i];
|
91
101
|
ctx.lineTo(point.x, point.y);
|
92
102
|
}
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
103
|
+
|
104
|
+
this._renderFill(ctx);
|
105
|
+
this._renderStroke(ctx);
|
106
|
+
},
|
107
|
+
|
108
|
+
/**
|
109
|
+
* @private
|
110
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
111
|
+
*/
|
112
|
+
_renderDashedStroke: function(ctx) {
|
113
|
+
var p1, p2;
|
114
|
+
|
115
|
+
ctx.beginPath();
|
116
|
+
for (var i = 0, len = this.points.length; i < len; i++) {
|
117
|
+
p1 = this.points[i];
|
118
|
+
p2 = this.points[i+1] || p1;
|
119
|
+
fabric.util.drawDashedLine(ctx, p1.x, p1.y, p2.x, p2.y, this.strokeDashArray);
|
99
120
|
}
|
100
121
|
},
|
101
122
|
|
102
123
|
/**
|
103
124
|
* Returns complexity of an instance
|
104
|
-
* @
|
105
|
-
* @return {Number} complexity
|
125
|
+
* @return {Number} complexity of this instance
|
106
126
|
*/
|
107
127
|
complexity: function() {
|
108
128
|
return this.get('points').length;
|
109
129
|
}
|
110
130
|
});
|
111
131
|
|
132
|
+
/* _FROM_SVG_START_ */
|
112
133
|
/**
|
113
134
|
* List of attribute names to account for when parsing SVG element (used by {@link fabric.Polyline.fromElement})
|
114
135
|
* @static
|
115
136
|
* @see: http://www.w3.org/TR/SVG/shapes.html#PolylineElement
|
116
137
|
*/
|
117
|
-
fabric.Polyline.ATTRIBUTE_NAMES =
|
138
|
+
fabric.Polyline.ATTRIBUTE_NAMES = fabric.SHARED_ATTRIBUTES.concat();
|
118
139
|
|
119
140
|
/**
|
120
141
|
* Returns fabric.Polyline instance from an SVG element
|
121
142
|
* @static
|
122
|
-
* @method fabric.Polyline.fromElement
|
123
143
|
* @param {SVGElement} element Element to parse
|
124
144
|
* @param {Object} [options] Options object
|
125
|
-
* @return {
|
145
|
+
* @return {fabric.Polyline} Instance of fabric.Polyline
|
126
146
|
*/
|
127
147
|
fabric.Polyline.fromElement = function(element, options) {
|
128
148
|
if (!element) {
|
@@ -131,27 +151,32 @@
|
|
131
151
|
options || (options = { });
|
132
152
|
|
133
153
|
var points = fabric.parsePointsAttribute(element.getAttribute('points')),
|
134
|
-
parsedAttributes = fabric.parseAttributes(element, fabric.Polyline.ATTRIBUTE_NAMES)
|
154
|
+
parsedAttributes = fabric.parseAttributes(element, fabric.Polyline.ATTRIBUTE_NAMES),
|
155
|
+
minX = min(points, 'x'),
|
156
|
+
minY = min(points, 'y');
|
157
|
+
|
158
|
+
minX = minX < 0 ? minX : 0;
|
159
|
+
minY = minX < 0 ? minY : 0;
|
135
160
|
|
136
161
|
for (var i = 0, len = points.length; i < len; i++) {
|
137
162
|
// normalize coordinates, according to containing box (dimensions of which are passed via `options`)
|
138
|
-
points[i].x -= (options.width / 2) || 0;
|
139
|
-
points[i].y -= (options.height / 2) || 0;
|
163
|
+
points[i].x -= (options.width / 2 + minX) || 0;
|
164
|
+
points[i].y -= (options.height / 2 + minY) || 0;
|
140
165
|
}
|
141
166
|
|
142
167
|
return new fabric.Polyline(points, fabric.util.object.extend(parsedAttributes, options), true);
|
143
168
|
};
|
169
|
+
/* _FROM_SVG_END_ */
|
144
170
|
|
145
171
|
/**
|
146
172
|
* Returns fabric.Polyline instance from an object representation
|
147
173
|
* @static
|
148
|
-
* @
|
149
|
-
* @
|
150
|
-
* @return {fabric.Polyline}
|
174
|
+
* @param object {Object} object Object to create an instance from
|
175
|
+
* @return {fabric.Polyline} Instance of fabric.Polyline
|
151
176
|
*/
|
152
177
|
fabric.Polyline.fromObject = function(object) {
|
153
178
|
var points = object.points;
|
154
179
|
return new fabric.Polyline(points, object, true);
|
155
180
|
};
|
156
181
|
|
157
|
-
})(typeof exports !== 'undefined' ? exports : this);
|
182
|
+
})(typeof exports !== 'undefined' ? exports : this);
|