diff --git a/src/shapes/text.class.js b/src/shapes/text.class.js index 15121180c6e..4e9205e771f 100644 --- a/src/shapes/text.class.js +++ b/src/shapes/text.class.js @@ -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(' '); }, diff --git a/test/unit/text.js b/test/unit/text.js index d5be19d577a..4c95b4daef3 100644 --- a/test/unit/text.js +++ b/test/unit/text.js @@ -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) {