Socket
Socket
Sign inDemoInstall

svgicons2svgfont

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svgicons2svgfont - npm Package Compare versions

Comparing version 0.0.10 to 0.0.11

tests/expected/transformedicons.svg

8

package.json
{
"name": "svgicons2svgfont",
"version": "0.0.10",
"version": "0.0.11",
"description": "Read a set of SVG icons and ouput a SVG font",

@@ -25,4 +25,4 @@ "homepage": "https://github.com/nfroidure/svgicons2svgfont",

"sax": "0.6.x",
"svg-pathdata": "0.0.4",
"readable-stream": "^1.0.26-2"
"svg-pathdata": "0.0.5",
"readable-stream": "^1.0.26-4"
},

@@ -33,3 +33,3 @@ "devDependencies": {

"coveralls": "~2.10.0",
"istanbul": "~0.2.6",
"istanbul": "~0.2.7",
"sax": "~0.6.0"

@@ -36,0 +36,0 @@ },

@@ -9,4 +9,3 @@ # svgicons2svgfont

Transform attributes either on 'g' element or path/shapes elements are
currently unsupported.
Transform attributes support is currenly experimental, report issues if any.

@@ -55,3 +54,3 @@ ## Usage

Default value: `MAX(icons.height)`
The ouputted font height (defaults to the height of the highest input icon).
The outputted font height (defaults to the height of the highest input icon).

@@ -58,0 +57,0 @@ ### descent

@@ -13,2 +13,28 @@ /*

// Transform helpers (will move elsewhere later)
function parseTransforms(value) {
return value.match(
/(rotate|translate|scale|skewX|skewY|matrix)\s*\(([^\)]*)\)\s*/g
).map(function(transform) {
return transform.match(/[\w\.\-]+/g);
});
}
function transformPath(path, transforms) {
transforms.forEach(function(transform) {
path[transform[0]].apply(path, transform.slice(1).map(function(n) {
return parseInt(n, 10);
}));
});
return path;
}
function applyTransforms(d, parents) {
var transforms = [];
parents.forEach(function(parent) {
if('undefined' !== typeof parent.attributes.transform) {
transforms = transforms.concat(parseTransforms(parent.attributes.transform));
}
});
return transformPath(new SVGPathData(d), transforms).encode();
}
// Required modules

@@ -92,3 +118,3 @@ var Path = require("path")

} else if('rect' === tag.name) {
glyph.d.push(
glyph.d.push(applyTransforms(
// Move to the left corner

@@ -101,8 +127,8 @@ 'M' + parseFloat(tag.attributes.x || 0,10).toString(10)

+ 'h' + (parseFloat(tag.attributes.width, 10)*-1).toString(10)
+ 'z'
);
+ 'z', parents
));
} else if('line' === tag.name) {
log('Found a line element in the icon "' + glyph.name + '" the result'
+' could be different than expected.');
glyph.d.push(
glyph.d.push(applyTransforms(
// Move to the line start

@@ -117,14 +143,14 @@ 'M' + parseFloat(tag.attributes.x1,10).toString(10)

+ ' ' + parseFloat(tag.attributes.y2,10).toString(10)
+ 'Z'
);
+ 'Z', parents
));
} else if('polyline' === tag.name) {
log('Found a polyline element in the icon "' + glyph.name + '" the'
+' result could be different than expected.');
glyph.d.push(
'M' + tag.attributes.points
);
glyph.d.push(applyTransforms(
'M' + tag.attributes.points, parents
));
} else if('polygon' === tag.name) {
glyph.d.push(
'M' + tag.attributes.points + 'Z'
);
glyph.d.push(applyTransforms(
'M' + tag.attributes.points + 'Z', parents
));
} else if('circle' === tag.name || 'ellipse' === tag.name) {

@@ -137,3 +163,3 @@ var cx = parseFloat(tag.attributes.cx,10)

parseFloat(tag.attributes.ry,10) : parseFloat(tag.attributes.r,10);
glyph.d.push(
glyph.d.push(applyTransforms(
'M' + (cx - rx) + ',' + cy

@@ -152,6 +178,6 @@ + 'C' + (cx - rx) + ',' + (cy + ry*KAPPA)

+ ' ' + (cx - rx) + ',' + cy
+ 'Z'
);
+ 'Z', parents
));
} else if('path' === tag.name && tag.attributes.d) {
glyph.d.push(tag.attributes.d);
glyph.d.push(applyTransforms(tag.attributes.d, parents));
}

@@ -158,0 +184,0 @@ });

@@ -130,2 +130,8 @@ var assert = require('assert')

it("should work with transformed SVG icons", function(done) {
generateFontToFile({
fontName: 'transformedicons'
}, done);
});
});

@@ -132,0 +138,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc