Merge remote-tracking branch 'origins/master' into parseSVGOpacity

This commit is contained in:
Kienz 2013-05-25 11:32:59 +02:00
commit 1ba6d1345e
8 changed files with 82 additions and 58 deletions

64
dist/all.js vendored
View file

@ -12957,7 +12957,8 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
"use strict";
var fabric = global.fabric || (global.fabric = { }),
toFixed = fabric.util.toFixed;
toFixed = fabric.util.toFixed,
min = fabric.util.array.min;
if (fabric.Polyline) {
fabric.warn('fabric.Polyline is already defined');
@ -12980,9 +12981,9 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
/**
* Constructor
* @param {Array} points array of points
* @param {Array} points Array of points
* @param {Object} [options] Options object
* @param {Boolean} skipOffset Whether points offsetting should be skipped
* @param {Boolean} [skipOffset] Whether points offsetting should be skipped
* @return {fabric.Polyline} thisArg
*/
initialize: function(points, options, skipOffset) {
@ -12994,7 +12995,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
/**
* @private
* @param {Boolean} skipOffset Whether points offsetting should be skipped
* @param {Boolean} [skipOffset] Whether points offsetting should be skipped
*/
_calcDimensions: function(skipOffset) {
return fabric.Polygon.prototype._calcDimensions.call(this, skipOffset);
@ -13002,8 +13003,8 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
/**
* Returns object representation of an instance
* @param {Array} propertiesToInclude
* @return {Object} object representation of an instance
* @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
* @return {Object} Object representation of an instance
*/
toObject: function(propertiesToInclude) {
return fabric.Polygon.prototype.toObject.call(this, propertiesToInclude);
@ -13075,7 +13076,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
/**
* Returns complexity of an instance
* @return {Number} complexity
* @return {Number} complexity of this instance
*/
complexity: function() {
return this.get('points').length;
@ -13094,7 +13095,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
* @static
* @param {SVGElement} element Element to parse
* @param {Object} [options] Options object
* @return {Object} instance of fabric.Polyline
* @return {fabric.Polyline} Instance of fabric.Polyline
*/
fabric.Polyline.fromElement = function(element, options) {
if (!element) {
@ -13103,12 +13104,17 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
options || (options = { });
var points = fabric.parsePointsAttribute(element.getAttribute('points')),
parsedAttributes = fabric.parseAttributes(element, fabric.Polyline.ATTRIBUTE_NAMES);
parsedAttributes = fabric.parseAttributes(element, fabric.Polyline.ATTRIBUTE_NAMES),
minX = min(points, 'x'),
minY = min(points, 'y');
minX = minX < 0 ? minX : 0;
minY = minX < 0 ? minY : 0;
for (var i = 0, len = points.length; i < len; i++) {
// normalize coordinates, according to containing box (dimensions of which are passed via `options`)
points[i].x -= (options.width / 2) || 0;
points[i].y -= (options.height / 2) || 0;
points[i].x -= (options.width / 2 + minX) || 0;
points[i].y -= (options.height / 2 + minY) || 0;
}
return new fabric.Polyline(points, fabric.util.object.extend(parsedAttributes, options), true);
@ -13117,8 +13123,8 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
/**
* Returns fabric.Polyline instance from an object representation
* @static
* @param {Object} [object] Object to create an instance from
* @return {fabric.Polyline}
* @param object {Object} object Object to create an instance from
* @return {fabric.Polyline} Instance of fabric.Polyline
*/
fabric.Polyline.fromObject = function(object) {
var points = object.points;
@ -13160,7 +13166,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
* Constructor
* @param {Array} points Array of points
* @param {Object} [options] Options object
* @param {Boolean} Whether points offsetting should be skipped
* @param {Boolean} [skipOffset] Whether points offsetting should be skipped
* @return {fabric.Polygon} thisArg
*/
initialize: function(points, options, skipOffset) {
@ -13172,6 +13178,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
/**
* @private
* @param {Boolean} [skipOffset] Whether points offsetting should be skipped
*/
_calcDimensions: function(skipOffset) {
@ -13189,8 +13196,8 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
if (skipOffset) return;
var halfWidth = this.width / 2,
halfHeight = this.height / 2;
var halfWidth = this.width / 2 + this.minX,
halfHeight = this.height / 2 + this.minY;
// change points to offset polygon into a bounding box
this.points.forEach(function(p) {
@ -13201,8 +13208,8 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
/**
* Returns object representation of an instance
* @param {Array} propertiesToInclude
* @return {Object} object representation of an instance
* @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
* @return {Object} Object representation of an instance
*/
toObject: function(propertiesToInclude) {
return extend(this.callSuper('toObject', propertiesToInclude), {
@ -13244,7 +13251,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
/**
* @private
* @param ctx {CanvasRenderingContext2D} context to render on
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
_render: function(ctx) {
var point;
@ -13263,7 +13270,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
/**
* @private
* @param ctx {CanvasRenderingContext2D} context to render on
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
_renderDashedStroke: function(ctx) {
var p1, p2;
@ -13298,7 +13305,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
* @static
* @param {SVGElement} element Element to parse
* @param {Object} [options] Options object
* @return {fabric.Polygon}
* @return {fabric.Polygon} Instance of fabric.Polygon
*/
fabric.Polygon.fromElement = function(element, options) {
if (!element) {
@ -13307,12 +13314,17 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
options || (options = { });
var points = fabric.parsePointsAttribute(element.getAttribute('points')),
parsedAttributes = fabric.parseAttributes(element, fabric.Polygon.ATTRIBUTE_NAMES);
parsedAttributes = fabric.parseAttributes(element, fabric.Polygon.ATTRIBUTE_NAMES),
minX = min(points, 'x'),
minY = min(points, 'y');
minX = minX < 0 ? minX : 0;
minY = minX < 0 ? minY : 0;
for (var i = 0, len = points.length; i < len; i++) {
// normalize coordinates, according to containing box (dimensions of which are passed via `options`)
points[i].x -= (options.width / 2) || 0;
points[i].y -= (options.height / 2) || 0;
points[i].x -= (options.width / 2 + minX) || 0;
points[i].y -= (options.height / 2 + minY) || 0;
}
return new fabric.Polygon(points, extend(parsedAttributes, options), true);
@ -13321,8 +13333,8 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
/**
* Returns fabric.Polygon instance from an object representation
* @static
* @param {Object} object Object to create an instance from
* @return {fabric.Polygon}
* @param object {Object} object Object to create an instance from
* @return {fabric.Polygon} Instance of fabric.Polygon
*/
fabric.Polygon.fromObject = function(object) {
return new fabric.Polygon(object.points, object, true);

4
dist/all.min.js vendored

File diff suppressed because one or more lines are too long

BIN
dist/all.min.js.gz vendored

Binary file not shown.

View file

@ -31,7 +31,7 @@
* Constructor
* @param {Array} points Array of points
* @param {Object} [options] Options object
* @param {Boolean} Whether points offsetting should be skipped
* @param {Boolean} [skipOffset] Whether points offsetting should be skipped
* @return {fabric.Polygon} thisArg
*/
initialize: function(points, options, skipOffset) {
@ -43,6 +43,7 @@
/**
* @private
* @param {Boolean} [skipOffset] Whether points offsetting should be skipped
*/
_calcDimensions: function(skipOffset) {
@ -60,8 +61,8 @@
if (skipOffset) return;
var halfWidth = this.width / 2,
halfHeight = this.height / 2;
var halfWidth = this.width / 2 + this.minX,
halfHeight = this.height / 2 + this.minY;
// change points to offset polygon into a bounding box
this.points.forEach(function(p) {
@ -72,8 +73,8 @@
/**
* Returns object representation of an instance
* @param {Array} propertiesToInclude
* @return {Object} object representation of an instance
* @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
* @return {Object} Object representation of an instance
*/
toObject: function(propertiesToInclude) {
return extend(this.callSuper('toObject', propertiesToInclude), {
@ -115,7 +116,7 @@
/**
* @private
* @param ctx {CanvasRenderingContext2D} context to render on
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
_render: function(ctx) {
var point;
@ -134,7 +135,7 @@
/**
* @private
* @param ctx {CanvasRenderingContext2D} context to render on
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
_renderDashedStroke: function(ctx) {
var p1, p2;
@ -169,7 +170,7 @@
* @static
* @param {SVGElement} element Element to parse
* @param {Object} [options] Options object
* @return {fabric.Polygon}
* @return {fabric.Polygon} Instance of fabric.Polygon
*/
fabric.Polygon.fromElement = function(element, options) {
if (!element) {
@ -178,12 +179,17 @@
options || (options = { });
var points = fabric.parsePointsAttribute(element.getAttribute('points')),
parsedAttributes = fabric.parseAttributes(element, fabric.Polygon.ATTRIBUTE_NAMES);
parsedAttributes = fabric.parseAttributes(element, fabric.Polygon.ATTRIBUTE_NAMES),
minX = min(points, 'x'),
minY = min(points, 'y');
minX = minX < 0 ? minX : 0;
minY = minX < 0 ? minY : 0;
for (var i = 0, len = points.length; i < len; i++) {
// normalize coordinates, according to containing box (dimensions of which are passed via `options`)
points[i].x -= (options.width / 2) || 0;
points[i].y -= (options.height / 2) || 0;
points[i].x -= (options.width / 2 + minX) || 0;
points[i].y -= (options.height / 2 + minY) || 0;
}
return new fabric.Polygon(points, extend(parsedAttributes, options), true);
@ -192,8 +198,8 @@
/**
* Returns fabric.Polygon instance from an object representation
* @static
* @param {Object} object Object to create an instance from
* @return {fabric.Polygon}
* @param object {Object} object Object to create an instance from
* @return {fabric.Polygon} Instance of fabric.Polygon
*/
fabric.Polygon.fromObject = function(object) {
return new fabric.Polygon(object.points, object, true);

View file

@ -3,7 +3,8 @@
"use strict";
var fabric = global.fabric || (global.fabric = { }),
toFixed = fabric.util.toFixed;
toFixed = fabric.util.toFixed,
min = fabric.util.array.min;
if (fabric.Polyline) {
fabric.warn('fabric.Polyline is already defined');
@ -26,9 +27,9 @@
/**
* Constructor
* @param {Array} points array of points
* @param {Array} points Array of points
* @param {Object} [options] Options object
* @param {Boolean} skipOffset Whether points offsetting should be skipped
* @param {Boolean} [skipOffset] Whether points offsetting should be skipped
* @return {fabric.Polyline} thisArg
*/
initialize: function(points, options, skipOffset) {
@ -40,7 +41,7 @@
/**
* @private
* @param {Boolean} skipOffset Whether points offsetting should be skipped
* @param {Boolean} [skipOffset] Whether points offsetting should be skipped
*/
_calcDimensions: function(skipOffset) {
return fabric.Polygon.prototype._calcDimensions.call(this, skipOffset);
@ -48,8 +49,8 @@
/**
* Returns object representation of an instance
* @param {Array} propertiesToInclude
* @return {Object} object representation of an instance
* @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
* @return {Object} Object representation of an instance
*/
toObject: function(propertiesToInclude) {
return fabric.Polygon.prototype.toObject.call(this, propertiesToInclude);
@ -121,7 +122,7 @@
/**
* Returns complexity of an instance
* @return {Number} complexity
* @return {Number} complexity of this instance
*/
complexity: function() {
return this.get('points').length;
@ -140,7 +141,7 @@
* @static
* @param {SVGElement} element Element to parse
* @param {Object} [options] Options object
* @return {Object} instance of fabric.Polyline
* @return {fabric.Polyline} Instance of fabric.Polyline
*/
fabric.Polyline.fromElement = function(element, options) {
if (!element) {
@ -149,12 +150,17 @@
options || (options = { });
var points = fabric.parsePointsAttribute(element.getAttribute('points')),
parsedAttributes = fabric.parseAttributes(element, fabric.Polyline.ATTRIBUTE_NAMES);
parsedAttributes = fabric.parseAttributes(element, fabric.Polyline.ATTRIBUTE_NAMES),
minX = min(points, 'x'),
minY = min(points, 'y');
minX = minX < 0 ? minX : 0;
minY = minX < 0 ? minY : 0;
for (var i = 0, len = points.length; i < len; i++) {
// normalize coordinates, according to containing box (dimensions of which are passed via `options`)
points[i].x -= (options.width / 2) || 0;
points[i].y -= (options.height / 2) || 0;
points[i].x -= (options.width / 2 + minX) || 0;
points[i].y -= (options.height / 2 + minY) || 0;
}
return new fabric.Polyline(points, fabric.util.object.extend(parsedAttributes, options), true);
@ -163,8 +169,8 @@
/**
* Returns fabric.Polyline instance from an object representation
* @static
* @param {Object} [object] Object to create an instance from
* @return {fabric.Polyline}
* @param object {Object} object Object to create an instance from
* @return {fabric.Polyline} Instance of fabric.Polyline
*/
fabric.Polyline.fromObject = function(object) {
var points = object.points;

View file

@ -511,7 +511,7 @@
equal(dataURL.substring(0, 21), 'data:image/png;base64');
try {
cObj.toDataURL({ format: 'jpeg' });
var dataURL = cObj.toDataURL({ format: 'jpeg' });
equal(dataURL.substring(0, 22), 'data:image/jpeg;base64');
}
catch(err) {
@ -737,7 +737,7 @@
equal(Math.round(object.get('left')), 1);
equal(Math.round(object.get('top')), 1);
equal(changedInvocations, 2);
//equal(changedInvocations, 2);
equal(completeInvocations, 1);
start();

View file

@ -51,7 +51,7 @@
ok(polygon instanceof fabric.Object);
equal(polygon.type, 'polygon');
deepEqual(polygon.get('points'), [ { x: 5, y: 7 }, { x: 15, y: 17 } ]);
deepEqual(polygon.get('points'), [ { x: -5, y: -5 }, { x: 5, y: 5 } ]);
});
test('complexity', function() {

View file

@ -51,7 +51,7 @@
ok(polyline instanceof fabric.Object);
equal(polyline.type, 'polyline');
deepEqual(polyline.get('points'), [ { x: 5, y: 7 }, { x: 15, y: 17 } ]);
deepEqual(polyline.get('points'), [ { x: -5, y: -5 }, { x: 5, y: 5 } ]);
});
test('complexity', function() {