fix text coordinates on init (#3745)

* fix text coordinates on init

* added small test

* fix test lint
This commit is contained in:
Andrea Bogazzi 2017-02-27 02:02:30 +01:00 committed by GitHub
parent 1f55de07c4
commit c3a6447aff
2 changed files with 20 additions and 2 deletions

View file

@ -358,6 +358,7 @@
this.callSuper('initialize', options);
this.__skipDimension = false;
this._initDimensions();
this.setCoords();
this.setupState({ propertySet: '_dimensionAffectingProps' });
},

View file

@ -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');