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

Fix display of svg without cache #3982

Merged
merged 3 commits into from
Jun 7, 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
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