Skip to content

Commit

Permalink
Show error msg on open paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddoc42 committed Aug 30, 2016
1 parent affd20d commit c10a714
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/js/IconManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ class IconManager {
this.errorCallback(errors.ERROR_INVALID_SVG_STRUCTURE);
return;
}
if (!this.isClosedPath(importedPath)) {
this.errorCallback(errors.ERROR_OPEN_PATHS);
}
importedPath.strokeWidth = 0;

// one time base setup
Expand Down Expand Up @@ -390,6 +393,20 @@ class IconManager {
this.loadingOverlay.css('opacity', 1);
}

/**
* Returns true if the path / compound path is closed, false otherwise.
*/
isClosedPath(path) {
if (path instanceof paper.Path) return path.closed;
else if (path instanceof paper.CompoundPath) {
for (let i = 0; i < path.children.length; ++i) {
if (!this.isClosedPath(path.children[i])) return false;
}
return true;
}
return false;
}

}

module.exports = IconManager;
7 changes: 7 additions & 0 deletions app/js/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ module.exports = {
title: 'No path found',
msg_1: 'Make sure that your SVG file looks something like this:',
msg_2: '&lt;svg&gt;&lt;path ... /&gt;&lt;/svg&gt;'
},

// multiple paths etc.
ERROR_OPEN_PATHS: {
title: 'Path must be closed',
msg_1: 'Your icon contains paths that are open but should be closed.',
msg_2: 'Details: https://github.com/Maddoc42/Android-Material-Icon-Generator#custom-svg-file-contains-only-a-single-path-but-no-output-is-generated'
}

};

0 comments on commit c10a714

Please sign in to comment.