IE9 bugfix for loading SVGs from URL that contain <text> nodes

This commit is contained in:
mbrzuzy 2015-07-01 09:04:25 -04:00
parent d0eb828ba5
commit 1ecebe38ee

View file

@ -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