Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'dev'

  • Loading branch information...
commit 3fe6b872bff228aa8c80ecc2a2f99bba563848be 2 parents 81d5201 + 8edb02b
Kir Belevich deepsweet authored
4 CHANGELOG.md
View
@@ -1,3 +1,7 @@
+### [ [>](https://github.com/svg/svgo/tree/v0.1.7) ] 0.1.7 / 08.12.2012
+* plugins/convertPathData: incorrect interpretation of `z + m` (fix [#69](https://github.com/svg/svgo/issues/69))
+* plugins/convertTransform: do a more accurate floating numbers rounding in `matrixToTransform()` (fix [#68](https://github.com/svg/svgo/issues/68))
+
### [ [>](https://github.com/svg/svgo/tree/v0.1.6) ] 0.1.6 / 07.12.2012
* plugins/convertPathData: collapse repeated instructions only after curveSmoothShorthands (fix [#64](https://github.com/svg/svgo/issues/64))
* lib/svgo/coa: handle 'there is nothing to optimize' case and display a message about it (fix [#61](https://github.com/svg/svgo/issues/61))
2  README.md
View
@@ -3,7 +3,7 @@
<img src="http://soulshine.in/svgo/logo.svg?v3" width="200" height="200" alt="logo"/>
-## SVGO v0.1.6 [![Build Status](https://secure.travis-ci.org/svg/svgo.png)](http://travis-ci.org/svg/svgo)
+## SVGO v0.1.7 [![Build Status](https://secure.travis-ci.org/svg/svgo.png)](http://travis-ci.org/svg/svgo)
**SVG O**ptimizer is a Nodejs-based tool for optimizing SVG vector graphics files.
![](//mc.yandex.ru/watch/18431326)
2  README.ru.md
View
@@ -3,7 +3,7 @@
<img src="http://soulshine.in/svgo/logo.svg?v3" width="200" height="200" alt="logo"/>
-## SVGO v0.1.6 [![Build Status](https://secure.travis-ci.org/svg/svgo.png)](http://travis-ci.org/svg/svgo)
+## SVGO v0.1.7 [![Build Status](https://secure.travis-ci.org/svg/svgo.png)](http://travis-ci.org/svg/svgo)
**SVG** **O**ptimizer – это инструмент для оптимизации векторной графики в формате SVG, написанный на Node.js.
![](//mc.yandex.ru/watch/18431326)
2  package.json
View
@@ -1,6 +1,6 @@
{
"name": "svgo",
- "version": "0.1.6",
+ "version": "0.1.7",
"description": "Nodejs-based tool for optimizing SVG vector graphics files",
"keywords": [ "svgo", "svg", "optimize", "minify" ],
"homepage": "http://svg.github.com/svgo/",
34 plugins/convertPathData.js
View
@@ -146,7 +146,8 @@ function convertToRelative(path) {
var instruction,
data,
newPoint,
- point = [0, 0];
+ point = [0, 0],
+ subpathPoint = [0, 0];
path.forEach(function(item) {
@@ -165,6 +166,10 @@ function convertToRelative(path) {
point[0] += newPoint[0];
point[1] += newPoint[1];
+ if (instruction === 'm') {
+ subpathPoint = point.slice(-2);
+ }
+
} else if (instruction === 'h') {
point[0] += data[0];
@@ -177,14 +182,29 @@ function convertToRelative(path) {
// convert absolute path data coordinates to relative
// M → m
+ if (instruction === 'M') {
+
+ if (point[0] !== 0 && point[1] !== 0) {
+ instruction = 'm';
+ }
+
+ // x y
+ // 0 1
+ data[0] -= point[0];
+ data[1] -= point[1];
+
+ point[0] += data[0];
+ point[1] += data[1];
+
+ subpathPoint = point.slice(-2);
+
+ }
+
// L → l
// T → t
- if ('MLT'.indexOf(instruction) > -1) {
+ else if ('LT'.indexOf(instruction) > -1) {
- // don't convert M if point is [0, 0]
- if (instruction !== 'M' || point[0] !== 0 && point[1] !== 0) {
- instruction = instruction.toLowerCase();
- }
+ instruction = instruction.toLowerCase();
// x y
// 0 1
@@ -268,7 +288,7 @@ function convertToRelative(path) {
// !data === z, reset current point
else {
- point = [0, 0];
+ point = subpathPoint;
}
});
30 plugins/convertTransform.js
View
@@ -129,7 +129,7 @@ function convertToShorts(transforms, params) {
transforms.length < 3 &&
transform.name === 'matrix'
) {
- transforms[i] = matrixToTransform(transform);
+ transforms[i] = matrixToTransform(transform, params);
}
// fixed-point numbers
@@ -233,7 +233,7 @@ function collapseIntoOne(transforms, params) {
transforms = transforms.map(function(transform) {
return transform.name === 'martix' ?
transform :
- transformToMatrix(transform);
+ transformToMatrix(transform, params);
});
// multiply all matrices into one
@@ -246,7 +246,7 @@ function collapseIntoOne(transforms, params) {
// and try to get a jackpot
if (params.matrixToTransform) {
- transforms = matrixToTransform(transforms);
+ transforms = matrixToTransform(transforms, params);
}
transforms = [transforms];
@@ -299,24 +299,24 @@ var mth = {
return Math.cos(this.rad(deg));
},
- acos: function(val) {
- return Math.round(this.deg(Math.acos(val)));
+ acos: function(val, floatPrecision) {
+ return +(this.deg(Math.acos(val)).toFixed(floatPrecision));
},
sin: function(deg) {
return Math.sin(this.rad(deg));
},
- asin: function(val) {
- return Math.round(this.deg(Math.asin(val)));
+ asin: function(val, floatPrecision) {
+ return +(this.deg(Math.asin(val)).toFixed(floatPrecision));
},
tan: function(deg) {
return Math.tan(this.rad(deg));
},
- atan: function(val) {
- return Math.round(this.deg(Math.atan(val)));
+ atan: function(val, floatPrecision) {
+ return +(this.deg(Math.atan(val)).toFixed(floatPrecision));
}
};
@@ -371,7 +371,7 @@ function transformToMatrix(transform) {
*
* @return {Object} transform object
*/
-function matrixToTransform(transform) {
+function matrixToTransform(transform, params) {
var data = transform.data;
@@ -402,12 +402,12 @@ function matrixToTransform(transform) {
data[4] === 0 &&
data[5] === 0
) {
- var a1 = mth.acos(data[0]),
- a2 = mth.asin(data[1]);
+ var a1 = mth.acos(data[0], params.floatPrecision),
+ a2 = mth.asin(data[1], params.floatPrecision);
a1 = a2 < 0 ? -a1 : a1;
- if (a1 === a2) {
+ if (Math.round(a1) === Math.round(a2)) {
transform.name = 'rotate';
transform.data = [a1];
}
@@ -421,7 +421,7 @@ function matrixToTransform(transform) {
data[5] === 0
) {
transform.name = 'skewX';
- transform.data = [mth.atan(data[2])];
+ transform.data = [mth.atan(data[2], params.floatPrecision)];
// [1, tan(a), 0, 1, 0, 0] → skewY(a)
} else if (
@@ -432,7 +432,7 @@ function matrixToTransform(transform) {
data[5] === 0
) {
transform.name = 'skewY';
- transform.data = [mth.atan(data[1])];
+ transform.data = [mth.atan(data[1], params.floatPrecision)];
}
return transform;
3  test/plugins/convertPathData.10.orig.svg
View
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg">
+ <path d="m100,200 300,400 z m100,200 L 300,400"/>
+</svg>
3  test/plugins/convertPathData.10.should.svg
View
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg">
+ <path d="m100 200l300 400zm100 200h100"/>
+</svg>
6 test/plugins/convertTransform.03.should.svg
View
@@ -1,8 +1,8 @@
<svg xmlns="http://www.w3.org/2000/svg">
<g transform="translate(50 100)"/>
<g transform="scale(.5 2)"/>
- <g transform="rotate(-45)"/>
- <g transform="skewX(25)"/>
- <g transform="skewY(25)"/>
+ <g transform="rotate(-45.009)"/>
+ <g transform="skewX(24.986)"/>
+ <g transform="skewY(24.986)"/>
<g transform="translate(130 150)"/>
</svg>
Please sign in to comment.
Something went wrong with that request. Please try again.