Skip to content

Commit

Permalink
v241 (#5281)
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored Sep 29, 2018
1 parent dd76fa2 commit cd20632
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 46 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## [2.4.1]
- Fix: Avoid enterEditing if another object is the activeObject [#5261](https://github.com/fabricjs/fabric.js/pull/5261)
- Fix: clipPath enliving for Image fromObject [#5279](https://github.com/fabricjs/fabric.js/pull/5279)
- Fix: toDataURL and canvas clipPath [#5278](https://github.com/fabricjs/fabric.js/pull/5278)
- Fix: early return if no xml is available [#5263](https://github.com/fabricjs/fabric.js/pull/5263)
- Fix: clipPath svg parsing in nodejs [#5262](https://github.com/fabricjs/fabric.js/pull/5262)
- Fix: Avoid running selection logic on mouse up [#5259](https://github.com/fabricjs/fabric.js/pull/5259)
- Fix: fix font size parsing on SVG [#5258](https://github.com/fabricjs/fabric.js/pull/5258)
- Fix: Avoid extra renders on mouseUp/Down [#5256](https://github.com/fabricjs/fabric.js/pull/5256)

## [2.4.0]
- Add: Add clipPath support to canvas and svg import/export. Low compatibility yet.

Expand Down
2 changes: 1 addition & 1 deletion HEADER.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! Fabric.js Copyright 2008-2015, Printio (Juriy Zaytsev, Maxim Chernyak) */

var fabric = fabric || { version: '2.4.0' };
var fabric = fabric || { version: '2.4.1' };
if (typeof exports !== 'undefined') {
exports.fabric = fabric;
}
Expand Down
102 changes: 59 additions & 43 deletions dist/fabric.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* build: `node build.js modules=ALL exclude=gestures,accessors requirejs minifier=uglifyjs` */
/*! Fabric.js Copyright 2008-2015, Printio (Juriy Zaytsev, Maxim Chernyak) */

var fabric = fabric || { version: '2.4.0' };
var fabric = fabric || { version: '2.4.1' };
if (typeof exports !== 'undefined') {
exports.fabric = fabric;
}
Expand Down Expand Up @@ -4056,7 +4056,8 @@ if (typeof console !== 'undefined') {
descendants.filter(function(el) {
return el.nodeName.replace('svg:', '') === 'clipPath';
}).forEach(function(el) {
clipPaths[el.id] = fabric.util.toArray(el.getElementsByTagName('*')).filter(function(el) {
var id = el.getAttribute('id');
clipPaths[id] = fabric.util.toArray(el.getElementsByTagName('*')).filter(function(el) {
return fabric.svgValidTagNamesRegEx.test(el.nodeName.replace('svg:', ''));
});
});
Expand Down Expand Up @@ -4185,8 +4186,6 @@ if (typeof console !== 'undefined') {
if (element.parentNode && fabric.svgValidParentsRegEx.test(element.parentNode.nodeName)) {
parentAttributes = fabric.parseAttributes(element.parentNode, attributes, svgUid);
}
fontSize = (parentAttributes && parentAttributes.fontSize ) ||
element.getAttribute('font-size') || fabric.Text.DEFAULT_SVG_FONT_SIZE;

var ownAttributes = attributes.reduce(function(memo, attr) {
value = element.getAttribute(attr);
Expand All @@ -4200,6 +4199,9 @@ if (typeof console !== 'undefined') {
ownAttributes = extend(ownAttributes,
extend(getGlobalStylesForElement(element, svgUid), fabric.parseStyleAttribute(element)));

fontSize = (parentAttributes && parentAttributes.fontSize ) ||
ownAttributes['font-size'] || fabric.Text.DEFAULT_SVG_FONT_SIZE;

var normalizedAttr, normalizedValue, normalizedStyle = {};
for (var attr in ownAttributes) {
normalizedAttr = normalizeAttr(attr);
Expand Down Expand Up @@ -4370,6 +4372,7 @@ if (typeof console !== 'undefined') {
}
if (!xml || !xml.documentElement) {
callback && callback(null);
return false;
}

fabric.parseSVGDocument(xml.documentElement, function (results, _options, elements, allElements) {
Expand Down Expand Up @@ -7469,13 +7472,11 @@ fabric.ElementsParser = function(elements, callback, options, reviver, parsingOp
ctx.restore();
}
if (path) {
if (path.isCacheDirty()) {
// needed to setup a couple of variables
path.shouldCache();
path.canvas = this;
path._transformDone = true;
path.renderCache({ forClipping: true });
}
path.canvas = this;
// needed to setup a couple of variables
path.shouldCache();
path._transformDone = true;
path.renderCache({ forClipping: true });
this.drawClipPathOnCanvas(ctx);
}
this._renderOverlay(ctx);
Expand All @@ -7494,7 +7495,7 @@ fabric.ElementsParser = function(elements, callback, options, reviver, parsingOp
ctx.save();
ctx.transform(v[0], v[1], v[2], v[3], v[4], v[5]);
// DEBUG: uncomment this line, comment the following
// ctx.globalAlpha = 0.4
// ctx.globalAlpha = 0.4;
ctx.globalCompositeOperation = 'destination-in';
path.transform(ctx);
ctx.scale(1 / path.zoomX, 1 / path.zoomY);
Expand Down Expand Up @@ -9578,10 +9579,12 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
renderTopLayer: function(ctx) {
if (this.isDrawingMode && this._isCurrentlyDrawing) {
this.freeDrawingBrush && this.freeDrawingBrush._render();
this.contextTopDirty = true;
}
// we render the top context - last object
if (this.selection && this._groupSelector) {
this._drawSelection(ctx);
this.contextTopDirty = true;
}
},

Expand All @@ -9596,7 +9599,6 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
this.clearContext(ctx);
this.renderTopLayer(ctx);
this.fire('after:render');
this.contextTopDirty = true;
return this;
},

Expand Down Expand Up @@ -11176,31 +11178,24 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
* Decides whether the canvas should be redrawn in mouseup and mousedown events.
* @private
* @param {Object} target
* @param {Object} pointer
*/
_shouldRender: function(target, pointer) {
_shouldRender: function(target) {
var activeObject = this._activeObject;

if (activeObject && activeObject.isEditing && target === activeObject) {
if (
!!activeObject !== !!target ||
(activeObject && target && (activeObject !== target))
) {
// this covers: switch of target, from target to no target, selection of target
// multiSelection with key and mouse
return true;
}
else if (activeObject && activeObject.isEditing) {
// if we mouse up/down over a editing textbox a cursor change,
// there is no need to re render
return false;
}
return !!(
(target && (
target.isMoving ||
target !== activeObject))
||
(!target && !!activeObject)
||
(!target && !activeObject && !this._groupSelector)
||
(pointer &&
this._previousPointer &&
this.selection && (
pointer.x !== this._previousPointer.x ||
pointer.y !== this._previousPointer.y))
);
return false;
},

/**
Expand All @@ -11212,7 +11207,7 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
*/
__onMouseUp: function (e) {
var target, transform = this._currentTransform,
groupSelector = this._groupSelector,
groupSelector = this._groupSelector, shouldRender = false,
isClick = (!groupSelector || (groupSelector.left === 0 && groupSelector.top === 0));
this._cacheTransformEventData(e);
target = this._target;
Expand Down Expand Up @@ -11241,12 +11236,12 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab

if (transform) {
this._finalizeCurrentTransform(e);
shouldRender = transform.actionPerformed;
}

var shouldRender = this._shouldRender(target, this._absolutePointer);

if (target || !isClick) {
if (!isClick) {
this._maybeGroupObjects(e);
shouldRender || (shouldRender = this._shouldRender(target));
}
if (target) {
target.isMoving = false;
Expand All @@ -11255,8 +11250,14 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
this._handleEvent(e, 'up', LEFT_CLICK, isClick);
this._groupSelector = null;
this._currentTransform = null;
// reset the target information about which corner is selected
target && (target.__corner = 0);
shouldRender && this.requestRenderAll();
if (shouldRender) {
this.requestRenderAll();
}
else if (!isClick) {
this.renderTop();
}
},

/**
Expand Down Expand Up @@ -11469,7 +11470,7 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
var pointer = this._pointer;
// save pointer for check in __onMouseUp event
this._previousPointer = pointer;
var shouldRender = this._shouldRender(target, pointer),
var shouldRender = this._shouldRender(target),
shouldGroup = this._shouldGroup(e, target);
if (this._shouldClearSelection(e, target)) {
this.discardActiveObject(e);
Expand Down Expand Up @@ -11499,7 +11500,7 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
}
this._handleEvent(e, 'down');
// we must renderAll so that we update the visuals
shouldRender && this.requestRenderAll();
(shouldRender || shouldGroup) && this.requestRenderAll();
},

/**
Expand Down Expand Up @@ -13454,7 +13455,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
if (!this._cacheCanvas) {
this._createCacheCanvas();
}
if (this.isCacheDirty(false)) {
if (this.isCacheDirty()) {
this.statefullCache && this.saveState({ propertySet: 'cacheProperties' });
this.drawObject(this._cacheContext, options.forClipping);
this.dirty = false;
Expand Down Expand Up @@ -18840,9 +18841,10 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
* @return {Object} object representation of an instance
*/
toObject: function(propertiesToInclude) {
var _includeDefaultValues = this.includeDefaultValues;
var objsToObject = this._objects.map(function(obj) {
var originalDefaults = obj.includeDefaultValues;
obj.includeDefaultValues = obj.group.includeDefaultValues;
obj.includeDefaultValues = _includeDefaultValues;
var _obj = obj.toObject(propertiesToInclude);
obj.includeDefaultValues = originalDefaults;
return _obj;
Expand All @@ -18863,9 +18865,10 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
objsToObject = sourcePath;
}
else {
var _includeDefaultValues = this.includeDefaultValues;
objsToObject = this._objects.map(function(obj) {
var originalDefaults = obj.includeDefaultValues;
obj.includeDefaultValues = obj.group.includeDefaultValues;
obj.includeDefaultValues = _includeDefaultValues;
var _obj = obj.toDatalessObject(propertiesToInclude);
obj.includeDefaultValues = originalDefaults;
return _obj;
Expand Down Expand Up @@ -19993,8 +19996,11 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
object.filters = filters || [];
fabric.Image.prototype._initFilters.call(object, [object.resizeFilter], function(resizeFilters) {
object.resizeFilter = resizeFilters[0];
var image = new fabric.Image(img, object);
callback(image);
fabric.util.enlivenObjects([object.clipPath], function(enlivedProps) {
object.clipPath = enlivedProps[0];
var image = new fabric.Image(img, object);
callback(image);
});
});
});
}, null, object.crossOrigin);
Expand Down Expand Up @@ -27513,6 +27519,16 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
return;
}

if (this.canvas) {
var currentActive = this.canvas._activeObject;
if (currentActive && currentActive !== this) {
// avoid running this logic when there is an active object
// this because is possible with shift click and fast clicks,
// to rapidly deselect and reselect this object and trigger an enterEdit
return;
}
}

if (this.__lastSelected && !this.__corner) {
this.selected = false;
this.__lastSelected = false;
Expand Down
2 changes: 1 addition & 1 deletion dist/fabric.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "fabric",
"description": "Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.",
"homepage": "http://fabricjs.com/",
"version": "2.4.0",
"version": "2.4.1",
"author": "Juriy Zaytsev <kangax@gmail.com>",
"contributors": [
{
Expand Down

0 comments on commit cd20632

Please sign in to comment.