Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
deepsweet committed Dec 8, 2012
2 parents 81d5201 + 8edb02b commit 3fe6b87
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -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))
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion README.ru.md
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -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/",
Expand Down
34 changes: 27 additions & 7 deletions plugins/convertPathData.js
Expand Up @@ -146,7 +146,8 @@ function convertToRelative(path) {
var instruction,
data,
newPoint,
point = [0, 0];
point = [0, 0],
subpathPoint = [0, 0];

path.forEach(function(item) {

Expand All @@ -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];
Expand All @@ -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
Expand Down Expand Up @@ -268,7 +288,7 @@ function convertToRelative(path) {

// !data === z, reset current point
else {
point = [0, 0];
point = subpathPoint;
}

});
Expand Down
30 changes: 15 additions & 15 deletions plugins/convertTransform.js
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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];
Expand Down Expand Up @@ -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));
}

};
Expand Down Expand Up @@ -371,7 +371,7 @@ function transformToMatrix(transform) {
*
* @return {Object} transform object
*/
function matrixToTransform(transform) {
function matrixToTransform(transform, params) {

var data = transform.data;

Expand Down Expand Up @@ -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];
}
Expand All @@ -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 (
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions test/plugins/convertPathData.10.orig.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions test/plugins/convertPathData.10.should.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions test/plugins/convertTransform.03.should.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3fe6b87

Please sign in to comment.