Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SVG paths allow the implicit commands if multiple parameters are used.

Converting this to individual commands at the parse step so they're easier to work with once parsed.
  • Loading branch information...
commit ed1c0ec2df692c4d58c6153aa4bcdfd850cc5a04 1 parent 016dbfc
@sebmarkbage sebmarkbage authored
Showing with 21 additions and 4 deletions.
  1. +21 −4 Source/ART.Path.js
View
25 Source/ART.Path.js
@@ -12,15 +12,32 @@ requires: ART
/* private functions */
+var parameterCount = {
+ l: 2, z: 0,
+ h: 1, v: 1,
+ c: 6, s: 4,
+ q: 4, t: 2,
+ a: 7
+};
+
var parse = function(path){
var parts = [], index = -1,
- bits = path.match(/[a-df-z]|[\-+]?(?:[\d\.]e[\-+]?|[^\s\-+,a-z])+/ig);
+ bits = path.match(/[a-df-z]|[\-+]?(?:[\d\.]e[\-+]?|[^\s\-+,a-z])+/ig),
+ command, part, paramCount = 0;
for (var i = 0, l = bits.length; i < l; i++){
var bit = bits[i];
- if (bit.match(/^[a-z]/i)) parts[++index] = [bit];
- else parts[index].push(Number(bit));
+ if (bit.match(/^[a-z]/i)){
+ command = bit;
+ parts[++index] = part = [command];
+ if (command == 'm') command = 'l';
+ else if (command == 'M') command = 'L';
+ paramCount = parameterCount[command.toLowerCase()];
+ } else {
+ if (part.length > paramCount) parts[++index] = part = [command];
+ part.push(Number(bit));
+ }
}
return parts;
@@ -333,4 +350,4 @@ ART.Path = new Class({
ART.Path.prototype.toString = ART.Path.prototype.toSVG;
-})();
+})();
Please sign in to comment.
Something went wrong with that request. Please try again.