diff --git a/src/mixins/itext.svg_export.js b/src/mixins/itext.svg_export.js
index 370e3f5967c..7458cf97fb0 100644
--- a/src/mixins/itext.svg_export.js
+++ b/src/mixins/itext.svg_export.js
@@ -1,6 +1,7 @@
/* _TO_SVG_START_ */
(function() {
- var toFixed = fabric.util.toFixed;
+ var toFixed = fabric.util.toFixed,
+ multipleSpacesRegex = / +/g;
fabric.util.object.extend(fabric.Text.prototype, /** @lends fabric.Text.prototype */ {
@@ -86,7 +87,8 @@
* @private
*/
_createTextCharSpan: function(_char, styleDecl, left, top) {
- var styleProps = this.getSvgSpanStyles(styleDecl, _char !== _char.trim()),
+ var shouldUseWhitespace = _char !== _char.trim() || _char.match(multipleSpacesRegex),
+ styleProps = this.getSvgSpanStyles(styleDecl, shouldUseWhitespace),
fillStyles = styleProps ? 'style="' + styleProps + '"' : '',
dy = styleDecl.deltaY, dySpan = '',
NUM_FRACTION_DIGITS = fabric.Object.NUM_FRACTION_DIGITS;
diff --git a/test/unit/text_to_svg.js b/test/unit/text_to_svg.js
index cdf1e08b87f..0a01aea9c08 100644
--- a/test/unit/text_to_svg.js
+++ b/test/unit/text_to_svg.js
@@ -18,6 +18,11 @@
assert.equal(removeTranslate(text.toSVG()), removeTranslate(TEXT_SVG_JUSTIFIED));
});
+ QUnit.test('toSVG with multiple spaces', function(assert) {
+ var TEXT_SVG_MULTIPLESPACES = '\t\n\t\tx y\n\t\n';
+ var text = new fabric.Text('x y');
+ assert.equal(removeTranslate(text.toSVG()), removeTranslate(TEXT_SVG_MULTIPLESPACES));
+ });
QUnit.test('toSVG with deltaY', function(assert) {
fabric.Object.NUM_FRACTION_DIGITS = 0;
var TEXT_SVG = '\t\n\t\txx\n\t\n';