mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-04-13 10:50:59 +00:00
Update parser.js
This commit is contained in:
parent
a70321f9a8
commit
eef80ebaf2
1 changed files with 19 additions and 12 deletions
|
|
@ -45,6 +45,9 @@
|
|||
fill: 'fillOpacity'
|
||||
};
|
||||
|
||||
fabric.cssRules = { };
|
||||
fabric.gradientDefs = { };
|
||||
|
||||
function normalizeAttr(attr) {
|
||||
// transform attribute names
|
||||
if (attr in attributesMap) {
|
||||
|
|
@ -349,13 +352,12 @@
|
|||
/**
|
||||
* @private
|
||||
*/
|
||||
function getGlobalStylesForElement(element) {
|
||||
function getGlobalStylesForElement(element, svgUid) {
|
||||
var styles = { };
|
||||
|
||||
for (var rule in fabric.cssRules) {
|
||||
for (var rule in fabric.cssRules[svgUid]) {
|
||||
if (elementMatchesRule(element, rule.split(' '))) {
|
||||
for (var property in fabric.cssRules[rule]) {
|
||||
styles[property] = fabric.cssRules[rule][property];
|
||||
for (var property in fabric.cssRules[svgUid][rule]) {
|
||||
styles[property] = fabric.cssRules[svgUid][rule][property];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -505,7 +507,8 @@
|
|||
if (!doc) {
|
||||
return;
|
||||
}
|
||||
var startTime = new Date();
|
||||
var startTime = new Date(),
|
||||
svgUid = fabric.Object.__uid++;
|
||||
|
||||
parseUseDirectives(doc);
|
||||
/* http://www.w3.org/TR/SVG/struct.html#SVGElementWidthAttribute
|
||||
|
|
@ -560,11 +563,12 @@
|
|||
width: widthAttr ? widthAttr : viewBoxWidth,
|
||||
height: heightAttr ? heightAttr : viewBoxHeight,
|
||||
widthAttr: widthAttr,
|
||||
heightAttr: heightAttr
|
||||
heightAttr: heightAttr,
|
||||
svgUid: svgUid
|
||||
};
|
||||
|
||||
fabric.gradientDefs = fabric.getGradientDefs(doc);
|
||||
fabric.cssRules = fabric.getCSSRules(doc);
|
||||
fabric.gradientDefs[svgUid] = fabric.getGradientDefs(doc);
|
||||
fabric.cssRules[svgUid] = fabric.getCSSRules(doc);
|
||||
// Precedence of rules: style > class > attribute
|
||||
|
||||
fabric.parseElements(elements, function(instances) {
|
||||
|
|
@ -688,7 +692,7 @@
|
|||
* @param {Array} attributes Array of attributes to parse
|
||||
* @return {Object} object containing parsed attributes' names/values
|
||||
*/
|
||||
parseAttributes: function(element, attributes) {
|
||||
parseAttributes: function(element, attributes, svgUid) {
|
||||
|
||||
if (!element) {
|
||||
return;
|
||||
|
|
@ -697,9 +701,12 @@
|
|||
var value,
|
||||
parentAttributes = { };
|
||||
|
||||
if (typeof svgUid === 'undefined') {
|
||||
svgUid = element.getAttribute('svgUid');
|
||||
}
|
||||
// if there's a parent container (`g` or `a` or `symbol` node), parse its attributes recursively upwards
|
||||
if (element.parentNode && /^symbol|[g|a]$/i.test(element.parentNode.nodeName)) {
|
||||
parentAttributes = fabric.parseAttributes(element.parentNode, attributes);
|
||||
parentAttributes = fabric.parseAttributes(element.parentNode, attributes, svgUid);
|
||||
}
|
||||
|
||||
var ownAttributes = attributes.reduce(function(memo, attr) {
|
||||
|
|
@ -716,7 +723,7 @@
|
|||
// add values parsed from style, which take precedence over attributes
|
||||
// (see: http://www.w3.org/TR/SVG/styling.html#UsingPresentationAttributes)
|
||||
ownAttributes = extend(ownAttributes,
|
||||
extend(getGlobalStylesForElement(element), fabric.parseStyleAttribute(element)));
|
||||
extend(getGlobalStylesForElement(element, svgUid), fabric.parseStyleAttribute(element)));
|
||||
|
||||
return _setStrokeFillOpacity(extend(parentAttributes, ownAttributes));
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue