diff --git a/src/shapes/text.class.js b/src/shapes/text.class.js index ffda6cea787..33496e37039 100644 --- a/src/shapes/text.class.js +++ b/src/shapes/text.class.js @@ -358,6 +358,7 @@ this.callSuper('initialize', options); this.__skipDimension = false; this._initDimensions(); + this.setCoords(); this.setupState({ propertySet: '_dimensionAffectingProps' }); }, diff --git a/test/unit/text.js b/test/unit/text.js index e90c369704c..73399df09a8 100644 --- a/test/unit/text.js +++ b/test/unit/text.js @@ -2,8 +2,8 @@ QUnit.module('fabric.Text'); - function createTextObject() { - return new fabric.Text('x'); + function createTextObject(text) { + return new fabric.Text(text || 'x'); } var CHAR_WIDTH = 20; @@ -141,6 +141,23 @@ equal(text.get('fontFamily'), 'blah'); }); + test('get bounding rect after init', function() { + var string = 'Some long text, the quick brown fox jumps over the lazy dog etc... blah blah blah'; + var text = new fabric.Text(string, { + left: 30, + top: 30, + fill: '#ffffff', + fontSize: 24, + fontWeight: 'normal', + fontFamily: 'Arial', + originY: 'bottom' + }); + var br = text.getBoundingRect(); + text.setCoords(); + var br2 = text.getBoundingRect(); + deepEqual(br, br2, 'text bounding box is the same before and after calling setCoords'); + }); + test('setShadow', function(){ var text = createTextObject(); ok(typeof text.setShadow == 'function');