diff options
author | Paulo F. Silva <paulo@pjfs.pt> | 2016-03-02 17:02:02 +0000 |
---|---|---|
committer | Paulo F. Silva <paulo@pjfs.pt> | 2016-03-02 17:02:02 +0000 |
commit | 4856081d28f08979b33405da399fac424ea2a350 (patch) | |
tree | 546e72ff2d3eaeb4394dea38f3db4262cd999632 | |
parent | dcbc4d4a3e74abc50e84aaeb549da63971e13120 (diff) | |
download | svg.js-4856081d28f08979b33405da399fac424ea2a350.tar.gz svg.js-4856081d28f08979b33405da399fac424ea2a350.zip |
Backports commit dd7cc2f5104d488b0ba85366e14fae57edb767b7 to v1.x branch
-rw-r--r-- | src/patharray.js | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/src/patharray.js b/src/patharray.js index 6a1c72c..d778fbf 100644 --- a/src/patharray.js +++ b/src/patharray.js @@ -13,15 +13,16 @@ SVG.extend(SVG.PathArray, { } // Move path string , move: function(x, y) { - /* get bounding box of current situation */ - var box = this.bbox() + // get bounding box of current situation + var box = this.bbox() /* get relative offset */ x -= box.x y -= box.y + // get relative offset if (!isNaN(x) && !isNaN(y)) { - /* move every point */ + // move every point for (var l, i = this.value.length - 1; i >= 0; i--) { l = this.value[i][0] @@ -58,10 +59,10 @@ SVG.extend(SVG.PathArray, { } // Resize path string , size: function(width, height) { - /* get bounding box of current situation */ - var i, l, box = this.bbox() + // get bounding box of current situation + var i, l, box = this.bbox() - /* recalculate position of all points according to new size */ + // recalculate position of all points according to new size for (i = this.value.length - 1; i >= 0; i--) { l = this.value[i][0] @@ -87,11 +88,11 @@ SVG.extend(SVG.PathArray, { } } else if (l == 'A') { - /* resize radii */ + // resize radii this.value[i][1] = (this.value[i][1] * width) / box.width this.value[i][2] = (this.value[i][2] * height) / box.height - /* move position values */ + // move position values this.value[i][6] = ((this.value[i][6] - box.x) * width) / box.width + box.x this.value[i][7] = ((this.value[i][7] - box.y) * height) / box.height + box.y } @@ -128,6 +129,17 @@ SVG.extend(SVG.PathArray, { }, []) } + // at this place there could be parts like ['3.124.854.32'] because we could not determine the point as seperator till now + // we fix this elements in the next loop + for(i = 0; i < array.length; ++i){ + if(array[i].indexOf('.') != array[i].lastIndexOf('.')){ + var split = array[i].split('.') // split at the point + var first = [split.shift(), split.shift()].join('.') // join the first number together + array.splice.apply(array, [i, 1].concat(first, split.map(function(el){ return '.'+el }))) // add first and all other entries back to array + i += split.length // dont forget to update the index + } + } + // array now is an array containing all parts of a path e.g. ['M', '0', '0', 'L', '30', '30' ...] var arr = [] @@ -228,4 +240,4 @@ SVG.extend(SVG.PathArray, { return SVG.parser.path.getBBox() } -})
\ No newline at end of file +}) |