Browse files

Merge branch 'dev'

  • Loading branch information...
2 parents 9555bcb + 6d2ce70 commit 81d52012675f1caa4aad0f5e7dd99cb04be6608d @deepsweet deepsweet committed Dec 7, 2012
Showing with 85 additions and 96 deletions.
  1. +6 −0 CHANGELOG.md
  2. +1 −1 README.md
  3. +1 −1 README.ru.md
  4. +30 −22 lib/svgo/coa.js
  5. +1 −1 package.json
  6. +0 −51 plugins/cleanupSVGElem.js
  7. +46 −20 plugins/convertPathData.js
View
6 CHANGELOG.md
@@ -1,3 +1,9 @@
+### [ [>](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))
+* plugins/cleanupSVGElem: delete as useless artefact
+
+
### [ [>](https://github.com/svg/svgo/tree/v0.1.5) ] 0.1.5 / 06.12.2012
* E-notated numbers in paths not recognised (fix [#63](https://github.com/svg/svgo/issues/63))
* update README with `svgo-grunt` and `svgo-osx-folder-action`
View
2 README.md
@@ -3,7 +3,7 @@
<img src="http://soulshine.in/svgo/logo.svg?v3" width="200" height="200" alt="logo"/>
-## SVGO v0.1.5 [![Build Status](https://secure.travis-ci.org/svg/svgo.png)](http://travis-ci.org/svg/svgo)
+## SVGO v0.1.6 [![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)
View
2 README.ru.md
@@ -3,7 +3,7 @@
<img src="http://soulshine.in/svgo/logo.svg?v3" width="200" height="200" alt="logo"/>
-## SVGO v0.1.5 [![Build Status](https://secure.travis-ci.org/svg/svgo.png)](http://travis-ci.org/svg/svgo)
+## SVGO v0.1.6 [![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)
View
52 lib/svgo/coa.js
@@ -133,35 +133,43 @@ module.exports = require('coa').Cmd()
return svgo.then(function(result) {
- // --datauri
- if (opts.datauri) {
- // convert to Data URI base64 string
- result.data = encodeSVGDatauri(result.data);
- }
+ if (result.info.outBytes >= result.info.inBytes) {
- // stdout
- if (output === '-' || (input === '-' && !output)) {
- process.stdout.write(result.data + '\n');
- }
+ UTIL.puts('\nThere is nothing to optimize!\n');
- // file
- else {
+ } else {
- // if input is from file - overwrite it
- if (!output && input) {
- output = input;
+ // --datauri
+ if (opts.datauri) {
+ // convert to Data URI base64 string
+ result.data = encodeSVGDatauri(result.data);
}
- // output file
- output = FS.createWriteStream(output, { encoding: 'utf8' });
- output.write(result.data);
- output.end();
+ // stdout
+ if (output === '-' || (input === '-' && !output)) {
+ process.stdout.write(result.data + '\n');
+ }
- // print time info
- printTimeInfo(startTime, Date.now());
+ // file
+ else {
+
+ // if input is from file - overwrite it
+ if (!output && input) {
+ output = input;
+ }
- // print optimization profit info
- printProfitInfo(result.info.inBytes, result.info.outBytes);
+ // output file
+ output = FS.createWriteStream(output, { encoding: 'utf8' });
+ output.write(result.data);
+ output.end();
+
+ // print time info
+ printTimeInfo(startTime, Date.now());
+
+ // print optimization profit info
+ printProfitInfo(result.info.inBytes, result.info.outBytes);
+
+ }
}
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "svgo",
- "version": "0.1.5",
+ "version": "0.1.6",
"description": "Nodejs-based tool for optimizing SVG vector graphics files",
"keywords": [ "svgo", "svg", "optimize", "minify" ],
"homepage": "http://svg.github.com/svgo/",
View
51 plugins/cleanupSVGElem.js
@@ -1,51 +0,0 @@
-'use strict';
-
-/**
- * Remove some useless svg element attributes.
- *
- * @see http://www.w3.org/TR/SVG/struct.html#SVGElement
- *
- * @param {Object} item current iteration item
- * @param {Object} params plugin params
- * @return {Boolean} if false, item will be filtered out
- *
- * @author Kir Belevich
- */
-exports.cleanupSVGElem = function(item, params) {
-
- if (item.isElem('svg') && item.attrs) {
-
- /**
- * Remove id attribute.
- *
- * @see http://www.w3.org/TR/SVG/struct.html#IDAttribute
- *
- * @example
- * <svg id="svg49">
- */
- if (params.id) item.removeAttr('id');
-
- /**
- * Remove version attribute.
- *
- * @see http://www.w3.org/TR/SVG/struct.html#SVGElementVersionAttribute
- *
- * @example
- * <svg version="1.1">
- */
- if (params.version) item.removeAttr('version');
-
- /**
- * Remove xnl:space attribute.
- *
- * @see http://www.w3.org/TR/SVG/struct.html#XMLSpaceAttribute
- *
- * @example
- * <svg xml:space="preserve">
- */
- // TODO: remove as a default value
- if (params.xmlspace) item.removeAttr('xml:space');
-
- }
-
-};
View
66 plugins/convertPathData.js
@@ -35,6 +35,8 @@ exports.convertPathData = function(item, params) {
data = filters(data, params);
+ data = collapseRepeated(data, params);
+
item.attr('d').value = js2path(data, params);
}
@@ -496,41 +498,65 @@ function filters(path, params) {
}
- // collapse repeated instructions data
+ item.instruction = instruction;
+ item.data = data;
+
+ prev = {
+ item: item,
+ point: point.slice(0)
+ };
+
+ }
+
+ return true;
+
+ });
+
+ return path;
+
+}
+
+// collapse repeated instructions data
+/**
+ * Collapse repeated instructions data
+ *
+ * @param {Array} path input path data
+ * @param {Object} params plugin params
+ *
+ * @return {Array} output path data
+ */
+function collapseRepeated(path, params) {
+
+ if (params.collapseRepeated) {
+
+ var prev;
+
+ path = path.filter(function(item) {
+
if (
- params.collapseRepeated &&
!hasMarkerMid &&
- prev.item &&
- instruction === prev.item.instruction
+ prev &&
+ item.instruction === prev.instruction
) {
// increase previous h or v data with current
- if (instruction === 'h' || instruction === 'v') {
- prev.item.data[0] += data[0];
+ if (item.instruction === 'h' || item.instruction === 'v') {
+ prev.data[0] += item.data[0];
// concat previous data with current
} else {
- prev.item.data = prev.item.data.concat(data);
+ prev.data = prev.data.concat(item.data);
}
- // if there was an original then remove it because of the new data
- delete prev.item.original;
-
// filter current item
return false;
}
- item.instruction = instruction;
- item.data = data;
-
- prev = {
- item: item,
- point: point.slice(0)
- };
+ prev = item;
- }
+ return true;
- return true;
+ });
- });
+ }
return path;

0 comments on commit 81d5201

Please sign in to comment.