Skip to content

Commit

Permalink
Add context check for __initRetinaScaling
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejslogins committed Feb 19, 2022
1 parent 043f102 commit 8ccb8b7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/static_canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,19 @@
return;
}
var scaleRatio = fabric.devicePixelRatio;
this.__initRetinaScaling(scaleRatio, this.lowerCanvasEl, this.contextContainer);
this.__initRetinaScaling(scaleRatio, this.lowerCanvasEl);
if (this.upperCanvasEl) {
this.__initRetinaScaling(scaleRatio, this.upperCanvasEl, this.contextTop);
this.__initRetinaScaling(scaleRatio, this.upperCanvasEl);
}
},

__initRetinaScaling: function(scaleRatio, canvas, context) {
__initRetinaScaling: function(scaleRatio, canvas) {
canvas.setAttribute('width', this.width * scaleRatio);
canvas.setAttribute('height', this.height * scaleRatio);
context.scale(scaleRatio, scaleRatio);
var context = canvas.getContext('2d');
if (context) {
context.scale(scaleRatio, scaleRatio);
}
},


Expand Down Expand Up @@ -319,8 +322,6 @@
if (this.interactive) {
this._applyCanvasStyle(this.lowerCanvasEl);
}

this.contextContainer = this.lowerCanvasEl.getContext('2d');
},

/**
Expand Down Expand Up @@ -1568,7 +1569,6 @@
}
this.overlayImage = null;
this._iTextInstances = null;
this.contextContainer = null;
// restore canvas style
this.lowerCanvasEl.classList.remove('lower-canvas');
fabric.util.setStyle(this.lowerCanvasEl, this._originalCanvasStyle);
Expand Down

0 comments on commit 8ccb8b7

Please sign in to comment.