Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'dev'

  • Loading branch information...
commit 2810d43aeae5dff3b1e5ef3f189dcc07900256f8 2 parents a529e27 + 09c0a8c
@deepsweet deepsweet authored
View
5 CHANGELOG.md
@@ -1,3 +1,8 @@
+### [ [>](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
+* plugins/transformsWithOnePath: ability to set new width or height independently with auto rescaling
+
### [ [>](https://github.com/svg/svgo/tree/v0.3.2) ] 0.3.2 / 03.05.2013
* new plugin [plugins/sortAttrs](https://github.com/svg/svgo/blob/master/plugins/sortAttrs.js)
* plugins/transformsWithOnePath: buggy hcrop (fix [#111](https://github.com/svg/svgo/issues/111))
View
2  package.json
@@ -1,6 +1,6 @@
{
"name": "svgo",
- "version": "0.3.2",
+ "version": "0.3.3",
"description": "Nodejs-based tool for optimizing SVG vector graphics files",
"keywords": [ "svgo", "svg", "optimize", "minify" ],
"homepage": "http://svg.github.com/svgo/",
View
21 plugins/convertPathData.js
@@ -84,7 +84,8 @@ function convertToRelative(path) {
newPoint,
point = [0, 0],
subpathPoint = [0, 0],
- index = 0;
+ index = 0,
+ mM = false;
path.forEach(function(item) {
@@ -106,6 +107,11 @@ function convertToRelative(path) {
point[1] += newPoint[1];
if (instruction === 'm') {
+ if (index === 1) {
+ instruction = 'M';
+ mM = true;
+ }
+
subpathPoint = point.slice(-2);
}
@@ -127,13 +133,16 @@ function convertToRelative(path) {
instruction = 'm';
}
- data[0] -= point[0];
- data[1] -= point[1];
+ // if "M" was not transformed from "m"
+ if (!mM) {
+ data[0] -= point[0];
+ data[1] -= point[1];
- point[0] += data[0];
- point[1] += data[1];
+ point[0] += data[0];
+ point[1] += data[1];
- subpathPoint = point.slice(-2);
+ subpathPoint = point.slice(-2);
+ }
}
View
75 plugins/transformsWithOnePath.js
@@ -211,42 +211,52 @@ exports.fn = function(data, params) {
ymax = Math.max.apply(this, ys).toFixed(params.floatPrecision),
svgWidth = +svgElem.attr('width').value,
svgHeight = +svgElem.attr('height').value,
- realWidth = Math.ceil(xmax - xmin),
- realHeight = Math.ceil(ymax - ymin),
+ realWidth = Math.round(xmax - xmin),
+ realHeight = Math.round(ymax - ymin),
centerX = realWidth / 2,
centerY = realHeight / 2,
transform = '',
scale;
- // hcrop
- if (params.hcrop) {
- transform += ' translate(' + (-xmin) + ' 0)';
-
- svgElem.attr('width').value = realWidth;
- }
-
+ // width & height
if (params.width && params.height) {
+
scale = Math.min(params.width / svgWidth, params.height / svgHeight);
+ realWidth = realWidth * scale;
+ realHeight = realHeight * scale;
+
svgElem.attr('width').value = params.width;
svgElem.attr('height').value = params.height;
transform += ' scale(' + scale + ')';
- }
- // vcenter
- if (params.vcenter) {
- transform += ' translate(0 ' + (((svgHeight - realHeight) / 2) - ymin) + ')';
- }
+ // width
+ } else if (params.width && !params.height) {
- // scale
- if (params.scale) {
- scale = params.scale;
+ scale = params.width / svgWidth;
+
+ realWidth = realWidth * scale;
+ realHeight = realHeight * scale;
+
+ svgElem.attr('width').value = params.width;
+ svgElem.attr('height').value = svgHeight * scale;
+
+ transform += ' scale(' + scale + ')';
+
+ // height
+ } else if (params.height && !params.width) {
+
+ scale = params.height / svgHeight;
realWidth = realWidth * scale;
realHeight = realHeight * scale;
- transform += ' translate(' + (-centerX * (scale - 1)) + ', ' + (-centerY * (scale - 1)) + ') scale(' + scale + ')';
+ svgElem.attr('width').value = svgWidth * scale;
+ svgElem.attr('height').value = params.height;
+
+ transform += ' scale(' + scale + ')';
+
}
// shiftX
@@ -263,6 +273,35 @@ exports.fn = function(data, params) {
transform += ' translate(0, ' + realHeight * shiftY + ')';
}
+ // scale
+ if (params.scale) {
+ scale = params.scale;
+
+ realWidth = realWidth * scale;
+ realHeight = realHeight * scale;
+
+ centerX = realWidth / 2;
+ centerY = realHeight / 2;
+
+ if (params.shiftX || params.shiftY) {
+ transform += ' scale(' + scale + ')';
+ } else {
+ transform += ' translate(' + (-centerX * (scale - 1)) + ', ' + (-centerY * (scale - 1)) + ') scale(' + scale + ')';
+ }
+ }
+
+ // hcrop
+ if (params.hcrop) {
+ transform += ' translate(' + (-xmin) + ' 0)';
+
+ svgElem.attr('width').value = realWidth;
+ }
+
+ // vcenter
+ if (params.vcenter) {
+ transform += ' translate(0 ' + (((svgHeight - realHeight) / 2) - ymin) + ')';
+ }
+
if (transform) {
pathElem.addAttr({
View
2  test/plugins/convertPathData.07.svg
@@ -11,7 +11,7 @@
@@@
<svg xmlns="http://www.w3.org/2000/svg">
- <path d="m0 0"/>
+ <path d="M0 0"/>
<path d=""/>
<path d=""/>
<path d=""/>
View
2  test/plugins/convertPathData.10.svg
@@ -5,5 +5,5 @@
@@@
<svg xmlns="http://www.w3.org/2000/svg">
- <path d="m100 200l300 400zm100 200h100"/>
+ <path d="M100 200l300 400zm100 200h100"/>
</svg>
Please sign in to comment.
Something went wrong with that request. Please try again.