aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/patharray.js30
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
+})