diff --git a/src/mixins/itext.svg_export.js b/src/mixins/itext.svg_export.js
index f9d9bb9539e..33e875377a4 100644
--- a/src/mixins/itext.svg_export.js
+++ b/src/mixins/itext.svg_export.js
@@ -87,7 +87,7 @@
* @private
*/
_createTextCharSpan: function(_char, styleDecl, left, top) {
- var styleProps = this.getSvgSpanStyles(styleDecl, false),
+ var styleProps = this.getSvgSpanStyles(styleDecl, _char !== _char.trim()),
fillStyles = styleProps ? 'style="' + styleProps + '"' : '';
return [
@@ -212,8 +212,12 @@
};
},
+ /**
+ * Returns styles-string for svg-export
+ * @param {Boolean} skipShadow a boolean to skip shadow filter output
+ * @return {String}
+ */
getSvgStyles: function(skipShadow) {
-
var svgStyle = fabric.Object.prototype.getSvgStyles.call(this, skipShadow);
return svgStyle + ' white-space: pre;';
},
diff --git a/src/mixins/object.svg_export.js b/src/mixins/object.svg_export.js
index 5ac001d4010..429277ac698 100644
--- a/src/mixins/object.svg_export.js
+++ b/src/mixins/object.svg_export.js
@@ -60,10 +60,11 @@
/**
* Returns styles-string for svg-export
- * @param {Boolean} skipShadow a boolean to skip shadow filter output
+ * @param {Object} style style properties for the span a boolean to skip shadow filter output
+ * @param {Boolean} useWhiteSpace a boolean to include an additional attribute in the style.
* @return {String}
*/
- getSvgSpanStyles: function(style) {
+ getSvgSpanStyles: function(style, useWhiteSpace) {
var strokeWidth = style.strokeWidth ? 'stroke-width: ' + style.strokeWidth + '; ' : '',
fontFamily = style.fontFamily ? 'font-family: ' + style.fontFamily.replace(/"/g, '\'') + '; ' : '',
fontSize = style.fontSize ? 'font-size: ' + style.fontSize + '; ' : '',
@@ -82,6 +83,7 @@
fontWeight,
textDecoration,
fill,
+ useWhiteSpace ? 'white-space: pre; ' : ''
].join('');
},
diff --git a/test/unit/text.js b/test/unit/text.js
index 3d2003385fc..38dd34d865b 100644
--- a/test/unit/text.js
+++ b/test/unit/text.js
@@ -59,7 +59,7 @@
};
var TEXT_SVG = '\t\n\t\t\n\t\t\tx\n\t\t\n\t\n';
- var TEXT_SVG_JUSTIFIED = '\t\n\t\t\n\t\t\txxxxxx\n\t\t\tx \n\t\t\ty\n\t\t\n\t\n';
+ var TEXT_SVG_JUSTIFIED = '\t\n\t\t\n\t\t\txxxxxx\n\t\t\tx \n\t\t\ty\n\t\t\n\t\n';
test('constructor', function() {
ok(fabric.Text);