Skip to content

Commit

Permalink
New PR fo 4808 (fabricjs#4831)
Browse files Browse the repository at this point in the history
* new commit per asturur

* new commit per asturur
  • Loading branch information
dennisrjohn authored and asturur committed Mar 17, 2018
1 parent 3ed67e9 commit e6225e0
Show file tree
Hide file tree
Showing 2 changed files with 12 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.indexOf('\'') > -1 ||
style.fontFamily.indexOf('"') > -1
? 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
14 changes: 7 additions & 7 deletions test/unit/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@
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"';
fontDecl = text._getFontDeclaration();
assert.equal(fontDecl, 'normal normal 40px "Times New Roman"');
text.fontFamily = '\'Times New Roman\'';
fontDecl = text._getFontDeclaration();
assert.equal(fontDecl, 'normal normal 40px \'Times New Roman\'');
});

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

0 comments on commit e6225e0

Please sign in to comment.