From 044770c6f90f633889726dfee0a4f48e7337ccc0 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Wed, 7 Jun 2017 10:01:49 +0200 Subject: [PATCH] Fix display of svg without cache (#3982) * small changes --- package.json | 3 ++- src/shapes/group.class.js | 2 +- src/shapes/object.class.js | 35 +++++++++++++++++----------------- src/shapes/path.class.js | 4 ---- src/shapes/path_group.class.js | 5 +---- 5 files changed, 22 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 1fca4f3d..be5069cc 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/shapes/group.class.js b/src/shapes/group.class.js index 1d8eb02d..6db90516 100644 --- a/src/shapes/group.class.js +++ b/src/shapes/group.class.js @@ -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++) { diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index ad28136e..0d2c3957 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -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) @@ -837,9 +827,6 @@ if (options) { this.setOptions(options); } - if (this.objectCaching) { - this._createCacheCanvas(); - } }, /** @@ -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(); } @@ -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()); }, /** diff --git a/src/shapes/path.class.js b/src/shapes/path.class.js index be92a02d..f4d0e9d9 100644 --- a/src/shapes/path.class.js +++ b/src/shapes/path.class.js @@ -104,10 +104,6 @@ } this._setPositionDimensions(options); - - if (this.objectCaching) { - this._createCacheCanvas(); - } }, /** diff --git a/src/shapes/path_group.class.js b/src/shapes/path_group.class.js index 141e24a7..34c82bd5 100644 --- a/src/shapes/path_group.class.js +++ b/src/shapes/path_group.class.js @@ -54,9 +54,6 @@ } this.setOptions(options); this.setCoords(); - if (this.objectCaching) { - this._createCacheCanvas(); - } }, /** @@ -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++) {