mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-05 04:14:54 +00:00
Update parser.js
Moved in a separate function. Tried to fix sneaky tabs and spaces.
This commit is contained in:
parent
52c9792e15
commit
4ccc2c83ba
1 changed files with 32 additions and 26 deletions
|
|
@ -364,6 +364,35 @@
|
|||
return styles;
|
||||
}
|
||||
|
||||
function parseUseDirectives(doc) {
|
||||
var nodelist = doc.getElementsByTagName('*');
|
||||
for (var i = 0; i < nodelist.length; i++) {
|
||||
var el = nodelist[i];
|
||||
if (el.tagName.toLowerCase() === 'use') {
|
||||
var xlink = el.getAttribute('xlink:href').substr(1);
|
||||
var x = el.getAttribute('x') || 0;
|
||||
var y = el.getAttribute('y') || 0;
|
||||
var el2 = doc.getElementById(xlink).cloneNode(true);
|
||||
var currentTrans = (el.getAttribute('transform') || '') + ' translate(' + x + ', ' + y + ')';
|
||||
for (var j = 0, attrs = el.attributes, l = attrs.length; j < l; j++) {
|
||||
var attr = attrs.item(j);
|
||||
if (attr.nodeName !== 'x' && attr.nodeName !== 'y' && attr.nodeName !== 'xlink:href') {
|
||||
if (attr.nodeName === 'transform') {
|
||||
currentTrans = currentTrans + ' ' + attr.nodeValue;
|
||||
} else {
|
||||
el2.setAttribute(attr.nodeName, attr.nodeValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
el2.setAttribute('transform', currentTrans);
|
||||
el2.removeAttribute('id');
|
||||
var pNode=el.parentNode;
|
||||
pNode.replaceChild(el2, el);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses an SVG document, converts it to an array of corresponding fabric.* instances and passes them to a callback
|
||||
* @static
|
||||
|
|
@ -404,31 +433,8 @@
|
|||
return function(doc, callback, reviver) {
|
||||
if (!doc) return;
|
||||
var startTime = new Date();
|
||||
var nodelist = doc.getElementsByTagName('*')
|
||||
for (var i = 0; i < nodelist.length; i++) {
|
||||
var el = nodelist[i];
|
||||
if (el.tagName.toLowerCase() == 'use') {
|
||||
var xlink = el.getAttribute('xlink:href').substr(1);
|
||||
var x = el.getAttribute('x') || 0;
|
||||
var y = el.getAttribute('y') || 0;
|
||||
var el2 = doc.getElementById(xlink).cloneNode(true);
|
||||
var currentTrans = (el.getAttribute('transform') || '') + ' translate(' + x + ', ' + y + ')';
|
||||
for (var j = 0, attrs = el.attributes, l = attrs.length; j < l; j++) {
|
||||
var attr = attrs.item(j);
|
||||
if(attr.nodeName != 'x' && attr.nodeName != 'y' && attr.nodeName != 'xlink:href') {
|
||||
if(attr.nodeName == 'transform') {
|
||||
currentTrans = currentTrans + ' ' + attr.nodeValue;
|
||||
} else {
|
||||
el2.setAttribute(attr.nodeName, attr.nodeValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
el2.setAttribute('transform', currentTrans);
|
||||
el2.removeAttribute('id');
|
||||
var pNode=el.parentNode;
|
||||
pNode.replaceChild(el2, el);
|
||||
}
|
||||
}
|
||||
|
||||
parseUseDirectives(doc);
|
||||
|
||||
var descendants = fabric.util.toArray(doc.getElementsByTagName('*'));
|
||||
|
||||
|
|
@ -447,7 +453,7 @@
|
|||
return reAllowedSVGTagNames.test(el.tagName) &&
|
||||
!hasAncestorWithNodeName(el, /^(?:pattern|defs)$/); // http://www.w3.org/TR/SVG/struct.html#DefsElement
|
||||
});
|
||||
|
||||
|
||||
if (!elements || (elements && !elements.length)) {
|
||||
callback && callback([], {});
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in a new issue