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 3.2.0 to 3.2.1

src/svgshapes2svgpath.js

6

bin/svgicons2svgfont.js

@@ -35,3 +35,3 @@ #! /usr/bin/env node

if(!program.args.length) {
console.error('No icons specified!');
console.error('No icons specified!'); // eslint-disable-line
process.exit(1);

@@ -43,3 +43,3 @@ }

appendUnicode: program.appendunicode,
log: program.v ? console.log : function() {},
log: program.v ? console.log : function() {}, // eslint-disable-line
})

@@ -57,4 +57,4 @@ .pipe(svgicons2svgfont({

metadata: program.metadata,
log: program.v ? console.log : function() {},
log: program.v ? console.log : function() {}, // eslint-disable-line
}))
.pipe(program.output ? fs.createWriteStream(program.output) : process.stdout);
{
"name": "svgicons2svgfont",
"version": "3.2.0",
"version": "3.2.1",
"description": "Read a set of SVG icons and ouput a SVG font",

@@ -12,3 +12,3 @@ "homepage": "https://github.com/nfroidure/svgicons2svgfont",

"lint": "eslint src/*.js bin/*.js tests/*.js",
"prepublish": "npm run test",
"preversion": "npm run lint && npm run test",
"cli": "env NPM_RUN_CLI=1"

@@ -31,16 +31,16 @@ },

"dependencies": {
"commander": "^2.8.1",
"readable-stream": "^2.0.2",
"sax": "^1.1.2",
"commander": "^2.9.0",
"readable-stream": "^2.0.4",
"sax": "^1.1.4",
"string.fromcodepoint": "^0.2.1",
"string.prototype.codepointat": "^0.2.0",
"svg-pathdata": "^1.0.1"
"svg-pathdata": "^1.0.3"
},
"devDependencies": {
"coveralls": "^2.11.4",
"eslint": "^1.4.0",
"eslint": "^1.10.0",
"eslint-config-simplifield": "^1.1.0",
"istanbul": "^0.3.19",
"mocha": "^2.3.2",
"mocha-lcov-reporter": "^0.0.2",
"istanbul": "^0.4.0",
"mocha": "^2.3.4",
"mocha-lcov-reporter": "^1.0.0",
"streamtest": "^1.2.1"

@@ -52,8 +52,3 @@ },

},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/nfroidure/svgicons2svgfont/blob/master/LICENSE"
}
],
"license": "MIT",
"bugs": {

@@ -60,0 +55,0 @@ "url": "https://github.com/nfroidure/svgicons2svgfont/issues"

@@ -20,2 +20,3 @@ 'use strict';

var gotFilesInfos = false;
var dirCopy;

@@ -28,3 +29,3 @@ // Ensure new were used

if(dir instanceof Array) {
var dirCopy = dir;
dirCopy = dir;
dir = '';

@@ -31,0 +32,0 @@ _getFilesInfos(dirCopy);

@@ -0,1 +1,3 @@

/* eslint no-multi-str:0 */
'use strict';

@@ -5,5 +7,7 @@

var util = require('util');
var ucs2 = require('punycode').ucs2;
var Stream = require('readable-stream');
var Sax = require('sax');
var SVGPathData = require('svg-pathdata');
var svgShapesToPath = require('./svgshapes2svgpath');

@@ -41,2 +45,4 @@ require('string.prototype.codepointat');

function tagShouldRender(curTag, parents) {
var values;
return !parents.some(function(tag) {

@@ -56,3 +62,3 @@ if('undefined' !== typeof tag.attributes.display &&

if('undefined' !== typeof tag.attributes.viewBox) {
var values = tag.attributes.viewBox.split(/\s*,*\s|\s,*\s*|,/);
values = tag.attributes.viewBox.split(/\s*,*\s|\s,*\s*|,/);
if(0 === parseFloat(values[2]) || 0 === parseFloat(values[3])) {

@@ -65,111 +71,2 @@ return true;

// 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';
}
function polylineToPath(attributes) {
return 'M' + attributes.points;
}
function lineToPath(attributes) {
// Move to the line start
return '' +
'M' + (parseFloat(attributes.x1, 10) || 0).toString(10) +
' ' + (parseFloat(attributes.y1, 10) || 0).toString(10) +
' ' + ((parseFloat(attributes.x1, 10) || 0) + 1).toString(10) +
' ' + ((parseFloat(attributes.y1, 10) || 0) + 1).toString(10) +
' ' + ((parseFloat(attributes.x2, 10) || 0) + 1).toString(10) +
' ' + ((parseFloat(attributes.y2, 10) || 0) + 1).toString(10) +
' ' + (parseFloat(attributes.x2, 10) || 0).toString(10) +
' ' + (parseFloat(attributes.y2, 10) || 0).toString(10) +
'Z';
}
// http://www.whizkidtech.redprince.net/bezier/circle/
var KAPPA = ((Math.sqrt(2) - 1) / 3) * 4;
function circleToPath(attributes) {
var cx = parseFloat(attributes.cx, 10);
var cy = parseFloat(attributes.cy, 10);
var rx = 'undefined' !== typeof attributes.rx ?
parseFloat(attributes.rx, 10) :
parseFloat(attributes.r, 10);
var ry = 'undefined' !== typeof attributes.ry ?
parseFloat(attributes.ry, 10) :
parseFloat(attributes.r, 10);
return '' +
'M' + (cx - rx) + ',' + cy +
'C' + (cx - rx) + ',' + (cy + (ry * KAPPA)) +
' ' + (cx - (rx * KAPPA)) + ',' + (cy + ry) +
' ' + cx + ',' + (cy + ry) +
'C' + (cx + (rx * KAPPA)) + ',' + (cy + ry) +
' ' + (cx + rx) + ',' + (cy + (ry * KAPPA)) +
' ' + (cx + rx) + ',' + cy +
'C' + (cx + rx) + ',' + (cy - (ry * KAPPA)) +
' ' + (cx + (rx * KAPPA)) + ',' + (cy - ry) +
' ' + cx + ',' + (cy - ry) +
'C' + (cx - (rx * KAPPA)) + ',' + (cy - ry) +
' ' + (cx - rx) + ',' + (cy - (ry * KAPPA)) +
' ' + (cx - rx) + ',' + cy +
'Z';
}
function polygonToPath(attributes) {
return 'M' + attributes.points + 'Z';
}
// Inherit of duplex stream

@@ -192,3 +89,3 @@ util.inherits(SVGIcons2SVGFontStream, Stream.Transform);

log = options.log || console.log.bind(console);
log = options.log || console.log.bind(console); // eslint-disable-line

@@ -253,2 +150,4 @@ // Ensure new were used

saxStream.on('opentag', function(tag) {
var values;
parents.push(tag);

@@ -265,3 +164,3 @@ // Checking if any parent rendering is disabled and exit if so

if('viewBox' in tag.attributes) {
var values = tag.attributes.viewBox.split(/\s*,*\s|\s,*\s*|,/);
values = tag.attributes.viewBox.split(/\s*,*\s|\s,*\s*|,/);
glyph.dX = parseFloat(values[0], 10);

@@ -291,16 +190,16 @@ glyph.dY = parseFloat(values[1], 10);

} else if('rect' === tag.name && 'none' !== tag.attributes.fill) {
glyph.d.push(applyTransforms(rectToPath(tag.attributes), parents));
glyph.d.push(applyTransforms(svgShapesToPath.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' +
' could be different than expected.');
glyph.d.push(applyTransforms(lineToPath(tag.attributes), parents));
glyph.d.push(applyTransforms(svgShapesToPath.lineToPath(tag.attributes), parents));
} else if('polyline' === tag.name && 'none' !== tag.attributes.fill) {
log('Found a polyline element in the icon "' + glyph.name + '" the' +
' result could be different than expected.');
glyph.d.push(applyTransforms(polylineToPath(tag.attributes), parents));
glyph.d.push(applyTransforms(svgShapesToPath.polylineToPath(tag.attributes), parents));
} else if('polygon' === tag.name && 'none' !== tag.attributes.fill) {
glyph.d.push(applyTransforms(polygonToPath(tag.attributes), parents));
glyph.d.push(applyTransforms(svgShapesToPath.polygonToPath(tag.attributes), parents));
} else if('circle' === tag.name || 'ellipse' === tag.name &&
'none' !== tag.attributes.fill) {
glyph.d.push(applyTransforms(circleToPath(tag.attributes), parents));
glyph.d.push(applyTransforms(svgShapesToPath.circleToPath(tag.attributes), parents));
} else if('path' === tag.name && tag.attributes.d &&

@@ -366,3 +265,4 @@ 'none' !== tag.attributes.fill) {

<?xml version="1.0" standalone="no"?> \n\
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >\n\
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"' +
' "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >\n\
<svg xmlns="http://www.w3.org/2000/svg">\n' + (

@@ -382,2 +282,4 @@ options.metadata ? '<metadata>' + options.metadata + '</metadata>\n' : ''

var d = '';
var bounds;
var pathData;

@@ -406,4 +308,4 @@ if(options.fixedWidth) {

// Naive bounds calculation (should draw, then calculate bounds...)
var pathData = new SVGPathData(d);
var bounds = {
pathData = new SVGPathData(d);
bounds = {
x1: Infinity,

@@ -438,4 +340,4 @@ y1: Infinity,

<glyph glyph-name="' + glyph.name + (0 === i ? '' : '-' + i) + '"\n\
unicode="' + unicode.split('').map(function(char) {
return '&#x' + char.codePointAt(0).toString(16).toUpperCase() + ';';
unicode="' + ucs2.decode(unicode).map(function(point) {
return '&#x' + point.toString(16).toUpperCase() + ';';
}).join('') + '"\n\

@@ -450,3 +352,5 @@ horiz-adv-x="' + glyph.width + '" d="' + d + '" />\n');

log('Font created');
'function' === (typeof options.callback) && (options.callback)(glyphs);
if('function' === (typeof options.callback)) {
(options.callback)(glyphs);
}
svgFontFlushCallback();

@@ -453,0 +357,0 @@ };

@@ -18,4 +18,4 @@ 'use strict';

0xEA01;
options.log = options.log || console.log;
options.err = options.err || console.err;
options.log = options.log || console.log; // eslint-disable-line
options.err = options.err || console.err; // eslint-disable-line

@@ -22,0 +22,0 @@ return function getMetadataFromFile(file, cb) {

@@ -13,3 +13,3 @@ 'use strict';

// Helpers
function generateFontToFile(options, done, fileSuffix, startUnicode, files) {
function generateFontToFile(options, done, fileSuffix, startUnicode, files) { // eslint-disable-line
var dest = path.join(__dirname, 'results', options.fontName +

@@ -353,5 +353,5 @@ (fileSuffix || '') + '.svg');

describe('Using multiple unicode values for a single icon', function() {
describe('Passing code points', function() {
it('should work', function(done) {
it('should work with multiple unicode values for a single icon', function(done) {
var svgIconStream = fs.createReadStream(

@@ -386,7 +386,3 @@ path.join(__dirname, 'fixtures', 'cleanicons', 'account.svg')

});
describe('Using ligatures', function() {
it('should work', function(done) {
it('should work with ligatures', function(done) {
var svgIconStream = fs.createReadStream(

@@ -420,2 +416,33 @@ path.join(__dirname, 'fixtures', 'cleanicons', 'account.svg')

it('should work with high code points', function(done) {
var ucs2 = require('punycode').ucs2;
var svgIconStream = fs.createReadStream(
path.join(__dirname, 'fixtures', 'cleanicons', 'account.svg')
);
var svgFontStream = svgicons2svgfont();
var content = '';
var decoder = new StringDecoder('utf8');
svgIconStream.metadata = {
name: 'account',
unicode: [ucs2.encode([0x1F63A])],
};
svgFontStream.on('data', function(chunk) {
content += decoder.write(chunk);
});
svgFontStream.on('finish', function() {
assert.equal(
fs.readFileSync(path.join(__dirname, 'expected', 'cleanicons-high.svg'),
{ encoding: 'utf8' }),
content
);
done();
});
svgFontStream.write(svgIconStream);
svgFontStream.end();
});
});

@@ -422,0 +449,0 @@

@@ -0,1 +1,3 @@

/* eslint max-nested-callbacks:0 */
'use strict';

@@ -2,0 +4,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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