Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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 1.0.0 to 1.1.0

tests/expected/pathfillnone.svg

2

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

@@ -5,0 +5,0 @@ "homepage": "https://github.com/nfroidure/svgicons2svgfont",

@@ -23,6 +23,9 @@ # svgicons2svgfont

, fs = require('fs');
, fontStream = svgicons2svgfont([
'icons/directory/icon1.svg',
'icons/directory/icon2.svg'
], options);
, fontStream = svgicons2svgfont([{
codepoint: 0xE001,
stream: fs.createReadStream('icons/icon1.svg')
}, {
codepoint: 0xE002,
stream: fs.createReadStream('icons/icon2.svg')
}], options);

@@ -111,9 +114,22 @@ // Saving in a file

Try [gulp-iconfont](https://github.com/nfroidure/gulp-iconfont) and
Try [gulp-iconfont](https://github.com/nfroidure/gulp-iconfont) and
[gulp-svgicons2svgfont](https://github.com/nfroidure/gulp-svgicons2svgfont).
### Stylus plugin
Use [stylus-iconfont](https://www.npmjs.org/package/stylus-iconfont).
### Mimosa plugin
[https://www.npmjs.org/package/mimosa-svgs-to-iconfonts](mimosa-svgs-to-iconfonts)
Use [mimosa-svgs-to-iconfonts](https://www.npmjs.org/package/mimosa-svgs-to-iconfonts).
## CLI alternatives
You can combine this plugin's CLI interface with
[svg2ttf](https://www.npmjs.com/package/),
[ttf2eot](https://www.npmjs.com/package/),
[ttf2woff](https://www.npmjs.com/package/)
and [ttf2woff2](https://www.npmjs.com/package/).
You can also use [webfonts-generator](https://www.npmjs.com/package/webfonts-generator).
## Stats

@@ -120,0 +136,0 @@

@@ -24,3 +24,3 @@ /*

path[transform[0]].apply(path, transform.slice(1).map(function(n) {
return parseInt(n, 10);
return parseFloat(n, 10);
}));

@@ -40,2 +40,60 @@ });

// Shapes helpers (should also move elsewhere)
function rectToPath(attributes) {
var x = 'undefined' !== typeof attributes.x ?
parseFloat(attributes.x, 10) :
0;
var y = 'undefined' !== typeof attributes.y ?
parseFloat(attributes.y, 10) :
0;
var width = 'undefined' !== typeof attributes.width ?
parseFloat(attributes.width, 10) :
0;
var height = 'undefined' !== typeof attributes.height ?
parseFloat(attributes.height, 10) :
0;
var rx = 'undefined' !== typeof attributes.rx ?
parseFloat(attributes.rx, 10) :
0;
var ry = 'undefined' !== typeof attributes.ry ?
parseFloat(attributes.ry, 10) :
0;
return '' +
// start at the left corner
'M' + (x + rx) + ' ' + y +
// top line
'h' + (width - (rx * 2)) +
// upper right corner
( rx || ry ?
'a ' + rx + ' ' + ry + ' 0 0 1 ' + rx + ' ' + ry :
''
) +
// Draw right side
'v' + (height - (ry * 2)) +
// Draw bottom right corner
( rx || ry ?
'a ' + rx + ' ' + ry + ' 0 0 1 ' + (rx * -1) + ' ' + ry :
''
) +
// Down the down side
'h' + ((width - (rx * 2)) * -1) +
// Draw bottom right corner
( rx || ry ?
'a ' + rx + ' ' + ry + ' 0 0 1 ' + (rx * -1) + ' ' + (ry * -1) :
''
) +
// Down the left side
'v' + ((height - (ry * 2)) * -1) +
// Draw bottom right corner
( rx || ry ?
'a ' + rx + ' ' + ry + ' 0 0 1 ' + rx + ' ' + (ry * -1) :
''
) +
// Close path
'z';
}
// Required modules

@@ -119,14 +177,5 @@ var Path = require("path")

// Change rect elements to the corresponding path
} else if('rect' === tag.name) {
glyph.d.push(applyTransforms(
// Move to the left corner
'M' + parseFloat(tag.attributes.x || 0,10).toString(10)
+ ' ' + parseFloat(tag.attributes.y || 0,10).toString(10)
// Draw the rectangle
+ 'h' + parseFloat(tag.attributes.width, 10).toString(10)
+ 'v' + (parseFloat(tag.attributes.height, 10)).toString(10)
+ 'h' + (parseFloat(tag.attributes.width, 10)*-1).toString(10)
+ 'z', parents
));
} else if('line' === tag.name) {
} else if('rect' === tag.name && 'none' !== tag.attributes.fill) {
glyph.d.push(applyTransforms(rectToPath(tag.attributes), parents));
} else if('line' === tag.name && 'none' !== tag.attributes.fill) {
log('Found a line element in the icon "' + glyph.name + '" the result'

@@ -146,3 +195,3 @@ +' could be different than expected.');

));
} else if('polyline' === tag.name) {
} else if('polyline' === tag.name && 'none' !== tag.attributes.fill) {
log('Found a polyline element in the icon "' + glyph.name + '" the'

@@ -153,7 +202,8 @@ +' result could be different than expected.');

));
} else if('polygon' === tag.name) {
} else if('polygon' === tag.name && 'none' !== tag.attributes.fill) {
glyph.d.push(applyTransforms(
'M' + tag.attributes.points + 'Z', parents
));
} else if('circle' === tag.name || 'ellipse' === tag.name) {
} else if('circle' === tag.name || 'ellipse' === tag.name &&
'none' !== tag.attributes.fill) {
var cx = parseFloat(tag.attributes.cx,10)

@@ -181,3 +231,4 @@ , cy = parseFloat(tag.attributes.cy,10)

));
} else if('path' === tag.name && tag.attributes.d) {
} else if('path' === tag.name && tag.attributes.d &&
'none' !== tag.attributes.fill) {
glyph.d.push(applyTransforms(tag.attributes.d, parents));

@@ -279,3 +330,3 @@ }

if('string' !== typeof glyph.name) {
throw Error('Please provide a name for the glyph at index ' + index);
throw new Error('Please provide a name for the glyph at index ' + index);
}

@@ -285,6 +336,6 @@ if(glyphs.some(function(g) {

})) {
throw Error('The glyph name "' + glyph.name + '" must be unique.');
throw new Error('The glyph name "' + glyph.name + '" must be unique.');
}
if('number' !== typeof glyph.codepoint) {
throw Error('Please provide a codepoint for the glyph "' + glyph.name + '"');
throw new Error('Please provide a codepoint for the glyph "' + glyph.name + '"');
}

@@ -294,3 +345,3 @@ if(glyphs.some(function(g) {

})) {
throw Error('The glyph "' + glyph.name
throw new Error('The glyph "' + glyph.name
+ '" codepoint seems to be used already elsewhere.');

@@ -297,0 +348,0 @@ }

@@ -165,2 +165,14 @@ var assert = require('assert')

it("should work with a icons with path with fill none", function(done) {
generateFontToFile({
fontName: 'pathfillnone'
}, done);
});
it("should work with shapes with rounded corners", function(done) {
generateFontToFile({
fontName: 'roundedcorners'
}, done);
});
});

@@ -167,0 +179,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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