Skip to content

Commit

Permalink
fix text coordinates on init (#3745)
Browse files Browse the repository at this point in the history
* fix text coordinates on init

* added small test

* fix test lint
asturur committed Feb 27, 2017
1 parent c1ff02e commit 0b325bb
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/shapes/text.class.js
Original file line number Diff line number Diff line change
@@ -358,6 +358,7 @@
this.callSuper('initialize', options);
this.__skipDimension = false;
this._initDimensions();
this.setCoords();
this.setupState({ propertySet: '_dimensionAffectingProps' });
},

21 changes: 19 additions & 2 deletions test/unit/text.js
Original file line number Diff line number Diff line change
@@ -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');

0 comments on commit 0b325bb

Please sign in to comment.