fabric-rails 1.0.12 → 1.0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +16 -0
- data/README.md +1 -1
- data/lib/fabric/rails/version.rb +2 -2
- data/vendor/assets/javascripts/event.js +1909 -0
- data/vendor/assets/javascripts/fabric.js +64 -16464
- data/vendor/assets/javascripts/fabric/HEADER.js +31 -0
- data/vendor/assets/javascripts/fabric/canvas.class.js +1007 -0
- data/vendor/assets/javascripts/fabric/canvas_animation.mixin.js +113 -0
- data/vendor/assets/javascripts/fabric/canvas_events.mixin.js +482 -0
- data/vendor/assets/javascripts/fabric/canvas_gestures.mixin.js +79 -0
- data/vendor/assets/javascripts/fabric/canvas_serialization.mixin.js +311 -0
- data/vendor/assets/javascripts/fabric/circle.class.js +182 -0
- data/vendor/assets/javascripts/fabric/color.class.js +284 -0
- data/vendor/assets/javascripts/fabric/ellipse.class.js +169 -0
- data/vendor/assets/javascripts/fabric/freedrawing.class.js +256 -0
- data/vendor/assets/javascripts/fabric/gradient.class.js +211 -0
- data/vendor/assets/javascripts/fabric/group.class.js +556 -0
- data/vendor/assets/javascripts/fabric/image.class.js +418 -0
- data/vendor/assets/javascripts/fabric/image_filters.js +809 -0
- data/vendor/assets/javascripts/fabric/intersection.class.js +178 -0
- data/vendor/assets/javascripts/fabric/line.class.js +188 -0
- data/vendor/assets/javascripts/fabric/log.js +26 -0
- data/vendor/assets/javascripts/fabric/node.js +149 -0
- data/vendor/assets/javascripts/fabric/object.class.js +1068 -0
- data/vendor/assets/javascripts/fabric/object_geometry.mixin.js +308 -0
- data/vendor/assets/javascripts/fabric/object_interactivity.mixin.js +496 -0
- data/vendor/assets/javascripts/fabric/object_origin.mixin.js +207 -0
- data/vendor/assets/javascripts/fabric/object_straightening.mixin.js +94 -0
- data/vendor/assets/javascripts/fabric/observable.mixin.js +91 -0
- data/vendor/assets/javascripts/fabric/parser.js +750 -0
- data/vendor/assets/javascripts/fabric/path.class.js +794 -0
- data/vendor/assets/javascripts/fabric/path_group.class.js +240 -0
- data/vendor/assets/javascripts/fabric/pattern.class.js +69 -0
- data/vendor/assets/javascripts/fabric/point.class.js +327 -0
- data/vendor/assets/javascripts/fabric/polygon.class.js +184 -0
- data/vendor/assets/javascripts/fabric/polyline.class.js +157 -0
- data/vendor/assets/javascripts/fabric/rect.class.js +298 -0
- data/vendor/assets/javascripts/fabric/scout.js +45 -0
- data/vendor/assets/javascripts/fabric/shadow.class.js +70 -0
- data/vendor/assets/javascripts/fabric/stateful.js +88 -0
- data/vendor/assets/javascripts/fabric/static_canvas.class.js +1298 -0
- data/vendor/assets/javascripts/fabric/text.class.js +934 -0
- data/vendor/assets/javascripts/fabric/triangle.class.js +108 -0
- data/vendor/assets/javascripts/fabric/util/anim_ease.js +360 -0
- data/vendor/assets/javascripts/fabric/util/dom_event.js +237 -0
- data/vendor/assets/javascripts/fabric/util/dom_misc.js +245 -0
- data/vendor/assets/javascripts/fabric/util/dom_request.js +72 -0
- data/vendor/assets/javascripts/fabric/util/dom_style.js +71 -0
- data/vendor/assets/javascripts/fabric/util/lang_array.js +250 -0
- data/vendor/assets/javascripts/fabric/util/lang_class.js +97 -0
- data/vendor/assets/javascripts/fabric/util/lang_function.js +35 -0
- data/vendor/assets/javascripts/fabric/util/lang_object.js +34 -0
- data/vendor/assets/javascripts/fabric/util/lang_string.js +60 -0
- data/vendor/assets/javascripts/fabric/util/misc.js +406 -0
- data/vendor/assets/javascripts/json2.js +491 -0
- metadata +53 -2
@@ -0,0 +1,178 @@
|
|
1
|
+
(function(global) {
|
2
|
+
|
3
|
+
"use strict";
|
4
|
+
|
5
|
+
/* Adaptation of work of Kevin Lindsey (kevin@kevlindev.com) */
|
6
|
+
|
7
|
+
var fabric = global.fabric || (global.fabric = { });
|
8
|
+
|
9
|
+
if (fabric.Intersection) {
|
10
|
+
fabric.warn('fabric.Intersection is already defined');
|
11
|
+
return;
|
12
|
+
}
|
13
|
+
|
14
|
+
/**
|
15
|
+
* Intersection class
|
16
|
+
* @class Intersection
|
17
|
+
* @memberOf fabric
|
18
|
+
*/
|
19
|
+
function Intersection(status) {
|
20
|
+
if (arguments.length > 0) {
|
21
|
+
this.init(status);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
fabric.Intersection = Intersection;
|
26
|
+
|
27
|
+
fabric.Intersection.prototype = /** @scope fabric.Intersection.prototype */ {
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Constructor
|
31
|
+
* @method init
|
32
|
+
* @param {String} status
|
33
|
+
*/
|
34
|
+
init: function (status) {
|
35
|
+
this.status = status;
|
36
|
+
this.points = [];
|
37
|
+
},
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Appends a point to intersection
|
41
|
+
* @method appendPoint
|
42
|
+
* @param {fabric.Point} point
|
43
|
+
*/
|
44
|
+
appendPoint: function (point) {
|
45
|
+
this.points.push(point);
|
46
|
+
},
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Appends points to intersection
|
50
|
+
* @method appendPoints
|
51
|
+
* @param {Array} points
|
52
|
+
*/
|
53
|
+
appendPoints: function (points) {
|
54
|
+
this.points = this.points.concat(points);
|
55
|
+
}
|
56
|
+
};
|
57
|
+
|
58
|
+
/**
|
59
|
+
* Checks if one line intersects another
|
60
|
+
* @static
|
61
|
+
* @method intersectLineLine
|
62
|
+
* @param {fabric.Point} a1
|
63
|
+
* @param {fabric.Point} a2
|
64
|
+
* @param {fabric.Point} b1
|
65
|
+
* @param {fabric.Point} b2
|
66
|
+
* @return {fabric.Intersection}
|
67
|
+
*/
|
68
|
+
fabric.Intersection.intersectLineLine = function (a1, a2, b1, b2) {
|
69
|
+
var result,
|
70
|
+
ua_t = (b2.x - b1.x) * (a1.y - b1.y) - (b2.y - b1.y) * (a1.x - b1.x),
|
71
|
+
ub_t = (a2.x - a1.x) * (a1.y - b1.y) - (a2.y - a1.y) * (a1.x - b1.x),
|
72
|
+
u_b = (b2.y - b1.y) * (a2.x - a1.x) - (b2.x - b1.x) * (a2.y - a1.y);
|
73
|
+
if (u_b !== 0) {
|
74
|
+
var ua = ua_t / u_b,
|
75
|
+
ub = ub_t / u_b;
|
76
|
+
if (0 <= ua && ua <= 1 && 0 <= ub && ub <= 1) {
|
77
|
+
result = new Intersection("Intersection");
|
78
|
+
result.points.push(new fabric.Point(a1.x + ua * (a2.x - a1.x), a1.y + ua * (a2.y - a1.y)));
|
79
|
+
}
|
80
|
+
else {
|
81
|
+
result = new Intersection("No Intersection");
|
82
|
+
}
|
83
|
+
}
|
84
|
+
else {
|
85
|
+
if (ua_t === 0 || ub_t === 0) {
|
86
|
+
result = new Intersection("Coincident");
|
87
|
+
}
|
88
|
+
else {
|
89
|
+
result = new Intersection("Parallel");
|
90
|
+
}
|
91
|
+
}
|
92
|
+
return result;
|
93
|
+
};
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Checks if line intersects polygon
|
97
|
+
* @method intersectLinePolygon
|
98
|
+
* @static
|
99
|
+
* @param {fabric.Point} a1
|
100
|
+
* @param {fabric.Point} a2
|
101
|
+
* @param {Array} points
|
102
|
+
* @return {fabric.Intersection}
|
103
|
+
*/
|
104
|
+
fabric.Intersection.intersectLinePolygon = function(a1,a2,points){
|
105
|
+
var result = new Intersection("No Intersection"),
|
106
|
+
length = points.length;
|
107
|
+
|
108
|
+
for (var i = 0; i < length; i++) {
|
109
|
+
var b1 = points[i],
|
110
|
+
b2 = points[(i+1) % length],
|
111
|
+
inter = Intersection.intersectLineLine(a1, a2, b1, b2);
|
112
|
+
|
113
|
+
result.appendPoints(inter.points);
|
114
|
+
}
|
115
|
+
if (result.points.length > 0) {
|
116
|
+
result.status = "Intersection";
|
117
|
+
}
|
118
|
+
return result;
|
119
|
+
};
|
120
|
+
|
121
|
+
/**
|
122
|
+
* Checks if polygon intersects another polygon
|
123
|
+
* @method intersectPolygonPolygon
|
124
|
+
* @static
|
125
|
+
* @param {Array} points1
|
126
|
+
* @param {Array} points2
|
127
|
+
* @return {fabric.Intersection}
|
128
|
+
*/
|
129
|
+
fabric.Intersection.intersectPolygonPolygon = function (points1, points2) {
|
130
|
+
var result = new Intersection("No Intersection"),
|
131
|
+
length = points1.length;
|
132
|
+
|
133
|
+
for (var i = 0; i < length; i++) {
|
134
|
+
var a1 = points1[i],
|
135
|
+
a2 = points1[(i+1) % length],
|
136
|
+
inter = Intersection.intersectLinePolygon(a1, a2, points2);
|
137
|
+
|
138
|
+
result.appendPoints(inter.points);
|
139
|
+
}
|
140
|
+
if (result.points.length > 0) {
|
141
|
+
result.status = "Intersection";
|
142
|
+
}
|
143
|
+
return result;
|
144
|
+
};
|
145
|
+
|
146
|
+
/**
|
147
|
+
* Checks if polygon intersects rectangle
|
148
|
+
* @method intersectPolygonRectangle
|
149
|
+
|
150
|
+
* @static
|
151
|
+
* @param {Array} points
|
152
|
+
* @param {Number} r1
|
153
|
+
* @param {Number} r2
|
154
|
+
* @return {fabric.Intersection}
|
155
|
+
*/
|
156
|
+
fabric.Intersection.intersectPolygonRectangle = function (points, r1, r2) {
|
157
|
+
var min = r1.min(r2),
|
158
|
+
max = r1.max(r2),
|
159
|
+
topRight = new fabric.Point(max.x, min.y),
|
160
|
+
bottomLeft = new fabric.Point(min.x, max.y),
|
161
|
+
inter1 = Intersection.intersectLinePolygon(min, topRight, points),
|
162
|
+
inter2 = Intersection.intersectLinePolygon(topRight, max, points),
|
163
|
+
inter3 = Intersection.intersectLinePolygon(max, bottomLeft, points),
|
164
|
+
inter4 = Intersection.intersectLinePolygon(bottomLeft, min, points),
|
165
|
+
result = new Intersection("No Intersection");
|
166
|
+
|
167
|
+
result.appendPoints(inter1.points);
|
168
|
+
result.appendPoints(inter2.points);
|
169
|
+
result.appendPoints(inter3.points);
|
170
|
+
result.appendPoints(inter4.points);
|
171
|
+
|
172
|
+
if (result.points.length > 0) {
|
173
|
+
result.status = "Intersection";
|
174
|
+
}
|
175
|
+
return result;
|
176
|
+
};
|
177
|
+
|
178
|
+
})(typeof exports !== 'undefined' ? exports : this);
|
@@ -0,0 +1,188 @@
|
|
1
|
+
(function(global) {
|
2
|
+
|
3
|
+
"use strict";
|
4
|
+
|
5
|
+
var fabric = global.fabric || (global.fabric = { }),
|
6
|
+
extend = fabric.util.object.extend,
|
7
|
+
coordProps = { 'x1': 1, 'x2': 1, 'y1': 1, 'y2': 1 };
|
8
|
+
|
9
|
+
if (fabric.Line) {
|
10
|
+
fabric.warn('fabric.Line is already defined');
|
11
|
+
return;
|
12
|
+
}
|
13
|
+
|
14
|
+
/**
|
15
|
+
* Line class
|
16
|
+
* @class Line
|
17
|
+
* @extends fabric.Object
|
18
|
+
*/
|
19
|
+
fabric.Line = fabric.util.createClass(fabric.Object, /** @scope fabric.Line.prototype */ {
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Type of an object
|
23
|
+
* @property
|
24
|
+
* @type String
|
25
|
+
*/
|
26
|
+
type: 'line',
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Constructor
|
30
|
+
* @method initialize
|
31
|
+
* @param {Array} [points] Array of points
|
32
|
+
* @param {Object} [options] Options object
|
33
|
+
* @return {fabric.Line} thisArg
|
34
|
+
*/
|
35
|
+
initialize: function(points, options) {
|
36
|
+
options = options || { };
|
37
|
+
|
38
|
+
if (!points) {
|
39
|
+
points = [0, 0, 0, 0];
|
40
|
+
}
|
41
|
+
|
42
|
+
this.callSuper('initialize', options);
|
43
|
+
|
44
|
+
this.set('x1', points[0]);
|
45
|
+
this.set('y1', points[1]);
|
46
|
+
this.set('x2', points[2]);
|
47
|
+
this.set('y2', points[3]);
|
48
|
+
|
49
|
+
this._setWidthHeight(options);
|
50
|
+
},
|
51
|
+
|
52
|
+
/**
|
53
|
+
* @private
|
54
|
+
* @method _setWidthHeight
|
55
|
+
* @param {Object} [options] Options
|
56
|
+
*/
|
57
|
+
_setWidthHeight: function(options) {
|
58
|
+
options || (options = { });
|
59
|
+
|
60
|
+
this.set('width', (this.x2 - this.x1) || 1);
|
61
|
+
this.set('height', (this.y2 - this.y1) || 1);
|
62
|
+
|
63
|
+
this.set('left', 'left' in options ? options.left : (this.x1 + this.width / 2));
|
64
|
+
this.set('top', 'top' in options ? options.top : (this.y1 + this.height / 2));
|
65
|
+
},
|
66
|
+
|
67
|
+
/**
|
68
|
+
* @private
|
69
|
+
* @method _set
|
70
|
+
* @param {String} key
|
71
|
+
* @param {Any} value
|
72
|
+
*/
|
73
|
+
_set: function(key, value) {
|
74
|
+
this[key] = value;
|
75
|
+
if (key in coordProps) {
|
76
|
+
this._setWidthHeight();
|
77
|
+
}
|
78
|
+
return this;
|
79
|
+
},
|
80
|
+
|
81
|
+
/**
|
82
|
+
* @private
|
83
|
+
* @method _render
|
84
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
85
|
+
*/
|
86
|
+
_render: function(ctx) {
|
87
|
+
ctx.beginPath();
|
88
|
+
|
89
|
+
if (this.group) {
|
90
|
+
ctx.translate(-this.group.width/2 + this.left, -this.group.height / 2 + this.top);
|
91
|
+
}
|
92
|
+
|
93
|
+
// move from center (of virtual box) to its left/top corner
|
94
|
+
ctx.moveTo(this.width === 1 ? 0 : (-this.width / 2), this.height === 1 ? 0 : (-this.height / 2));
|
95
|
+
ctx.lineTo(this.width === 1 ? 0 : (this.width / 2), this.height === 1 ? 0 : (this.height / 2));
|
96
|
+
|
97
|
+
ctx.lineWidth = this.strokeWidth;
|
98
|
+
|
99
|
+
// TODO: test this
|
100
|
+
// make sure setting "fill" changes color of a line
|
101
|
+
// (by copying fillStyle to strokeStyle, since line is stroked, not filled)
|
102
|
+
var origStrokeStyle = ctx.strokeStyle;
|
103
|
+
ctx.strokeStyle = ctx.fillStyle;
|
104
|
+
ctx.stroke();
|
105
|
+
ctx.strokeStyle = origStrokeStyle;
|
106
|
+
},
|
107
|
+
|
108
|
+
/**
|
109
|
+
* Returns complexity of an instance
|
110
|
+
* @method complexity
|
111
|
+
* @return {Number} complexity
|
112
|
+
*/
|
113
|
+
complexity: function() {
|
114
|
+
return 1;
|
115
|
+
},
|
116
|
+
|
117
|
+
/**
|
118
|
+
* Returns object representation of an instance
|
119
|
+
* @methd toObject
|
120
|
+
* @param {Array} propertiesToInclude
|
121
|
+
* @return {Object} object representation of an instance
|
122
|
+
*/
|
123
|
+
toObject: function(propertiesToInclude) {
|
124
|
+
return extend(this.callSuper('toObject', propertiesToInclude), {
|
125
|
+
x1: this.get('x1'),
|
126
|
+
y1: this.get('y1'),
|
127
|
+
x2: this.get('x2'),
|
128
|
+
y2: this.get('y2')
|
129
|
+
});
|
130
|
+
},
|
131
|
+
|
132
|
+
/**
|
133
|
+
* Returns SVG representation of an instance
|
134
|
+
* @method toSVG
|
135
|
+
* @return {String} svg representation of an instance
|
136
|
+
*/
|
137
|
+
toSVG: function() {
|
138
|
+
return [
|
139
|
+
'<line ',
|
140
|
+
'x1="', this.get('x1'), '" ',
|
141
|
+
'y1="', this.get('y1'), '" ',
|
142
|
+
'x2="', this.get('x2'), '" ',
|
143
|
+
'y2="', this.get('y2'), '" ',
|
144
|
+
'style="', this.getSvgStyles(), '" ',
|
145
|
+
'/>'
|
146
|
+
].join('');
|
147
|
+
}
|
148
|
+
});
|
149
|
+
|
150
|
+
/**
|
151
|
+
* List of attribute names to account for when parsing SVG element (used by {@link fabric.Line.fromElement})
|
152
|
+
* @static
|
153
|
+
* @see http://www.w3.org/TR/SVG/shapes.html#LineElement
|
154
|
+
*/
|
155
|
+
fabric.Line.ATTRIBUTE_NAMES = 'x1 y1 x2 y2 stroke stroke-width transform'.split(' ');
|
156
|
+
|
157
|
+
/**
|
158
|
+
* Returns fabric.Line instance from an SVG element
|
159
|
+
* @static
|
160
|
+
* @method fabric.Line.fromElement
|
161
|
+
* @param {SVGElement} element Element to parse
|
162
|
+
* @param {Object} [options] Options object
|
163
|
+
* @return {fabric.Line} instance of fabric.Line
|
164
|
+
*/
|
165
|
+
fabric.Line.fromElement = function(element, options) {
|
166
|
+
var parsedAttributes = fabric.parseAttributes(element, fabric.Line.ATTRIBUTE_NAMES);
|
167
|
+
var points = [
|
168
|
+
parsedAttributes.x1 || 0,
|
169
|
+
parsedAttributes.y1 || 0,
|
170
|
+
parsedAttributes.x2 || 0,
|
171
|
+
parsedAttributes.y2 || 0
|
172
|
+
];
|
173
|
+
return new fabric.Line(points, extend(parsedAttributes, options));
|
174
|
+
};
|
175
|
+
|
176
|
+
/**
|
177
|
+
* Returns fabric.Line instance from an object representation
|
178
|
+
* @static
|
179
|
+
* @method fabric.Line.fromObject
|
180
|
+
* @param {Object} object Object to create an instance from
|
181
|
+
* @return {fabric.Line} instance of fabric.Line
|
182
|
+
*/
|
183
|
+
fabric.Line.fromObject = function(object) {
|
184
|
+
var points = [object.x1, object.y1, object.x2, object.y2];
|
185
|
+
return new fabric.Line(points, object);
|
186
|
+
};
|
187
|
+
|
188
|
+
})(typeof exports !== 'undefined' ? exports : this);
|
@@ -0,0 +1,26 @@
|
|
1
|
+
/**
|
2
|
+
* Wrapper around `console.log` (when available)
|
3
|
+
* @method log
|
4
|
+
* @param {Any} values Values to log
|
5
|
+
*/
|
6
|
+
fabric.log = function() { };
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Wrapper around `console.warn` (when available)
|
10
|
+
* @method warn
|
11
|
+
* @param {Any} Values to log as a warning
|
12
|
+
*/
|
13
|
+
fabric.warn = function() { };
|
14
|
+
|
15
|
+
if (typeof console !== 'undefined') {
|
16
|
+
if (typeof console.log !== 'undefined' && console.log.apply) {
|
17
|
+
fabric.log = function() {
|
18
|
+
return console.log.apply(console, arguments);
|
19
|
+
};
|
20
|
+
}
|
21
|
+
if (typeof console.warn !== 'undefined' && console.warn.apply) {
|
22
|
+
fabric.warn = function() {
|
23
|
+
return console.warn.apply(console, arguments);
|
24
|
+
};
|
25
|
+
}
|
26
|
+
}
|
@@ -0,0 +1,149 @@
|
|
1
|
+
(function() {
|
2
|
+
|
3
|
+
if (typeof document !== 'undefined' && typeof window !== 'undefined') {
|
4
|
+
return;
|
5
|
+
}
|
6
|
+
|
7
|
+
var DOMParser = new require('xmldom').DOMParser,
|
8
|
+
URL = require('url'),
|
9
|
+
HTTP = require('http'),
|
10
|
+
|
11
|
+
Canvas = require('canvas'),
|
12
|
+
Image = require('canvas').Image;
|
13
|
+
|
14
|
+
/** @private */
|
15
|
+
function request(url, encoding, callback) {
|
16
|
+
var oURL = URL.parse(url),
|
17
|
+
client = HTTP.createClient(oURL.port, oURL.hostname),
|
18
|
+
req = client.request('GET', oURL.pathname, { 'host': oURL.hostname });
|
19
|
+
|
20
|
+
client.addListener('error', function(err) {
|
21
|
+
if (err.errno === process.ECONNREFUSED) {
|
22
|
+
fabric.log('ECONNREFUSED: connection refused to ' + client.host + ':' + client.port);
|
23
|
+
}
|
24
|
+
else {
|
25
|
+
fabric.log(err.message);
|
26
|
+
}
|
27
|
+
});
|
28
|
+
|
29
|
+
req.end();
|
30
|
+
req.on('response', function (response) {
|
31
|
+
var body = "";
|
32
|
+
if (encoding) {
|
33
|
+
response.setEncoding(encoding);
|
34
|
+
}
|
35
|
+
response.on('end', function () {
|
36
|
+
callback(body);
|
37
|
+
});
|
38
|
+
response.on('data', function (chunk) {
|
39
|
+
if (response.statusCode === 200) {
|
40
|
+
body += chunk;
|
41
|
+
}
|
42
|
+
});
|
43
|
+
});
|
44
|
+
}
|
45
|
+
|
46
|
+
fabric.util.loadImage = function(url, callback, context) {
|
47
|
+
var img = new Image();
|
48
|
+
if (url && url.indexOf('data') === 0) {
|
49
|
+
img.src = img._src = url;
|
50
|
+
callback && callback.call(context, img);
|
51
|
+
}
|
52
|
+
else if (url) {
|
53
|
+
request(url, 'binary', function(body) {
|
54
|
+
img.src = new Buffer(body, 'binary');
|
55
|
+
// preserving original url, which seems to be lost in node-canvas
|
56
|
+
img._src = url;
|
57
|
+
callback && callback.call(context, img);
|
58
|
+
});
|
59
|
+
}
|
60
|
+
};
|
61
|
+
|
62
|
+
fabric.loadSVGFromURL = function(url, callback) {
|
63
|
+
url = url.replace(/^\n\s*/, '').replace(/\?.*$/, '').trim();
|
64
|
+
request(url, '', function(body) {
|
65
|
+
fabric.loadSVGFromString(body, callback);
|
66
|
+
});
|
67
|
+
};
|
68
|
+
|
69
|
+
fabric.loadSVGFromString = function(string, callback) {
|
70
|
+
var doc = new DOMParser().parseFromString(string);
|
71
|
+
fabric.parseSVGDocument(doc.documentElement, function(results, options) {
|
72
|
+
callback(results, options);
|
73
|
+
});
|
74
|
+
};
|
75
|
+
|
76
|
+
fabric.util.getScript = function(url, callback) {
|
77
|
+
request(url, '', function(body) {
|
78
|
+
eval(body);
|
79
|
+
callback && callback();
|
80
|
+
});
|
81
|
+
};
|
82
|
+
|
83
|
+
fabric.Image.fromObject = function(object, callback) {
|
84
|
+
fabric.util.loadImage(object.src, function(img) {
|
85
|
+
var oImg = new fabric.Image(img);
|
86
|
+
|
87
|
+
oImg._initConfig(object);
|
88
|
+
oImg._initFilters(object);
|
89
|
+
callback(oImg);
|
90
|
+
});
|
91
|
+
};
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Only available when running fabric on node.js
|
95
|
+
* @method createCanvasForNode
|
96
|
+
* @param width Canvas width
|
97
|
+
* @param height Canvas height
|
98
|
+
* @return {Object} wrapped canvas instance
|
99
|
+
*/
|
100
|
+
fabric.createCanvasForNode = function(width, height) {
|
101
|
+
|
102
|
+
var canvasEl = fabric.document.createElement('canvas'),
|
103
|
+
nodeCanvas = new Canvas(width || 600, height || 600);
|
104
|
+
|
105
|
+
// jsdom doesn't create style on canvas element, so here be temp. workaround
|
106
|
+
canvasEl.style = { };
|
107
|
+
|
108
|
+
canvasEl.width = nodeCanvas.width;
|
109
|
+
canvasEl.height = nodeCanvas.height;
|
110
|
+
|
111
|
+
var FabricCanvas = fabric.Canvas || fabric.StaticCanvas;
|
112
|
+
var fabricCanvas = new FabricCanvas(canvasEl);
|
113
|
+
fabricCanvas.contextContainer = nodeCanvas.getContext('2d');
|
114
|
+
fabricCanvas.nodeCanvas = nodeCanvas;
|
115
|
+
fabricCanvas.Font = Canvas.Font;
|
116
|
+
|
117
|
+
return fabricCanvas;
|
118
|
+
};
|
119
|
+
|
120
|
+
/** @ignore */
|
121
|
+
fabric.StaticCanvas.prototype.createPNGStream = function() {
|
122
|
+
return this.nodeCanvas.createPNGStream();
|
123
|
+
};
|
124
|
+
|
125
|
+
fabric.StaticCanvas.prototype.createJPEGStream = function(opts) {
|
126
|
+
return this.nodeCanvas.createJPEGStream(opts);
|
127
|
+
};
|
128
|
+
|
129
|
+
var origSetWidth = fabric.StaticCanvas.prototype.setWidth;
|
130
|
+
fabric.StaticCanvas.prototype.setWidth = function(width) {
|
131
|
+
origSetWidth.call(this);
|
132
|
+
this.nodeCanvas.width = width;
|
133
|
+
return this;
|
134
|
+
};
|
135
|
+
if (fabric.Canvas) {
|
136
|
+
fabric.Canvas.prototype.setWidth = fabric.StaticCanvas.prototype.setWidth;
|
137
|
+
}
|
138
|
+
|
139
|
+
var origSetHeight = fabric.StaticCanvas.prototype.setHeight;
|
140
|
+
fabric.StaticCanvas.prototype.setHeight = function(height) {
|
141
|
+
origSetHeight.call(this);
|
142
|
+
this.nodeCanvas.height = height;
|
143
|
+
return this;
|
144
|
+
};
|
145
|
+
if (fabric.Canvas) {
|
146
|
+
fabric.Canvas.prototype.setHeight = fabric.StaticCanvas.prototype.setHeight;
|
147
|
+
}
|
148
|
+
|
149
|
+
})();
|