From 1ecebe38ee6ba569f3488e578be4296408bd51a3 Mon Sep 17 00:00:00 2001 From: mbrzuzy Date: Wed, 1 Jul 2015 09:04:25 -0400 Subject: [PATCH] IE9 bugfix for loading SVGs from URL that contain nodes --- src/shapes/text.class.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/shapes/text.class.js b/src/shapes/text.class.js index 66a9164f..1c74e483 100644 --- a/src/shapes/text.class.js +++ b/src/shapes/text.class.js @@ -1038,8 +1038,25 @@ if (!options.originX) { options.originX = 'left'; } - var textContent = element.textContent.replace(/^\s+|\s+$|\n+/g, '').replace(/\s+/g, ' '), - text = new fabric.Text(textContent, options), + + var textContent = ''; + + // The XML is not properly parsed in IE9 so a workaround to get + // textContent is through firstChild.data. Another workaround would be + // to convert XML loaded from a file to be converted using DOMParser (same way loadSVGFromString() does) + if (!('textContent' in element)) { + if ('firstChild' in element && element.firstChild !== null) { + if ('data' in element.firstChild && element.firstChild.data !== null) { + textContent = element.firstChild.data; + } + } + } else { + textContent = element.textContent; + } + + textContent = element.textContent.replace(/^\s+|\s+$|\n+/g, '').replace(/\s+/g, ' '); + + var text = new fabric.Text(textContent, options); /* Adjust positioning: x/y attributes in SVG correspond to the bottom-left corner of text bounding box