polygon.class.js
2.17 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
(function(global) {
'use strict';
var fabric = global.fabric || (global.fabric = { });
if (fabric.Polygon) {
fabric.warn('fabric.Polygon is already defined');
return;
}
/**
* Polygon class
* @class fabric.Polygon
* @extends fabric.Polyline
* @see {@link fabric.Polygon#initialize} for constructor definition
*/
fabric.Polygon = fabric.util.createClass(fabric.Polyline, /** @lends fabric.Polygon.prototype */ {
/**
* Type of an object
* @type String
* @default
*/
type: 'polygon',
/**
* @private
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
_render: function(ctx) {
if (!this.commonRender(ctx)) {
return;
}
ctx.closePath();
this._renderPaintInOrder(ctx);
},
/**
* @private
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
_renderDashedStroke: function(ctx) {
this.callSuper('_renderDashedStroke', ctx);
ctx.closePath();
},
});
/* _FROM_SVG_START_ */
/**
* List of attribute names to account for when parsing SVG element (used by `fabric.Polygon.fromElement`)
* @static
* @memberOf fabric.Polygon
* @see: http://www.w3.org/TR/SVG/shapes.html#PolygonElement
*/
fabric.Polygon.ATTRIBUTE_NAMES = fabric.SHARED_ATTRIBUTES.concat();
/**
* Returns {@link fabric.Polygon} instance from an SVG element
* @static
* @memberOf fabric.Polygon
* @param {SVGElement} element Element to parse
* @param {Function} callback callback function invoked after parsing
* @param {Object} [options] Options object
*/
fabric.Polygon.fromElement = fabric.Polyline.fromElementGenerator('Polygon');
/* _FROM_SVG_END_ */
/**
* Returns fabric.Polygon instance from an object representation
* @static
* @memberOf fabric.Polygon
* @param {Object} object Object to create an instance from
* @param {Function} [callback] Callback to invoke when an fabric.Path instance is created
*/
fabric.Polygon.fromObject = function(object, callback) {
return fabric.Object._fromObject('Polygon', object, callback, 'points');
};
})(typeof exports !== 'undefined' ? exports : this);