mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-04-19 05:31:07 +00:00
Fix a bug in recent caching changes (#4051)
* small fix * fixed and added tests * comeon andrea wake up
This commit is contained in:
parent
4a8df81c4b
commit
98ed4cc351
4 changed files with 38 additions and 9 deletions
|
|
@ -340,7 +340,7 @@
|
|||
*/
|
||||
willDrawShadow: function() {
|
||||
if (this.shadow) {
|
||||
return true;
|
||||
return this.callSuper('willDrawShadow');
|
||||
}
|
||||
for (var i = 0, len = this._objects.length; i < len; i++) {
|
||||
if (this._objects[i].willDrawShadow()) {
|
||||
|
|
|
|||
|
|
@ -945,8 +945,6 @@
|
|||
if (shouldResizeCanvas) {
|
||||
this._cacheCanvas.width = Math.max(Math.ceil(width) + additionalWidth, minCacheSize);
|
||||
this._cacheCanvas.height = Math.max(Math.ceil(height) + additionalHeight, minCacheSize);
|
||||
this.cacheWidth = width;
|
||||
this.cacheHeight = height;
|
||||
this.cacheTranslationX = (width + additionalWidth) / 2;
|
||||
this.cacheTranslationY = (height + additionalHeight) / 2;
|
||||
}
|
||||
|
|
@ -954,6 +952,8 @@
|
|||
this._cacheContext.setTransform(1, 0, 0, 1, 0, 0);
|
||||
this._cacheContext.clearRect(0, 0, this._cacheCanvas.width, this._cacheCanvas.height);
|
||||
}
|
||||
this.cacheWidth = width;
|
||||
this.cacheHeight = height;
|
||||
this._cacheContext.translate(this.cacheTranslationX, this.cacheTranslationY);
|
||||
this._cacheContext.scale(zoomX, zoomY);
|
||||
this.zoomX = zoomX;
|
||||
|
|
@ -1268,7 +1268,7 @@
|
|||
* @return {Boolean}
|
||||
*/
|
||||
willDrawShadow: function() {
|
||||
return !!this.shadow;
|
||||
return !!this.shadow && (this.shadow.offsetX !== 0 || this.shadow.offsetY !== 0);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -612,18 +612,40 @@
|
|||
group3 = new fabric.Group([group, group2]);
|
||||
|
||||
equal(group3.willDrawShadow(), false, 'group will not cast shadow because objects do not have it');
|
||||
group3.shadow = {};
|
||||
group3.shadow = { offsetX: 1, offsetY: 2, };
|
||||
equal(group3.willDrawShadow(), true, 'group will cast shadow because group itself has shadow');
|
||||
delete group3.shadow;
|
||||
group2.shadow = {};
|
||||
group2.shadow = { offsetX: 1, offsetY: 2, };
|
||||
equal(group3.willDrawShadow(), true, 'group will cast shadow because inner group2 has shadow');
|
||||
delete group2.shadow;
|
||||
rect1.shadow = {};
|
||||
rect1.shadow = { offsetX: 1, offsetY: 2, };
|
||||
equal(group3.willDrawShadow(), true, 'group will cast shadow because inner rect1 has shadow');
|
||||
equal(group.willDrawShadow(), true, 'group will cast shadow because inner rect1 has shadow');
|
||||
equal(group2.willDrawShadow(), false, 'group will not cast shadow because no child has shadow');
|
||||
});
|
||||
|
||||
test('group willDrawShadow with no offsets', function() {
|
||||
var rect1 = new fabric.Rect({ top: 1, left: 1, width: 2, height: 2, strokeWidth: 0, fill: 'red', opacity: 1, objectCaching: false}),
|
||||
rect2 = new fabric.Rect({ top: 5, left: 5, width: 2, height: 2, strokeWidth: 0, fill: 'red', opacity: 1, objectCaching: false}),
|
||||
rect3 = new fabric.Rect({ top: 5, left: 5, width: 2, height: 2, strokeWidth: 0, fill: 'red', opacity: 1, objectCaching: false}),
|
||||
rect4 = new fabric.Rect({ top: 5, left: 5, width: 2, height: 2, strokeWidth: 0, fill: 'red', opacity: 1, objectCaching: false}),
|
||||
group = new fabric.Group([rect1, rect2]),
|
||||
group2 = new fabric.Group([rect3, rect4]),
|
||||
group3 = new fabric.Group([group, group2]);
|
||||
|
||||
equal(group3.willDrawShadow(), false, 'group will not cast shadow because objects do not have it');
|
||||
group3.shadow = { offsetX: 0, offsetY: 0 };
|
||||
equal(group3.willDrawShadow(), false, 'group will NOT cast shadow because group itself has shadow but not offsets');
|
||||
group3.shadow = { offsetX: 2, offsetY: 0 };
|
||||
equal(group3.willDrawShadow(), true, 'group will cast shadow because group itself has shadow and one offsetX different than 0');
|
||||
group3.shadow = { offsetX: 0, offsetY: 2 };
|
||||
equal(group3.willDrawShadow(), true, 'group will cast shadow because group itself has shadow and one offsetY different than 0');
|
||||
group3.shadow = { offsetX: -2, offsetY: 0 };
|
||||
equal(group3.willDrawShadow(), true, 'group will cast shadow because group itself has shadow and one offsetX different than 0');
|
||||
group3.shadow = { offsetX: 0, offsetY: -2 };
|
||||
equal(group3.willDrawShadow(), true, 'group will cast shadow because group itself has shadow and one offsetY different than 0');
|
||||
});
|
||||
|
||||
test('group shouldCache', function() {
|
||||
var rect1 = new fabric.Rect({ top: 1, left: 1, width: 2, height: 2, strokeWidth: 0, fill: 'red', opacity: 1, objectCaching: true}),
|
||||
rect2 = new fabric.Rect({ top: 5, left: 5, width: 2, height: 2, strokeWidth: 0, fill: 'red', opacity: 1, objectCaching: true}),
|
||||
|
|
@ -637,8 +659,8 @@
|
|||
equal(group2.shouldCache(), false, 'group2 will not cache because is drawing on parent group3 cache');
|
||||
equal(rect3.shouldCache(), false, 'rect3 will not cache because is drawing on parent2 group cache');
|
||||
|
||||
group2.shadow = {};
|
||||
rect1.shadow = {};
|
||||
group2.shadow = { offsetX: 2, offsetY: 0 };
|
||||
rect1.shadow = { offsetX: 0, offsetY: 2 };
|
||||
|
||||
equal(group3.shouldCache(), false, 'group3 will cache because children have shadow');
|
||||
equal(group2.shouldCache(), true, 'group2 will cache because is not drawing on parent group3 cache and no children have shadow');
|
||||
|
|
|
|||
|
|
@ -1351,4 +1351,11 @@
|
|||
equal(context.shadowOffsetY, object.shadow.offsetY * object.scaleY * group.scaleY);
|
||||
equal(context.shadowBlur, object.shadow.blur * (object.scaleX * group.scaleX + object.scaleY * group.scaleY) / 2);
|
||||
});
|
||||
|
||||
test('willDrawShadow', function() {
|
||||
var object = new fabric.Object({ shadow: { offsetX: 0, offsetY: 0 }});
|
||||
equal(object.willDrawShadow(), false, 'object will not drawShadow');
|
||||
object.shadow.offsetX = 1;
|
||||
equal(object.willDrawShadow(), true, 'object will drawShadow');
|
||||
});
|
||||
})();
|
||||
|
|
|
|||
Loading…
Reference in a new issue