Skip to content

Commit

Permalink
new commit per asturur
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisrjohn committed Mar 16, 2018
1 parent 2ce99ee commit a5c1cdc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/shapes/text.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1203,12 +1203,16 @@
*/
_getFontDeclaration: function(styleObject, forMeasuring) {
var style = styleObject || this;
var fontFamily = style.fontFamily === undefined ||
style.fontFamily.includes('\'') ||
style.fontFamily.includes('"')
? style.fontFamily : '"' + style.fontFamily + '"';
return [
// node-canvas needs "weight style", while browsers need "style weight"
(fabric.isLikelyNode ? style.fontWeight : style.fontStyle),
(fabric.isLikelyNode ? style.fontStyle : style.fontWeight),
forMeasuring ? this.CACHE_FONT_SIZE + 'px' : style.fontSize + 'px',
(fabric.isLikelyNode ? ('"' + style.fontFamily + '"') : style.fontFamily)
fontFamily
].join(' ');
},

Expand Down
12 changes: 5 additions & 7 deletions test/unit/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,11 @@
assert.ok(typeof text._getFontDeclaration === 'function', 'has a private method _getFontDeclaration');
var fontDecl = text._getFontDeclaration();
assert.ok(typeof fontDecl == 'string', 'it returns a string');
if (fabric.isLikelyNode) {
assert.equal(fontDecl, 'normal normal 40px "Times New Roman"');
}
else {
assert.equal(fontDecl, 'normal normal 40px Times New Roman');
}

assert.equal(fontDecl, 'normal normal 40px "Times New Roman"');
text.fontFamily = '"Times New Roman"';
assert.equal(fontDecl, 'normal normal 40px "Times New Roman"');
text.fontFamily = '\'Times New Roman\'';
assert.equal(fontDecl, 'normal normal 40px \'Times New Roman\'');
});

QUnit.test('toObject', function(assert) {
Expand Down

0 comments on commit a5c1cdc

Please sign in to comment.