Permalink
Browse files

Merge branch 'dev'

  • Loading branch information...
2 parents 2810d43 + fe136d3 commit 2e42deab6eb49a0c8d2edebe452d84079d425d75 @deepsweet deepsweet committed May 6, 2013
Showing with 78 additions and 84 deletions.
  1. +5 −0 CHANGELOG.md
  2. +1 −1 package.json
  3. +0 −6 plugins/_path.js
  4. +26 −33 plugins/convertPathData.js
  5. +9 −2 plugins/mergePaths.js
  6. +35 −41 plugins/transformsWithOnePath.js
  7. +2 −1 test/plugins/mergePaths.01.svg
View
@@ -1,3 +1,8 @@
+### [ [>](https://github.com/svg/svgo/tree/v0.3.4) ] 0.3.4 / 06.05.2013
+* plugins/convertPathData: fix m->M bug in some cases
+* plugins/transformsWithOnePath: fix last point calculation for C/S/Q/T
+* plugins/mergePaths: add space delimiter between z and m
+
### [ [>](https://github.com/svg/svgo/tree/v0.3.3) ] 0.3.3 / 05.05.2013
* plugins/convertPathData: convert very first m to M, fix applyTransforms with translate() (fix [#112](https://github.com/svg/svgo/issues/112))
* plugins/transformsWithOnePath: fix real width/height rounding; fix scale transform origin; reorder transforms
View
@@ -1,6 +1,6 @@
{
"name": "svgo",
- "version": "0.3.3",
+ "version": "0.3.4",
"description": "Nodejs-based tool for optimizing SVG vector graphics files",
"keywords": [ "svgo", "svg", "optimize", "minify" ],
"homepage": "http://svg.github.com/svgo/",
View
@@ -192,7 +192,6 @@ exports.applyTransforms = function(elem, path) {
) {
var matrix = transformsMultiply(transform2js(elem.attr('transform').value)),
- currentPoint = [0, 0],
newPoint;
path.forEach(function(pathItem) {
@@ -239,11 +238,6 @@ exports.applyTransforms = function(elem, path) {
}
- currentPoint[0] += pathItem.data[pathItem.data.length - 2];
- currentPoint[1] += pathItem.data[pathItem.data.length - 1];
-
- pathItem.point = currentPoint.slice(0);
-
}
});
@@ -228,13 +228,13 @@ function convertToRelative(path) {
item.instruction = instruction;
item.data = data;
- item.point = point.slice(0);
}
// !data === z, reset current point
else {
point = subpathPoint;
+ mM = false;
}
});
@@ -254,16 +254,12 @@ function filters(path, params) {
var instruction,
data,
- point = [0, 0],
- prev = {
- point: [0, 0]
- };
+ prev;
path = path.filter(function(item) {
instruction = item.instruction;
data = item.data;
- point = item.point;
if (data) {
@@ -303,7 +299,7 @@ function filters(path, params) {
// q
else if (
- prev.item &&
+ prev &&
instruction === 'q' &&
isCurveStraightLine(
[ 0, data[0], data[2] ],
@@ -324,24 +320,24 @@ function filters(path, params) {
// q (original) + t
if (
- prev.item &&
- prev.item.original &&
- prev.item.original.instruction === 'q'
+ prev &&
+ prev.original &&
+ prev.original.instruction === 'q'
) {
if (isCurveStraightLine(
- [ prev.item.original.data[0], prev.item.original.data[2], data[0] ],
- [ prev.item.original.data[1], prev.item.original.data[3], data[1] ]
+ [ prev.original.data[0], prev.original.data[2], data[0] ],
+ [ prev.original.data[1], prev.original.data[3], data[1] ]
)) {
instruction = 'l';
data = data.slice(-2);
} else {
- prev.item.instruction = 'q';
- prev.item.data = prev.item.original.data;
+ prev.instruction = 'q';
+ prev.data = prev.original.data;
}
}
// [^qt] + t
- else if (!prev.item || 'qt'.indexOf(prev.item.instruction) === -1) {
+ else if (!prev || 'qt'.indexOf(prev.instruction) === -1) {
instruction = 'l';
data = data.slice(-2);
}
@@ -375,34 +371,34 @@ function filters(path, params) {
}
// convert curves into smooth shorthands
- if (params.curveSmoothShorthands && prev.item) {
+ if (params.curveSmoothShorthands && prev) {
// curveto
if (instruction === 'c') {
// c + c → c + s
if (
- prev.item.instruction === 'c' &&
- data[0] === -(prev.item.data[2] - prev.item.data[4]) &&
- data[1] === -(prev.item.data[3] - prev.item.data[5])
+ prev.instruction === 'c' &&
+ data[0] === -(prev.data[2] - prev.data[4]) &&
+ data[1] === -(prev.data[3] - prev.data[5])
) {
instruction = 's';
data = data.slice(2);
}
// s + c → s + s
else if (
- prev.item.instruction === 's' &&
- data[0] === -(prev.item.data[0] - prev.item.data[2]) &&
- data[1] === -(prev.item.data[1] - prev.item.data[3])
+ prev.instruction === 's' &&
+ data[0] === -(prev.data[0] - prev.data[2]) &&
+ data[1] === -(prev.data[1] - prev.data[3])
) {
instruction = 's';
data = data.slice(2);
}
// [^cs] + c → [^cs] + s
else if (
- 'cs'.indexOf(prev.item.instruction) === -1 &&
+ 'cs'.indexOf(prev.instruction) === -1 &&
data[0] === 0 &&
data[1] === 0
) {
@@ -417,19 +413,19 @@ function filters(path, params) {
// q + q → q + t
if (
- prev.item.instruction === 'q' &&
- data[0] === (prev.item.data[2] - prev.item.data[0]) &&
- data[1] === (prev.item.data[3] - prev.item.data[1])
+ prev.instruction === 'q' &&
+ data[0] === (prev.data[2] - prev.data[0]) &&
+ data[1] === (prev.data[3] - prev.data[1])
) {
instruction = 't';
data = data.slice(2);
}
// t + q → t + t
else if (
- prev.item.instruction === 't' &&
- data[2] === prev.item.data[0] &&
- data[3] === prev.item.data[1]
+ prev.instruction === 't' &&
+ data[2] === prev.data[0] &&
+ data[3] === prev.data[1]
) {
instruction = 't';
data = data.slice(2);
@@ -466,10 +462,7 @@ function filters(path, params) {
item.instruction = instruction;
item.data = data;
- prev = {
- item: item,
- point: point.slice(0)
- };
+ prev = item;
}
View
@@ -16,7 +16,8 @@ exports.fn = function(item) {
if (item.isElem() && !item.isEmpty()) {
- var prevContentItem;
+ var prevContentItem,
+ delim = '';
item.content = item.content.filter(function(contentItem) {
@@ -30,7 +31,13 @@ exports.fn = function(item) {
contentItem.hasAttr('d') &&
Object.keys(contentItem.attrs).length === 1
) {
- prevContentItem.attr('d').value += contentItem.attr('d').value;
+ // "zM", but "z m"
+ // looks like a FontForge parsing bug
+ if (contentItem.attr('d').value.charAt(0) === 'm') {
+ delim = ' ';
+ }
+
+ prevContentItem.attr('d').value += delim + contentItem.attr('d').value;
return false;
}
Oops, something went wrong.

0 comments on commit 2e42dea

Please sign in to comment.