Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaBogazzi committed Dec 27, 2024
1 parent 3c9d124 commit 9c6606c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 23 deletions.
27 changes: 7 additions & 20 deletions dist/fabric.js
Original file line number Diff line number Diff line change
Expand Up @@ -15180,8 +15180,8 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
// for sure this ALIASING_LIMIT is slightly creating problem
// in situation in which the cache canvas gets an upper limit
// also objectScale contains already scaleX and scaleY
width: neededX + ALIASING_LIMIT,
height: neededY + ALIASING_LIMIT,
width: Math.ceil(neededX + ALIASING_LIMIT),
height: Math.ceil(neededY + ALIASING_LIMIT),
zoomX: objectScale.scaleX,
zoomY: objectScale.scaleY,
x: neededX,
Expand All @@ -15206,29 +15206,16 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
}
var canvas = this._cacheCanvas,
dims = this._limitCacheSize(this._getCacheCanvasDimensions()),
minCacheSize = fabric.minCacheSideLimit,
width = dims.width, height = dims.height, drawingWidth, drawingHeight,
zoomX = dims.zoomX, zoomY = dims.zoomY,
dimensionsChanged = width !== this.cacheWidth || height !== this.cacheHeight,
zoomChanged = this.zoomX !== zoomX || this.zoomY !== zoomY,
shouldRedraw = dimensionsChanged || zoomChanged,
additionalWidth = 0, additionalHeight = 0, shouldResizeCanvas = false;
if (dimensionsChanged) {
var canvasWidth = this._cacheCanvas.width,
canvasHeight = this._cacheCanvas.height,
sizeGrowing = width > canvasWidth || height > canvasHeight,
sizeShrinking = (width < canvasWidth * 0.9 || height < canvasHeight * 0.9) &&
canvasWidth > minCacheSize && canvasHeight > minCacheSize;
shouldResizeCanvas = sizeGrowing || sizeShrinking;
if (sizeGrowing && !dims.capped && (width > minCacheSize || height > minCacheSize)) {
additionalWidth = width * 0.1;
additionalHeight = height * 0.1;
}
}
shouldRedraw = dimensionsChanged || zoomChanged;

if (shouldRedraw) {
if (shouldResizeCanvas) {
canvas.width = Math.ceil(width + additionalWidth);
canvas.height = Math.ceil(height + additionalHeight);
if (dimensionsChanged) {
canvas.width = width;
canvas.height = height;
}
else {
this._cacheContext.setTransform(1, 0, 0, 1, 0, 0);
Expand Down
2 changes: 1 addition & 1 deletion dist/fabric.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test/unit/canvas_static.js
Original file line number Diff line number Diff line change
Expand Up @@ -1319,12 +1319,12 @@
});

QUnit.test('loadFromJSON with clipPath', function(assert) {
var canvas2 = new fabric.StaticCanvas(null, { width: 400, height: 400 });
var canvas2 = new fabric.StaticCanvas(null, { width: 400, height: 400, renderOnAddRemove: false });
var done = assert.async();
var json = '{"clipPath": {"type":"text","left":150,"top":200,"width":128,"height":64.32,"fill":"#000000","stroke":"","strokeWidth":"","scaleX":0.8,"scaleY":0.8,"angle":0,"flipX":false,"flipY":false,"opacity":1,"text":"NAME HERE","fontSize":24,"fontWeight":"","fontFamily":"Delicious_500","fontStyle":"","lineHeight":"","textDecoration":"","textAlign":"center","path":"","strokeStyle":"","backgroundColor":""}}';
canvas2.loadFromJSON(json, function() {
canvas2.renderAll();
assert.equal('text', canvas2.clipPath.type);
canvas2.dispose();
done();
});
});
Expand Down

0 comments on commit 9c6606c

Please sign in to comment.