Skip to content

Commit

Permalink
Change getFontDeclaration (#3191)
Browse files Browse the repository at this point in the history
* Change getFontDeclaration
  • Loading branch information
asturur committed Aug 22, 2016
1 parent 181cdec commit 702126e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/shapes/text.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,15 +844,16 @@
},

/**
* @private
* return font declaration string for canvas context
* @returns {String} font declaration formatted for canvas context.
*/
_getFontDeclaration: function() {
return [
// node-canvas needs "weight style", while browsers need "style weight"
(fabric.isLikelyNode ? this.fontWeight : this.fontStyle),
(fabric.isLikelyNode ? this.fontStyle : this.fontWeight),
this.fontSize + 'px',
(fabric.isLikelyNode ? ('"' + this.fontFamily + '"') : this.fontFamily)
'"' + this.fontFamily + '"'
].join(' ');
},

Expand Down
8 changes: 8 additions & 0 deletions test/unit/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@
equal(text.toString(), '#<fabric.Text (1): { "text": "x", "fontFamily": "Times New Roman" }>');
});

test('_getFontDeclaration', function() {
var text = createTextObject();
ok(typeof text._getFontDeclaration == 'function', 'has a private method _getFontDeclaration');
var fontDecl = text._getFontDeclaration();
ok(typeof fontDecl == 'string', 'it returns a string');
equal(fontDecl, 'normal 40px "Times New Roman"');
});

test('toObject', function() {
var text = createTextObject();
ok(typeof text.toObject == 'function');
Expand Down

0 comments on commit 702126e

Please sign in to comment.