svgo
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -0,1 +1,6 @@ | ||
### [ [>](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 | ||
@@ -2,0 +7,0 @@ * new plugin [plugins/sortAttrs](https://github.com/svg/svgo/blob/master/plugins/sortAttrs.js) |
{ | ||
"name": "svgo", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": "Nodejs-based tool for optimizing SVG vector graphics files", | ||
@@ -5,0 +5,0 @@ "keywords": [ "svgo", "svg", "optimize", "minify" ], |
@@ -87,3 +87,4 @@ 'use strict'; | ||
subpathPoint = [0, 0], | ||
index = 0; | ||
index = 0, | ||
mM = false; | ||
@@ -110,2 +111,7 @@ path.forEach(function(item) { | ||
if (instruction === 'm') { | ||
if (index === 1) { | ||
instruction = 'M'; | ||
mM = true; | ||
} | ||
subpathPoint = point.slice(-2); | ||
@@ -132,9 +138,12 @@ } | ||
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); | ||
} | ||
@@ -141,0 +150,0 @@ } |
@@ -214,4 +214,4 @@ 'use strict'; | ||
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, | ||
@@ -222,12 +222,10 @@ centerY = realHeight / 2, | ||
// hcrop | ||
if (params.hcrop) { | ||
transform += ' translate(' + (-xmin) + ' 0)'; | ||
// width & height | ||
if (params.width && params.height) { | ||
svgElem.attr('width').value = realWidth; | ||
} | ||
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; | ||
@@ -237,12 +235,7 @@ 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; | ||
@@ -252,3 +245,20 @@ realWidth = realWidth * scale; | ||
transform += ' translate(' + (-centerX * (scale - 1)) + ', ' + (-centerY * (scale - 1)) + ') scale(' + 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; | ||
svgElem.attr('width').value = svgWidth * scale; | ||
svgElem.attr('height').value = params.height; | ||
transform += ' scale(' + scale + ')'; | ||
} | ||
@@ -270,2 +280,31 @@ | ||
// 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) { | ||
@@ -272,0 +311,0 @@ |
217642
6255