mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
Implement PathItem.create(pathData)
determining if the data describes a plain path or a compound-path with multiple sub-paths.
This commit is contained in:
parent
9f9222f416
commit
21033f7850
2 changed files with 19 additions and 10 deletions
|
@ -27,6 +27,24 @@ var PathItem = Item.extend(/** @lends PathItem# */{
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
},
|
},
|
||||||
|
|
||||||
|
statics: /** @lends PathItem */{
|
||||||
|
/**
|
||||||
|
* Creates a path item from the given SVG path-data, determining if the
|
||||||
|
* data describes a plain path or a compound-path with multiple
|
||||||
|
* sub-paths.
|
||||||
|
*
|
||||||
|
* @param {String} pathData the SVG path-data to parse
|
||||||
|
* @return {Path|CompoundPath} the newly created path item
|
||||||
|
*/
|
||||||
|
create: function(pathData) {
|
||||||
|
// If there are multiple moveTo commands or a closePath command
|
||||||
|
// followed by other commands, we have a CompoundPath.
|
||||||
|
var ctor = (pathData && pathData.match(/m/gi) || []).length > 1
|
||||||
|
|| /z\s*\S+/i.test(pathData) ? CompoundPath : Path;
|
||||||
|
return new ctor(pathData);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
_asPathItem: function() {
|
_asPathItem: function() {
|
||||||
// See Item#_asPathItem()
|
// See Item#_asPathItem()
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -135,16 +135,7 @@ new function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function importPath(node) {
|
function importPath(node) {
|
||||||
// Get the path data, and determine whether it is a compound path or a
|
return PathItem.create(node.getAttribute('d'));
|
||||||
// normal path based on the amount of moveTo commands inside it.
|
|
||||||
var data = node.getAttribute('d'),
|
|
||||||
param = { pathData: data };
|
|
||||||
// If there are multiple moveTo commands or a closePath command followed
|
|
||||||
// by other commands, we have a CompoundPath:
|
|
||||||
// TODO: PathItem.create()?
|
|
||||||
return (data && data.match(/m/gi) || []).length > 1 || /z\b/i.test(data)
|
|
||||||
? new CompoundPath(param)
|
|
||||||
: new Path(param);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function importGradient(node, type) {
|
function importGradient(node, type) {
|
||||||
|
|
Loading…
Reference in a new issue