Skip to content

Commit

Permalink
fix(): 5.x Disable offscreen check for bg and overlay when not needed (
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored May 7, 2023
1 parent 8f53632 commit 3251c46
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Changelog

## [5.4.0]

- fix() fix an issue with offScreen detection and background/overlay Vpt setting [`#8896`](https://github.com/fabricjs/fabric.js/pull/8896)

## [5.2.1]

- fix(): add `eraser` to Object state/cache props [`#7720`](https://github.com/fabricjs/fabric.js/pull/7720)

## [5.2.0]

- feat(fabric.Object): isType accepts multiple `type` [`#7715`](https://github.com/fabricjs/fabric.js/pull/7715)
- chore(): Replace deprecated String.prototype.substr() with Array.prototype.slice() [`#7696`](https://github.com/fabricjs/fabric.js/pull/7696)
- chore(): use Array.isArray instead of ie6+ workarounds [`#7718`](https://github.com/fabricjs/fabric.js/pull/7718)
- MINOR: feat(fabric.Canvas): add `getTopContext` method to expose the internal contextTop [`#7697`](https://github.com/fabricjs/fabric.js/pull/7697)
- fix(fabric.Object) Add cacheContext checks before trying to render on cache [`#7694`](https://github.com/fabricjs/fabric.js/pull/7694)
- tests(): node test suite enhancement [`#7691`](https://github.com/fabricjs/fabric.js/pull/7691)
- feat(Canvas#getCenter): migrate to `getCenterPoint` [`#7699`](https://github.com/fabricjs/fabric.js/pull/7699)
- updated package.json [`803ce95`](https://github.com/fabricjs/fabric.js/commit/803ce95878150fba9e4195804bccae9bcfe45c6d)
- tests(fabric.animation): fix test reliability [`4be0fb9`](https://github.com/fabricjs/fabric.js/commit/4be0fb9903e15db294b89030feb645e5da766740)

## [5.1.0]

- build(deps): bump node-fetch from 2.6.6 to 2.6.7 [`#7684`](https://github.com/fabricjs/fabric.js/pull/7684)
Expand Down
5 changes: 5 additions & 0 deletions src/static_canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -999,10 +999,15 @@
}
if (object) {
ctx.save();
var skipOffscreen = this.skipOffscreen;
// if the object doesn't move with the viewport,
// the offscreen concept does not apply;
this.skipOffscreen = needsVpt;
if (needsVpt) {
ctx.transform(v[0], v[1], v[2], v[3], v[4], v[5]);
}
object.render(ctx);
this.skipOffscreen = skipOffscreen;
ctx.restore();
}
},
Expand Down
66 changes: 66 additions & 0 deletions test/visual/generic_rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,72 @@
height: 100,
});

function bgOverlayVpt(canvas, callback) {
var rectbg = new fabric.Rect({
width: 300,
height: 300,
top: 0,
left: 0,
fill: 'rgba(255,0,0,0.5)'
});
var rectoverlay = new fabric.Rect({
width: 300,
height: 300,
top: 0,
left: 0,
fill: 'rgba(0,0,255,0.5)'
});
canvas.overlayVpt = false;
canvas.backgroundVpt = false;
canvas.setViewportTransform([0.1,0,0,0.1,7000,7000]);
canvas.backgroundImage = rectbg;
canvas.overlayImage = rectoverlay;
canvas.renderAll();
callback(canvas.lowerCanvasEl);
}

tests.push({
test: 'bg-overlay and vpts',
code: bgOverlayVpt,
golden: 'bgOverlayVpt.png',
percentage: 0.04,
width: 300,
height: 300,
});

function bgOverlayRespectingVpt(canvas, callback) {
var rectbg = new fabric.Rect({
width: 300,
height: 300,
top: 0,
left: 0,
fill: 'rgba(255,0,0,0.5)'
});
var rectoverlay = new fabric.Rect({
width: 300,
height: 300,
top: 0,
left: 0,
fill: 'rgba(0,0,255,0.5)'
});
canvas.overlayVpt = true;
canvas.backgroundVpt = true;
canvas.setViewportTransform([0.9,0,0,0.9,150,150]);
canvas.backgroundImage = rectbg;
canvas.overlayImage = rectoverlay;
canvas.renderAll();
callback(canvas.lowerCanvasEl);
}

tests.push({
test: 'bg-overlay and vpts',
code: bgOverlayRespectingVpt,
golden: 'bgOverlayRespectVpt.png',
percentage: 0.04,
width: 300,
height: 300,
});

function gradientStroke(canvas, callback) {
var line = new fabric.Line([10, 10, 200, 200], {
stroke: new fabric.Gradient({
Expand Down
Binary file added test/visual/golden/bgOverlayRespectVpt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/visual/golden/bgOverlayVpt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3251c46

Please sign in to comment.