Skip to content

Commit 112047f

Browse files
authored
Merge pull request #28 from adroitwhiz/dont-export-undef-llk
Don't apply undefined styles in exportSVG + handle invalid fill-rule in importer
2 parents dcb612e + e000902 commit 112047f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/svg/SvgExport.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,12 @@ new function() {
304304
var get = entry.get,
305305
type = entry.type,
306306
value = item[get]();
307+
308+
// In some cases, the style's value is undefined. Trying to save it
309+
// will result in erroneous behavior; for instance, properties like
310+
// "fill-rule" will have the invalid value of "none" if undefined.
311+
if (value === undefined) return;
312+
307313
if (entry.exportFilter
308314
? entry.exportFilter(item, value)
309315
: !parent || !Base.equals(parent[get](), value) ||

src/svg/SvgImport.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,14 @@ new function() {
531531
if (matrix)
532532
group.transform(matrix);
533533
}
534-
}
534+
},
535+
536+
'fill-rule': function(item, value) {
537+
// Sometimes, the fill-rule attribute will be set to "none" due to a paper.js bug.
538+
// This is coerced into a `null`. A null `fillRule` will cause certain operaions to error out.
539+
// So, only set the fill rule if it's one of the two valid options: "evenodd" and "nonzero".
540+
if (value === 'evenodd' || value === 'nonzero') item.fillRule = value;
541+
}
535542
});
536543

537544
function getAttribute(node, name, styles) {

0 commit comments

Comments
 (0)