Skip to content

Commit

Permalink
Fix display of svg without cache (#3982)
Browse files Browse the repository at this point in the history
* small changes
  • Loading branch information
asturur authored Jun 7, 2017
1 parent 0bf4b2a commit 044770c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 27 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"license": "MIT",
"scripts": {
"build": "node build.js modules=ALL exclude=json,gestures",
"build:watch": "onchange 'src/**/**' 'test/**/**' 'HEADER.js' 'lib/**/**' -- npm run build",
"build_export": "npm run build && npm run export_dist_to_site",
"build:watch": "onchange 'src/**/**' 'test/**/**' 'HEADER.js' 'lib/**/**' -- npm run build_export",
"build_with_gestures": "node build.js modules=ALL exclude=json",
"test": "node test.js",
"lint": "eslint --config .eslintrc.json src",
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/group.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
* @return {Boolean}
*/
shouldCache: function() {
var parentCache = this.objectCaching && (!this.group || this.needsItsOwnCache || !this.group.isCaching());
var parentCache = this.objectCaching && (!this.group || this.needsItsOwnCache() || !this.group.isCaching());
this.caching = parentCache;
if (parentCache) {
for (var i = 0, len = this._objects.length; i < len; i++) {
Expand Down
35 changes: 18 additions & 17 deletions src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -796,16 +796,6 @@
*/
dirty: true,

/**
* When set to `true`, force the object to have its own cache, even if it is inside a group
* it may be needed when your object behave in a particular way on the cache and always needs
* its own isolated canvas to render correctly.
* since 1.7.5
* @type Boolean
* @default false
*/
needsItsOwnCache: false,

/**
* List of properties to consider when checking if state
* of an object is changed (fabric.Object#hasStateChanged)
Expand Down Expand Up @@ -837,9 +827,6 @@
if (options) {
this.setOptions(options);
}
if (this.objectCaching) {
this._createCacheCanvas();
}
},

/**
Expand Down Expand Up @@ -1154,7 +1141,7 @@
ctx.transform.apply(ctx, this.transformMatrix);
}
this.clipTo && fabric.util.clipContext(this, ctx);
if (this.shouldCache()) {
if (this.shouldCache(noTransform)) {
if (!this._cacheCanvas) {
this._createCacheCanvas();
}
Expand All @@ -1175,17 +1162,31 @@
ctx.restore();
},

/**
* When returns `true`, force the object to have its own cache, even if it is inside a group
* it may be needed when your object behave in a particular way on the cache and always needs
* its own isolated canvas to render correctly.
* This function is created to be subclassed by custom classes.
* since 1.7.12
* @type function
* @return false
*/
needsItsOwnCache: function() {
return false;
},

/**
* Decide if the object should cache or not.
* objectCaching is a global flag, wins over everything
* needsItsOwnCache should be used when the object drawing method requires
* a cache step. None of the fabric classes requires it.
* Generally you do not cache objects in groups because the group outside is cached.
* @param {Boolean} noTransform if rendereing in pathGroup, caching is not supported at object level
* @return {Boolean}
*/
shouldCache: function() {
return this.objectCaching &&
(!this.group || this.needsItsOwnCache || !this.group.isCaching());
shouldCache: function(noTransform) {
return !noTransform && this.objectCaching &&
(!this.group || this.needsItsOwnCache() || !this.group.isCaching());
},

/**
Expand Down
4 changes: 0 additions & 4 deletions src/shapes/path.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@
}

this._setPositionDimensions(options);

if (this.objectCaching) {
this._createCacheCanvas();
}
},

/**
Expand Down
5 changes: 1 addition & 4 deletions src/shapes/path_group.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@
}
this.setOptions(options);
this.setCoords();
if (this.objectCaching) {
this._createCacheCanvas();
}
},

/**
Expand Down Expand Up @@ -112,7 +109,7 @@
* @return {Boolean}
*/
shouldCache: function() {
var parentCache = this.objectCaching && (!this.group || this.needsItsOwnCache || !this.group.isCaching());
var parentCache = this.objectCaching && (!this.group || this.needsItsOwnCache() || !this.group.isCaching());
this.caching = parentCache;
if (parentCache) {
for (var i = 0, len = this.paths.length; i < len; i++) {
Expand Down

0 comments on commit 044770c

Please sign in to comment.