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 45774fd
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/static_canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@
__initRetinaScaling: function(scaleRatio, canvas, context) {
canvas.setAttribute('width', this.width * scaleRatio);
canvas.setAttribute('height', this.height * scaleRatio);
context.scale(scaleRatio, scaleRatio);
if (context) {
context.scale(scaleRatio, scaleRatio);
}
},


Expand Down Expand Up @@ -815,7 +817,6 @@
* Returns coordinates of a center of canvas.
* Returned value is an object with top and left properties
* @return {Object} object with "top" and "left" number values
* @deprecated migrate to `getCenterPoint`
*/
getCenter: function () {
return {
Expand All @@ -824,21 +825,13 @@
};
},

/**
* Returns coordinates of a center of canvas.
* @return {fabric.Point}
*/
getCenterPoint: function () {
return new fabric.Point(this.width / 2, this.height / 2);
},

/**
* Centers object horizontally in the canvas
* @param {fabric.Object} object Object to center horizontally
* @return {fabric.Canvas} thisArg
*/
centerObjectH: function (object) {
return this._centerObject(object, new fabric.Point(this.getCenterPoint().x, object.getCenterPoint().y));
return this._centerObject(object, new fabric.Point(this.getCenter().left, object.getCenterPoint().y));
},

/**
Expand All @@ -848,7 +841,7 @@
* @chainable
*/
centerObjectV: function (object) {
return this._centerObject(object, new fabric.Point(object.getCenterPoint().x, this.getCenterPoint().y));
return this._centerObject(object, new fabric.Point(object.getCenterPoint().x, this.getCenter().top));
},

/**
Expand All @@ -858,8 +851,9 @@
* @chainable
*/
centerObject: function(object) {
var center = this.getCenterPoint();
return this._centerObject(object, center);
var center = this.getCenter();

return this._centerObject(object, new fabric.Point(center.left, center.top));
},

/**
Expand All @@ -870,6 +864,7 @@
*/
viewportCenterObject: function(object) {
var vpCenter = this.getVpCenter();

return this._centerObject(object, vpCenter);
},

Expand Down Expand Up @@ -903,9 +898,9 @@
* @chainable
*/
getVpCenter: function() {
var center = this.getCenterPoint(),
var center = this.getCenter(),
iVpt = invertTransform(this.viewportTransform);
return transformPoint(center, iVpt);
return transformPoint({ x: center.left, y: center.top }, iVpt);
},

/**
Expand Down

0 comments on commit 45774fd

Please sign in to comment.