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.3 to 0.0.4

tests/expected/originalicons2.svg

2

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

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

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

svgicons2svgfont [![Build Status](https://travis-ci.org/nfroidure/svgicons2svgfont.png?branch=master)](https://travis-ci.org/nfroidure/svgicons2svgfont)
============
# svgicons2svgfont [![Build Status](https://travis-ci.org/nfroidure/svgicons2svgfont.png?branch=master)](https://travis-ci.org/nfroidure/svgicons2svgfont)
svgicons2svgfont is a simple tool to merge multiple icons to an SVG font.

@@ -11,4 +11,3 @@

Usage
-------------
## Usage
NodeJS module:

@@ -35,3 +34,21 @@ ```js

[Grunt plugin](https://github.com/nfroidure/grunt-svgicons2svgfont):
## Options (not plugged to CLI yet)
### fontName : String
The font family name you want (defaults to 'iconfont').
### fixedWidth : Boolean
Creates a monospace font of the width of the largest input icon (defaults to
false).
### fontHeight : Boolean
The ouputted font height (defaults to the height of the highest input icon).
### descent : Number
The font descent (defaults to 0). It is usefull to fix the font baseline yourself.
The ascent formula is : ascent = fontHeight - descent.
# [Grunt plugin](https://github.com/nfroidure/grunt-svgicons2svgfont):
```sh

@@ -41,5 +58,4 @@ npm install grunt-svgicons2svgfont

Contributing
-------------
## Contributing
Feel free to pull your code if you agree with publishing under the MIT license.

@@ -16,3 +16,2 @@ /*

, Stream = require("stream").PassThrough
, Fs = require("fs")
, Sax = require("sax")

@@ -24,2 +23,4 @@ , SVGPathData = require("svg-pathdata");

options.fontName = options.fontName || 'iconfont';
options.fixedWidth = options.fixedWidth || false;
options.descent = options.descent || 0;
var outputStream = new Stream()

@@ -110,5 +111,9 @@ , log = (options.log || console.log.bind(console))

})) {
var fontHeight = (glyphs.length > 1 ? glyphs.reduce(function (gA, gB) {
return Math.max(gA.height || gA, gB.height || gB);
}) : glyphs[0].height);
var fontWidth = (glyphs.length > 1 ? glyphs.reduce(function (gA, gB) {
return Math.max(gA.width || gA, gB.width || gB);
}) : glyphs[0].width)
, fontHeight = options.fontHeight ||
(glyphs.length > 1 ? glyphs.reduce(function (gA, gB) {
return Math.max(gA.height || gA, gB.height || gB);
}) : glyphs[0].height);
if(fontHeight>(glyphs.length > 1 ? glyphs.reduce(function (gA, gB) {

@@ -126,4 +131,6 @@ return Math.min(gA.height || gA, gB.height || gB);

<defs>\n\
<font id="' + options.fontName + '" horiz-adv-x="' + fontHeight + '">\n\
<font-face units-per-em="' + fontHeight + '" ascent="' + fontHeight + '" descent="0" />\n\
<font id="' + options.fontName + '" horiz-adv-x="' + fontWidth + '">\n\
<font-face font-family="' + options.fontName + '"\n\
units-per-em="' + fontHeight + '" ascent="' + (fontHeight - options.descent) + '"\n\
descent="' + options.descent + '" />\n\
<missing-glyph horiz-adv-x="0" />\n');

@@ -140,3 +147,3 @@ glyphs.forEach(function(glyph) {

unicode="&#x' + (glyph.codepoint.toString(16)).toUpperCase() + ';"\n\
horiz-adv-x="' + glyph.width + '" d="' + d +'" />\n');
horiz-adv-x="' + (options.fixedWidth ? fontWidth : glyph.width) + '" d="' + d +'" />\n');
});

@@ -143,0 +150,0 @@ outputStream.write('\

@@ -8,5 +8,6 @@ var assert = require('assert')

// Helpers
function generateFontToFile(options, done) {
function generateFontToFile(options, done, fileSuffix) {
var codepoint = 0xE001
, dest = __dirname + '/results/' + options.fontName + '.svg'
, dest = __dirname + '/results/' + options.fontName
+ (fileSuffix || '') + '.svg'
, stream = svgicons2svgfont(Fs.readdirSync(__dirname + '/fixtures/' + options.fontName)

@@ -23,3 +24,4 @@ .map(function(file) {

assert.equal(
Fs.readFileSync(__dirname + '/expected/' + options.fontName + '.svg',
Fs.readFileSync(__dirname + '/expected/' + options.fontName
+ (fileSuffix || '') + '.svg',
{encoding: 'utf8'}),

@@ -134,2 +136,27 @@ Fs.readFileSync(dest,

describe('Using options', function() {
it("should work with fixedWidth option set to true", function(done) {
generateFontToFile({
fontName: 'originalicons',
fixedWidth: true
}, done, '2');
});
it("should work with custom fontHeight option", function(done) {
generateFontToFile({
fontName: 'originalicons',
fontHeight: 800
}, done, '3');
});
it("should work with custom descent option", function(done) {
generateFontToFile({
fontName: 'originalicons',
descent: 200
}, done, '4');
});
});
describe('Testing CLI', function() {

@@ -136,0 +163,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

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