Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove PathGroups for Groups. #3969

Merged
merged 10 commits into from
Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ var filesToInclude = [
'src/shapes/polyline.class.js',
'src/shapes/polygon.class.js',
'src/shapes/path.class.js',
'src/shapes/path_group.class.js',
'src/shapes/group.class.js',
'src/shapes/image.class.js',

Expand Down
2 changes: 2 additions & 0 deletions src/elements_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fabric.ElementsParser.prototype._createObject = function(klass, el, index) {
var obj = klass.fromElement(el, this.options);
this.resolveGradient(obj, 'fill');
this.resolveGradient(obj, 'stroke');
obj._removeTransformMatrix();
this.reviver && this.reviver(el, obj);
this.instances[index] = obj;
this.checkIfDone();
Expand All @@ -59,6 +60,7 @@ fabric.ElementsParser.prototype.createCallback = function(index, el) {
return function(obj) {
_this.resolveGradient(obj, 'fill');
_this.resolveGradient(obj, 'stroke');
obj._removeTransformMatrix();
_this.reviver && _this.reviver(el, obj);
_this.instances[index] = obj;
_this.checkIfDone();
Expand Down
31 changes: 9 additions & 22 deletions src/gradient.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,12 @@
return a.offset - b.offset;
});

if (!(object.group && object.group.type === 'path-group')) {
for (var prop in coords) {
if (prop === 'x1' || prop === 'x2') {
coords[prop] += this.offsetX - object.width / 2;
}
else if (prop === 'y1' || prop === 'y2') {
coords[prop] += this.offsetY - object.height / 2;
}
for (var prop in coords) {
if (prop === 'x1' || prop === 'x2') {
coords[prop] += this.offsetX - object.width / 2;
}
else if (prop === 'y1' || prop === 'y2') {
coords[prop] += this.offsetY - object.height / 2;
}
}

Expand Down Expand Up @@ -260,27 +258,15 @@
/**
* Returns an instance of CanvasGradient
* @param {CanvasRenderingContext2D} ctx Context to render on
* @param {Object} object
* @return {CanvasGradient}
*/
toLive: function(ctx, object) {
var gradient, prop, coords = fabric.util.object.clone(this.coords);
toLive: function(ctx) {
var gradient, coords = fabric.util.object.clone(this.coords);

if (!this.type) {
return;
}

if (object.group && object.group.type === 'path-group') {
for (prop in coords) {
if (prop === 'x1' || prop === 'x2') {
coords[prop] += -this.offsetX + object.width / 2;
}
else if (prop === 'y1' || prop === 'y2') {
coords[prop] += -this.offsetY + object.height / 2;
}
}
}

if (this.type === 'linear') {
gradient = ctx.createLinearGradient(
coords.x1, coords.y1, coords.x2, coords.y2);
Expand Down Expand Up @@ -391,6 +377,7 @@
if (gradientTransform || ellipseMatrix !== '') {
gradient.gradientTransform = fabric.parseTransformAttribute((gradientTransform || '') + ellipseMatrix);
}

return gradient;
},
/* _FROM_SVG_END_ */
Expand Down
10 changes: 3 additions & 7 deletions src/mixins/itext.svg_export.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@
* @private
*/
_getSVGLeftTopOffsets: function() {
var lineTop = this.getHeightOfLine(0),
textLeft = -this.width / 2,
textTop = -this.height / 2;

return {
textLeft: textLeft + (this.group && this.group.type === 'path-group' ? this.left : 0),
textTop: textTop + (this.group && this.group.type === 'path-group' ? -this.top : 0),
lineTop: lineTop
textLeft: -this.width / 2,
textTop: -this.height / 2,
lineTop: this.getHeightOfLine(0)
};
},

Expand Down
13 changes: 3 additions & 10 deletions src/mixins/object.svg_export.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,14 @@
* @return {String}
*/
getSvgTransform: function() {
if (this.group && this.group.type === 'path-group') {
return '';
}
var angle = this.getAngle(),
skewX = (this.getSkewX() % 360),
skewY = (this.getSkewY() % 360),
center = this.getCenterPoint(),

NUM_FRACTION_DIGITS = fabric.Object.NUM_FRACTION_DIGITS,

translatePart = this.type === 'path-group' ? '' : 'translate(' +
translatePart = 'translate(' +
toFixed(center.x, NUM_FRACTION_DIGITS) +
' ' +
toFixed(center.y, NUM_FRACTION_DIGITS) +
Expand All @@ -146,13 +143,9 @@

skewYPart = skewY !== 0 ? ' skewY(' + toFixed(skewY, NUM_FRACTION_DIGITS) + ')' : '',

addTranslateX = this.type === 'path-group' ? this.width : 0,

flipXPart = this.flipX ? ' matrix(-1 0 0 1 ' + addTranslateX + ' 0) ' : '',

addTranslateY = this.type === 'path-group' ? this.height : 0,
flipXPart = this.flipX ? ' matrix(-1 0 0 1 0 0) ' : '',

flipYPart = this.flipY ? ' matrix(1 0 0 -1 0 ' + addTranslateY + ')' : '';
flipYPart = this.flipY ? ' matrix(1 0 0 -1 0 0)' : '';

return [
translatePart, anglePart, scalePart, flipXPart, flipYPart, skewXPart, skewYPart
Expand Down
3 changes: 1 addition & 2 deletions src/mixins/object_origin.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prototype */ {

/**
* Translates the coordinates from origin to center coordinates (based on the object's dimensions)
* Translates the coordinates from a set of origin to another (based on the object's dimensions)
* @param {fabric.Point} point The point which corresponds to the originX and originY params
* @param {String} fromOriginX Horizontal origin: 'left', 'center' or 'right'
* @param {String} fromOriginY Vertical origin: 'top', 'center' or 'bottom'
Expand Down Expand Up @@ -172,7 +172,6 @@
setPositionByOrigin: function(pos, originX, originY) {
var center = this.translateToCenterPoint(pos, originX, originY),
position = this.translateToOriginPoint(center, this.originX, this.originY);

this.set('left', position.x);
this.set('top', position.y);
},
Expand Down
24 changes: 8 additions & 16 deletions src/shapes/circle.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@
angle = (this.endAngle - this.startAngle) % ( 2 * pi);

if (angle === 0) {
if (this.group && this.group.type === 'path-group') {
x = this.left + this.radius;
y = this.top + this.radius;
}
markup.push(
'<circle ', this.getSvgId(),
'cx="' + x + '" cy="' + y + '" ',
Expand Down Expand Up @@ -139,12 +135,11 @@
/**
* @private
* @param {CanvasRenderingContext2D} ctx context to render on
* @param {Boolean} [noTransform] When true, context is not transformed
*/
_render: function(ctx, noTransform) {
_render: function(ctx) {
ctx.beginPath();
ctx.arc(noTransform ? this.left + this.radius : 0,
noTransform ? this.top + this.radius : 0,
ctx.arc(0,
0,
this.radius,
this.startAngle,
this.endAngle, false);
Expand Down Expand Up @@ -205,14 +200,11 @@
throw new Error('value of `r` attribute is required and can not be negative');
}

parsedAttributes.left = parsedAttributes.left || 0;
parsedAttributes.top = parsedAttributes.top || 0;

var obj = new fabric.Circle(extend(parsedAttributes, options));

obj.left -= obj.radius;
obj.top -= obj.radius;
return obj;
parsedAttributes.left = (parsedAttributes.left || 0) - parsedAttributes.radius;
parsedAttributes.top = (parsedAttributes.top || 0) - parsedAttributes.radius;
parsedAttributes.originX = 'left';
parsedAttributes.originY = 'top';
return new fabric.Circle(extend(parsedAttributes, options));
};

/**
Expand Down
24 changes: 8 additions & 16 deletions src/shapes/ellipse.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@
*/
toSVG: function(reviver) {
var markup = this._createBaseSVGMarkup(), x = 0, y = 0;
if (this.group && this.group.type === 'path-group') {
x = this.left + this.rx;
y = this.top + this.ry;
}
markup.push(
'<ellipse ', this.getSvgId(),
'cx="', x, '" cy="', y, '" ',
Expand All @@ -139,15 +135,14 @@
/**
* @private
* @param {CanvasRenderingContext2D} ctx context to render on
* @param {Boolean} [noTransform] When true, context is not transformed
*/
_render: function(ctx, noTransform) {
_render: function(ctx) {
ctx.beginPath();
ctx.save();
ctx.transform(1, 0, 0, this.ry / this.rx, 0, 0);
ctx.arc(
noTransform ? this.left + this.rx : 0,
noTransform ? (this.top + this.ry) * this.rx / this.ry : 0,
0,
0,
this.rx,
0,
piBy2,
Expand Down Expand Up @@ -180,14 +175,11 @@

var parsedAttributes = fabric.parseAttributes(element, fabric.Ellipse.ATTRIBUTE_NAMES);

parsedAttributes.left = parsedAttributes.left || 0;
parsedAttributes.top = parsedAttributes.top || 0;

var ellipse = new fabric.Ellipse(extend(parsedAttributes, options));

ellipse.top -= ellipse.ry;
ellipse.left -= ellipse.rx;
return ellipse;
parsedAttributes.left = (parsedAttributes.left || 0) - parsedAttributes.rx;
parsedAttributes.top = (parsedAttributes.top || 0) - parsedAttributes.ry;
parsedAttributes.originX = 'left';
parsedAttributes.originY = 'top';
return new fabric.Ellipse(extend(parsedAttributes, options));
};
/* _FROM_SVG_END_ */

Expand Down
49 changes: 29 additions & 20 deletions src/shapes/group.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,20 @@
if (isAlreadyGrouped) {
// do not change coordinate of objects enclosed in a group,
// because objects coordinate system have been group coodinate system already.
this._updateObjectsCoords(true);
var object;
for (var i = this._objects.length; i--; ) {
object = this._objects[i];
object.__origHasControls = object.hasControls;
object.hasControls = false;
}
}
else {
this._calcBounds();
this._updateObjectsCoords();
var center = options && options.centerPoint;
// if coming from svg i do not want to calc bounds.
// i assume width and height are passed along options
center || this._calcBounds();
this._updateObjectsCoords(center);
delete options.centerPont;
this.callSuper('initialize', options);
}

Expand All @@ -101,28 +110,23 @@
* @private
* @param {Boolean} [skipCoordsChange] if true, coordinates of objects enclosed in a group do not change
*/
_updateObjectsCoords: function(skipCoordsChange) {
var center = this.getCenterPoint();
_updateObjectsCoords: function(center) {
var center = center || this.getCenterPoint();
for (var i = this._objects.length; i--; ){
this._updateObjectCoords(this._objects[i], center, skipCoordsChange);
this._updateObjectCoords(this._objects[i], center);
}
},

/**
* @private
* @param {Object} object
* @param {fabric.Point} center, current center of group.
* @param {Boolean} [skipCoordsChange] if true, coordinates of object dose not change
*/
_updateObjectCoords: function(object, center, skipCoordsChange) {
_updateObjectCoords: function(object, center) {
// do not display corners of objects enclosed in a group
object.__origHasControls = object.hasControls;
object.hasControls = false;

if (skipCoordsChange) {
return;
}

var objectLeft = object.getLeft(),
objectTop = object.getTop(),
ignoreZoom = true, skipAbsolute = true;
Expand Down Expand Up @@ -273,13 +277,19 @@
* @return {Object} object representation of an instance
*/
toDatalessObject: function(propertiesToInclude) {
var objsToObject = this.getObjects().map(function(obj) {
var originalDefaults = obj.includeDefaultValues;
obj.includeDefaultValues = obj.group.includeDefaultValues;
var _obj = obj.toDatalessObject(propertiesToInclude);
obj.includeDefaultValues = originalDefaults;
return _obj;
});
var objsToObject, sourcePath = this.sourcePath;
if (sourcePath) {
objsToObject = sourcePath;
}
else {
objsToObject = this.getObjects().map(function(obj) {
var originalDefaults = obj.includeDefaultValues;
obj.includeDefaultValues = obj.group.includeDefaultValues;
var _obj = obj.toDatalessObject(propertiesToInclude);
obj.includeDefaultValues = originalDefaults;
return _obj;
});
}
return extend(this.callSuper('toDatalessObject', propertiesToInclude), {
objects: objsToObject
});
Expand Down Expand Up @@ -344,7 +354,6 @@
/**
* Execute the drawing operation for an object on a specified context
* @param {CanvasRenderingContext2D} ctx Context to render on
* @param {Boolean} [noTransform] When true, context is not transformed
*/
drawObject: function(ctx) {
for (var i = 0, len = this._objects.length; i < len; i++) {
Expand Down
12 changes: 2 additions & 10 deletions src/shapes/image.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,6 @@
toSVG: function(reviver) {
var markup = this._createBaseSVGMarkup(), x = -this.width / 2, y = -this.height / 2,
preserveAspectRatio = 'none', filtered = true;
if (this.group && this.group.type === 'path-group') {
x = this.left;
y = this.top;
}
if (this.alignX !== 'none' && this.alignY !== 'none') {
preserveAspectRatio = 'x' + this.alignX + 'Y' + this.alignY + ' ' + this.meetOrSlice;
}
Expand Down Expand Up @@ -467,13 +463,9 @@
/**
* @private
* @param {CanvasRenderingContext2D} ctx Context to render on
* @param {Boolean} noTransform
*/
_render: function(ctx, noTransform) {
var x, y, imageMargins = this._findMargins(), elementToDraw;

x = (noTransform ? this.left : -this.width / 2);
y = (noTransform ? this.top : -this.height / 2);
_render: function(ctx) {
var x = -this.width / 2, y = -this.height / 2, imageMargins = this._findMargins(), elementToDraw;

if (this.meetOrSlice === 'slice') {
ctx.beginPath();
Expand Down
5 changes: 2 additions & 3 deletions src/shapes/itext.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,10 @@
/**
* @private
* @param {CanvasRenderingContext2D} ctx Context to render on
* @param {Boolean} noTransform
*/
render: function(ctx, noTransform) {
render: function(ctx) {
this.clearContextTop();
this.callSuper('render', ctx, noTransform);
this.callSuper('render', ctx);
// clear the cursorOffsetCache, so we ensure to calculate once per renderCursor
// the correct position but not at every cursor animation.
this.cursorOffsetCache = { };
Expand Down
Loading