UNPKG

9.13 kBMarkdownView Raw
1<!--
2# This file is automatically generated by a `metapak`
3# module. Do not change it elsewhere, changes would
4# be overridden.
5-->
6# svgicons2svgfont
7> Read a set of SVG icons and ouput a SVG font
8
9[![NPM version](https://badge.fury.io/js/svgicons2svgfont.svg)](https://npmjs.org/package/svgicons2svgfont)
10[![Build status](https://secure.travis-ci.org/nfroidure/svgicons2svgfont.svg)](https://travis-ci.org/nfroidure/svgicons2svgfont)
11[![Dependency Status](https://david-dm.org/nfroidure/svgicons2svgfont.svg)](https://david-dm.org/nfroidure/svgicons2svgfont)
12[![devDependency Status](https://david-dm.org/nfroidure/svgicons2svgfont/dev-status.svg)](https://david-dm.org/nfroidure/svgicons2svgfont#info=devDependencies)
13[![Coverage Status](https://coveralls.io/repos/nfroidure/svgicons2svgfont/badge.svg?branch=master)](https://coveralls.io/r/nfroidure/svgicons2svgfont?branch=master)
14[![Code Climate](https://codeclimate.com/github/nfroidure/svgicons2svgfont.svg)](https://codeclimate.com/github/nfroidure/svgicons2svgfont)
15[![Dependency Status](https://dependencyci.com/github/nfroidure/svgicons2svgfont/badge)](https://dependencyci.com/github/nfroidure/svgicons2svgfont)
16
17svgicons2svgfont is a simple tool to merge
18 multiple icons to an SVG font.
19
20'rect', 'line', 'circle', 'ellipsis', 'polyline' and 'polygon' shapes will be
21 converted to pathes. Multiple pathes will be merged.
22
23Transform attributes support is currenly experimental,
24 [report issues if any](https://github.com/nfroidure/svgicons2svgfont/issues/6).
25
26You can test this library with the
27 [frontend generator](http://nfroidure.github.io/svgiconfont/).
28
29You may want to convert fonts to icons, if so use
30 [svgfont2svgicons](https://github.com/nfroidure/svgfont2svgicons).
31
32## Usage
33
34### In your scripts
35```js
36const SVGIcons2SVGFontStream = require('svgicons2svgfont');
37const fs = require('fs');
38const fontStream = new SVGIcons2SVGFontStream({
39 fontName: 'hello'
40});
41
42// Setting the font destination
43fontStream.pipe(fs.createWriteStream('fonts/hello.svg'))
44 .on('finish',function() {
45 console.log('Font successfully created!')
46 })
47 .on('error',function(err) {
48 console.log(err);
49 });
50
51// Writing glyphs
52const glyph1 = fs.createReadStream('icons/icon1.svg');
53glyph1.metadata = {
54 unicode: ['\uE001\uE002'],
55 name: 'icon1'
56};
57fontStream.write(glyph1);
58// Multiple unicode values are possible
59const glyph2 = fs.createReadStream('icons/icon1.svg');
60glyph2.metadata = {
61 unicode: ['\uE002', '\uEA02'],
62 name: 'icon2'
63};
64fontStream.write(glyph2);
65// Either ligatures are available
66const glyph3 = fs.createReadStream('icons/icon1.svg');
67glyph3.metadata = {
68 unicode: ['\uE001\uE002'],
69 name: 'icon1-icon2'
70};
71fontStream.write(glyph3);
72
73// Do not forget to end the stream
74fontStream.end();
75```
76
77## CLI interface
78All options are available except the `log` one by using this pattern:
79 `--{LOWER_CASE(optionName)}={optionValue}`.
80```sh
81svgicons2svgfont --fontname=hello -o font/destination/file.svg icons/directory/*.svg
82```
83Note that you won't be able to customize icon names or icons unicodes by
84 passing options but by using the following convention to name your icons files:
85 `${icon.unicode}-${icon.name}.svg` where `icon.unicode` is a comma separated
86 list of unicode strings (ex: 'uEA01,uE001,uE001uE002', note that the last
87 string is in fact a ligature).
88
89There is a few more options for the CLI interface, you can list all of them:
90```txt
91svgicons2svgfont --help
92# Usage: svgicons2svgfont [options] <icons ...>
93#
94# Options:
95#
96# -V, --version output the version number
97# -v, --verbose tell me everything!
98# -o, --output [/dev/stdout] file to write output to
99# -f, --fontname [value] the font family name you want [iconfont]
100# -i, --fontId [value] the font id you want [fontname]
101# -st, --style [value] the font style you want
102# -we, --weight [value] the font weight you want
103# -w, --fixedWidth creates a monospace font of the width of the largest input icon
104# -c, --centerhorizontally calculate the bounds of a glyph and center it horizontally
105# -n, --normalize normalize icons by scaling them to the height of the highest icon
106# -h, --height [value] the output font height [MAX(icons.height)] (icons will be scaled so the highest has this height)
107# -r, --round [value] setup the SVG path rounding [10e12]
108# -d, --descent [value] the font descent [0]
109# -a, --ascent [value] the font ascent [height - descent]
110# -s, --startunicode [value] the start unicode codepoint for unprefixed files [0xEA01]
111# -a, --prependUnicode prefix files with their automatically allocated unicode code point
112# -m, --metadata content of the metadata tag
113# -h, --help output usage information
114```
115
116## API
117
118### new SVGIcons2SVGFontStream(options)
119
120#### options.fontName
121Type: `String`
122Default value: `'iconfont'`
123
124The font family name you want.
125
126#### options.fontId
127Type: `String`
128Default value: the options.fontName value
129
130The font id you want.
131
132#### options.fontStyle
133Type: `String`
134Default value: `''`
135
136The font style you want.
137
138#### options.fontWeight
139Type: `String`
140Default value: `''`
141
142The font weight you want.
143
144#### options.fixedWidth
145Type: `Boolean`
146Default value: `false`
147
148Creates a monospace font of the width of the largest input icon.
149
150#### options.centerHorizontally
151Type: `Boolean`
152Default value: `false`
153
154Calculate the bounds of a glyph and center it horizontally.
155
156#### options.normalize
157Type: `Boolean`
158Default value: `false`
159
160Normalize icons by scaling them to the height of the highest icon.
161
162#### options.fontHeight
163Type: `Number`
164Default value: `MAX(icons.height)`
165The outputted font height (defaults to the height of the highest input icon).
166
167#### options.round
168Type: `Number`
169Default value: `10e12`
170Setup SVG path rounding.
171
172#### options.descent
173Type: `Number`
174Default value: `0`
175
176The font descent. It is usefull to fix the font baseline yourself.
177
178**Warning:** The descent is a positive value!
179
180#### options.ascent
181Type: `Number`
182Default value: `fontHeight - descent`
183
184The font ascent. Use this options only if you know what you're doing. A suitable
185 value for this is computed for you.
186
187#### options.metadata
188Type: `String`
189Default value: `undefined`
190
191The font [metadata](http://www.w3.org/TR/SVG/metadata.html). You can set any
192 character data in but it is the be suited place for a copyright mention.
193
194#### options.metadataProvider
195Type: `(file: string, cb: (err: any, metadata: {file: string, name: string, unicode: string[], renamed: boolean}) => void`
196
197Default value: `require('svgicons2svgfont/src/metadata')(options)`
198
199A function which determines the metadata for an icon. It takes a parameter `file` with an icon svg and should return
200icon metadata (asynchronously) via the callback function. You can use this function to provide custom logic for svg to
201codepoint mapping.
202
203| | |
204| ------------------ | ---------------------------------------------------------------------------------------- |
205| `metadata.path` | The path to the icon file. (The original `file` param is the file was not moved.) |
206| `metadata.name` | The name of the icon |
207| `metadata.unicode` | The unicode codepoints corresponding to this glyph. Each should be a 1-codepoint string. |
208| `metadata.renamed` | Wether the original file was moved (e.g. to prefix it with its unicode codepoint) |
209
210#### options.log
211Type: `Function`
212Default value: `console.log`
213
214Allows you to provide your own logging function. Set to `function(){}` to
215 disable logging.
216
217## Build systems
218
219### Grunt plugins
220
221[grunt-svgicons2svgfont](https://github.com/nfroidure/grunt-svgicons2svgfont)
222 and [grunt-webfont](https://github.com/sapegin/grunt-webfont).
223
224### Gulp plugins
225
226Try [gulp-iconfont](https://github.com/nfroidure/gulp-iconfont) and
227 [gulp-svgicons2svgfont](https://github.com/nfroidure/gulp-svgicons2svgfont).
228
229### Stylus plugin
230
231Use [stylus-iconfont](https://www.npmjs.org/package/stylus-iconfont).
232
233### Mimosa plugin
234
235Use [mimosa-svgs-to-iconfonts](https://www.npmjs.org/package/mimosa-svgs-to-iconfonts).
236
237## CLI alternatives
238
239You can combine this plugin's CLI interface with
240 [svg2ttf](https://www.npmjs.com/package/svg2ttf),
241 [ttf2eot](https://www.npmjs.com/package/ttf2eot),
242 [ttf2woff](https://www.npmjs.com/package/ttf2woff)
243 and [ttf2woff2](https://www.npmjs.com/package/ttf2woff2).
244You can also use [webfonts-generator](https://www.npmjs.com/package/webfonts-generator).
245
246## Stats
247
248[![NPM](https://nodei.co/npm/svgicons2svgfont.png?downloads=true&stars=true)](https://nodei.co/npm/svgicons2svgfont/)
249[![NPM](https://nodei.co/npm-dl/svgicons2svgfont.png)](https://nodei.co/npm/svgicons2svgfont/)
250
251## Contributing
252Feel free to push your code if you agree with publishing under the MIT license.
253
254# License
255[MIT](https://github.com/nfroidure/svgicons2svgfont/blob/master/LICENSE)