Make sure text objects have dimensions before they're added to canvas. Closes #158.

This commit is contained in:
kangax 2012-07-27 02:56:52 +02:00
parent 0371d7ba7c
commit 82ba3169f7
4 changed files with 30 additions and 3 deletions

14
dist/all.js vendored
View file

@ -12446,10 +12446,22 @@ fabric.Image.filters.GradientTransparency.fromObject = function(object) {
this.text = text;
this.setOptions(options);
this.theta = this.angle * Math.PI / 180;
this.width = this.getWidth();
this._initDimensions();
this.setCoords();
},
_initDimensions: function() {
// render on offscreen canvas, so that object would get dimensions
var canvasEl = fabric.document.createElement('canvas');
if (!canvasEl.getContext && typeof G_vmlCanvasManager != 'undefined') {
G_vmlCanvasManager.initElement(canvasEl);
}
this._render(canvasEl.getContext('2d'));
},
/**
* Creates `stateProperties` list on an instance, and adds `fabric.Text` -specific ones to it
* (such as "fontFamily", "fontWeight", etc.)

2
dist/all.min.js vendored

File diff suppressed because one or more lines are too long

BIN
dist/all.min.js.gz vendored

Binary file not shown.

View file

@ -121,10 +121,25 @@
this.text = text;
this.setOptions(options);
this.theta = this.angle * Math.PI / 180;
this.width = this.getWidth();
this._initDimensions();
this.setCoords();
},
/**
* Renders text object on offscreen canvas, so that it would get dimensions
* @private
* @method _initDimensions
*/
_initDimensions: function() {
var canvasEl = fabric.document.createElement('canvas');
if (!canvasEl.getContext && typeof G_vmlCanvasManager != 'undefined') {
G_vmlCanvasManager.initElement(canvasEl);
}
this._render(canvasEl.getContext('2d'));
},
/**
* Creates `stateProperties` list on an instance, and adds `fabric.Text` -specific ones to it
* (such as "fontFamily", "fontWeight", etc.)