Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
svgicons2svgfont
Advanced tools
The svgicons2svgfont npm package is a tool that converts a set of SVG icons into a single SVG font. This is useful for creating icon fonts that can be used in web development, allowing for scalable and customizable icons.
Convert SVG icons to SVG font
This feature allows you to convert a directory of SVG icons into a single SVG font file. The code sample demonstrates how to read SVG files from a directory, create a font stream, and write the resulting SVG font to a file.
const fs = require('fs');
const SVGIcons2SVGFontStream = require('svgicons2svgfont');
const fontStream = new SVGIcons2SVGFontStream({
fontName: 'myfont'
});
fontStream.pipe(fs.createWriteStream('myfont.svg'))
.on('finish', () => {
console.log('Font successfully created!');
})
.on('error', (err) => {
console.error(err);
});
fs.readdirSync('icons').forEach(file => {
const glyph = fs.createReadStream(`icons/${file}`);
glyph.metadata = { unicode: [String.fromCharCode(0xe001 + i)], name: file.replace('.svg', '') };
fontStream.write(glyph);
});
fontStream.end();
The svg2ttf package converts SVG fonts to TTF (TrueType Font) format. While svgicons2svgfont focuses on creating SVG fonts from individual SVG icons, svg2ttf is used for converting those SVG fonts into TTF format, which is widely supported across different platforms.
Fontello is a tool that allows you to build custom icon fonts from a variety of icon sets. It provides a web interface for selecting icons and generating font files in various formats, including SVG, TTF, and WOFF. Unlike svgicons2svgfont, which is a command-line tool, Fontello offers a more user-friendly, graphical approach.
IcoMoon is another popular tool for creating custom icon fonts. It offers both a web app and a command-line tool for generating icon fonts from SVG icons. IcoMoon provides additional features such as icon set management and the ability to generate multiple font formats, making it a more comprehensive solution compared to svgicons2svgfont.
Read a set of SVG icons and output a SVG font
svgicons2svgfont
is a simple tool to merge multiple icons to an SVG font.
'rect', 'line', 'circle', 'ellipsis', 'polyline' and 'polygon' shapes will be converted to pathes. Multiple pathes will be merged.
Transform attributes support is currenly experimental, report issues if any.
You can test this library with the frontend generator.
You may want to convert fonts to icons, if so use svgfont2svgicons.
import { SVGIcons2SVGFontStream } from 'svgicons2svgfont';
import { createReadStream, createWriteStream } from 'node:fs';
const fontStream = new SVGIcons2SVGFontStream({
fontName: 'hello',
});
// Setting the font destination
fontStream
.pipe(createWriteStream('fonts/hello.svg'))
.on('finish', function () {
console.log('Font successfully created!');
})
.on('error', function (err) {
console.log(err);
});
// Writing glyphs
const glyph1 = createReadStream('icons/icon1.svg');
glyph1.metadata = {
unicode: ['\uE001\uE002'],
name: 'icon1',
};
fontStream.write(glyph1);
// Multiple unicode values are possible
const glyph2 = createReadStream('icons/icon1.svg');
glyph2.metadata = {
unicode: ['\uE002', '\uEA02'],
name: 'icon2',
};
fontStream.write(glyph2);
// Either ligatures are available
const glyph3 = createReadStream('icons/icon1.svg');
glyph3.metadata = {
unicode: ['\uE001\uE002'],
name: 'icon1-icon2',
};
fontStream.write(glyph3);
// Do not forget to end the stream
fontStream.end();
To debug, simply use the following env var: DEBUG=svgicons2svgfont
.
All options are available except the log
one by using this pattern:
--{LOWER_CASE(optionName)}={optionValue}
.
svgicons2svgfont --fontName=hello -o font/destination/file.svg icons/directory/*.svg
Note that you won't be able to customize icon names or icons unicodes by passing
options but by using the following convention to name your icons files:
${icon.unicode}-${icon.name}.svg
where icon.unicode
is a comma separated
list of unicode strings (ex: 'uEA01,uE001,uE001uE002', note that the last string
is in fact a ligature).
There is a few more options for the CLI interface, you can list all of them:
npx svgicons2svgfont --help
Gives:
Usage: svgicons2svgfont [options] <icons ...>
Options:
-V, --version output the version number
-v, --verbose tell me everything!
-o, --output [/dev/stdout] file to write output to
-f, --fontName [value] the font family name you want [iconfont]
-i, --fontId [value] the font id you want [fontName]
-st, --style [value] the font style you want
-we, --weight [value] the font weight you want
-w, --fixedWidth creates a monospace font of the width of the largest input icon
-c, --centerHorizontally calculate the bounds of a glyph and center it horizontally
-y, --centerVertically centers the glyphs vertically in the generated font.
-n, --normalize normalize icons by scaling them to the height of the highest icon
-p, --preserveAspectRatio used with normalize to scale down glyph if the SVG width is greater than the height
-h, --height [value] the output font height [MAX(icons.height)] (icons will be scaled so the highest has
this height)
-r, --round [value] setup the SVG path rounding [10e12]
-d, --descent [value] the font descent [0]
-a, --ascent [value] the font ascent [height - descent]
-s, --startUnicode [value] the start unicode code point for unprefixed files [0xEA01]
-u, --prependUnicode prefix files with their automatically allocated unicode code point
-m, --metadata content of the metadata tag
--help display help for command
Type: String
Default value: 'iconfont'
The font family name you want.
Type: String
Default value: the options.fontName value
The font id you want.
Type: String
Default value: ''
The font style you want.
Type: String
Default value: ''
The font weight you want.
Type: Boolean
Default value: false
Creates a monospace font of the width of the largest input icon.
Type: Boolean
Default value: false
Calculate the bounds of a glyph and center it horizontally.
Type: Boolean
Default value: false
Centers the glyphs vertically in the generated font.
Type: Boolean
Default value: false
Normalize icons by scaling them to the height of the highest icon.
Type: Boolean
Default value: false
Used with normalize to scale down glyph if the SVG width is greater than the height.
Type: Number
Default value: MAX(icons.height)
The outputted font height
(defaults to the height of the highest input icon).
Type: Number
Default value: 10e12
Setup SVG path rounding.
Type: Number
Default value: 0
The font descent. It is usefull to fix the font baseline yourself.
Warning: The descent is a positive value!
Type: Number
Default value: fontHeight - descent
The font ascent. Use this options only if you know what you're doing. A suitable value for this is computed for you.
Type: String
Default value: undefined
The font metadata. You can set any character data in but it is the be suited place for a copyright mention.
Type:
(file: string, cb: (err: any, metadata: {file: string, name: string, unicode: string[], renamed: boolean}) => void
Default value: require('svgicons2svgfont/src/metadata')(options)
A function which determines the metadata for an icon. It takes a parameter
file
with an icon svg and should return icon metadata (asynchronously) via the
callback function. You can use this function to provide custom logic for svg to
codepoint mapping.
metadata.path | The path to the icon file. (The original file param is the file was not moved.) |
metadata.name | The name of the icon |
metadata.unicode | The unicode codepoints corresponding to this glyph. Each should be a 1-codepoint string. |
metadata.renamed | Wether the original file was moved (e.g. to prefix it with its unicode codepoint) |
Type: Function
Default value: console.log
Allows you to provide your own logging function. Set to function(){}
to
disable logging.
grunt-svgicons2svgfont and grunt-webfont.
Try gulp-iconfont and gulp-svgicons2svgfont.
Use stylus-iconfont.
You can combine this plugin's CLI interface with svg2ttf, ttf2eot, ttf2woff and ttf2woff2. You can also use webfonts-generator.
Feel free to push your code if you agree with publishing under the MIT license.
FAQs
Read a set of SVG icons and output a SVG font
The npm package svgicons2svgfont receives a total of 44,219 weekly downloads. As such, svgicons2svgfont popularity was classified as popular.
We found that svgicons2svgfont demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.