From e0009020ed402583b5469b10fcca2137c761c186 Mon Sep 17 00:00:00 2001 From: adroitwhiz Date: Fri, 8 Nov 2019 20:51:15 -0500 Subject: [PATCH] Don't apply undefined styles in exportSVG --- src/svg/SvgExport.js | 6 ++++++ src/svg/SvgImport.js | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/svg/SvgExport.js b/src/svg/SvgExport.js index 672f2f8f..2c8c5b4d 100644 --- a/src/svg/SvgExport.js +++ b/src/svg/SvgExport.js @@ -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) || diff --git a/src/svg/SvgImport.js b/src/svg/SvgImport.js index 9b97668b..a94fc8e2 100644 --- a/src/svg/SvgImport.js +++ b/src/svg/SvgImport.js @@ -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) {