Merge pull request #28 from adroitwhiz/dont-export-undef-llk

Don't apply undefined styles in exportSVG + handle invalid fill-rule in importer
This commit is contained in:
DD Liu 2020-05-06 16:45:21 -04:00 committed by GitHub
commit 112047f5ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View file

@ -304,6 +304,12 @@ new function() {
var get = entry.get,
type = entry.type,
value = item[get]();
// In some cases, the style's value is undefined. Trying to save it
// will result in erroneous behavior; for instance, properties like
// "fill-rule" will have the invalid value of "none" if undefined.
if (value === undefined) return;
if (entry.exportFilter
? entry.exportFilter(item, value)
: !parent || !Base.equals(parent[get](), value) ||

View file

@ -531,7 +531,14 @@ new function() {
if (matrix)
group.transform(matrix);
}
}
},
'fill-rule': function(item, value) {
// Sometimes, the fill-rule attribute will be set to "none" due to a paper.js bug.
// This is coerced into a `null`. A null `fillRule` will cause certain operaions to error out.
// So, only set the fill rule if it's one of the two valid options: "evenodd" and "nonzero".
if (value === 'evenodd' || value === 'nonzero') item.fillRule = value;
}
});
function getAttribute(node, name, styles) {