1 | # webfont
|
2 |
|
3 | [![NPM version](https://img.shields.io/npm/v/webfont.svg)](https://www.npmjs.org/package/webfont)
|
4 | [![Travis Build Status](https://img.shields.io/travis/itgalaxy/webfont/master.svg?label=build)](https://travis-ci.org/itgalaxy/webfont)
|
5 | [![Build status](https://ci.appveyor.com/api/projects/status/a8absovr2r44w1oc?svg=true)](https://ci.appveyor.com/project/evilebottnawi/webfont)
|
6 | [![Greenkeeper badge](https://badges.greenkeeper.io/itgalaxy/webfont.svg)](https://greenkeeper.io/)
|
7 | [![dependencies Status](https://david-dm.org/itgalaxy/webfont/status.svg)](https://david-dm.org/itgalaxy/webfont)
|
8 | [![devDependencies Status](https://david-dm.org/itgalaxy/webfont/dev-status.svg)](https://david-dm.org/itgalaxy/webfont?type=dev)
|
9 |
|
10 | Generator of font from SVG icons.
|
11 |
|
12 | Features:
|
13 |
|
14 | - Supported font formats: WOFF2, WOFF, EOT, TTF and SVG.
|
15 |
|
16 | - Support configuration Files - use a JavaScript, JSON or YAML file to specify configuration information
|
17 | for an entire directory and all of its subdirectories.
|
18 |
|
19 | - Supported browsers: IE8+.
|
20 |
|
21 | - Generates CSS files allows to use custom templates.
|
22 |
|
23 | - CLI.
|
24 |
|
25 | ## Install
|
26 |
|
27 | ```shell
|
28 | npm install --save-dev webfont
|
29 | ```
|
30 |
|
31 | ## Usage
|
32 |
|
33 | ```js
|
34 | const webfont = require('webfont').default
|
35 |
|
36 | webfont({
|
37 | files: 'src/svg-icons/**/*.svg',
|
38 | fontName: 'my-font-name'
|
39 | })
|
40 | .then((result) => {
|
41 | console.log(result);
|
42 | });
|
43 | ```
|
44 |
|
45 | Or
|
46 |
|
47 | ```js
|
48 | import webfont from 'webfont';
|
49 |
|
50 | webfont({
|
51 | files: 'src/svg-icons/**/*.svg',
|
52 | fontName: 'my-font-name'
|
53 | })
|
54 | .then((result) => {
|
55 | console.log(result);
|
56 | });
|
57 | ```
|
58 |
|
59 | ## Options
|
60 |
|
61 | ### `files`
|
62 |
|
63 | A file glob, or array of file globs.
|
64 | Ultimately passed to [node-glob](https://github.com/isaacs/node-glob) to figure out what files you want to lint.
|
65 |
|
66 | `node_modules` and `bower_components` are always ignored.
|
67 |
|
68 | ### `configFile`
|
69 |
|
70 | A `webfont` configuration object.
|
71 |
|
72 | ### `fontName`
|
73 |
|
74 | Type: `String`
|
75 | Default: `webfont`
|
76 |
|
77 | The font family name you want.
|
78 |
|
79 | ### `formats`
|
80 |
|
81 | Type: `Array`
|
82 | Default value: `['svg', 'ttf', 'eot', 'woff', 'woff2']`
|
83 | Possible values: `svg, ttf, eot, woff, woff2`.
|
84 |
|
85 | Font file types to generate.
|
86 |
|
87 | ### `template`
|
88 |
|
89 | Type: `string`
|
90 | Default: `null`
|
91 |
|
92 | Possible values: `css`, `scss` (feel free to contribute). If you want to use custom template use this option.
|
93 | Example: `template: path.resolve(__dirname, './my-template.css')`.
|
94 |
|
95 | ### `cssTemplateClassName`
|
96 |
|
97 | Type: `string`
|
98 | Default: `null`
|
99 |
|
100 | Default font class name.
|
101 |
|
102 | ### `cssTemplateFontPath`
|
103 |
|
104 | Type: `string`
|
105 | Default: `./`
|
106 |
|
107 | Path to generated fonts in the `CSS` file.
|
108 |
|
109 | ### `cssTemplateFontName`
|
110 |
|
111 | Type: `string`
|
112 |
|
113 | Default value getting from `fontName` options, but you can specify any value.
|
114 |
|
115 | ### `glyphTransformFn`
|
116 |
|
117 | Type: `function`
|
118 | Default: `null`
|
119 |
|
120 | If you need transform glyph metadata (e.g. titles of CSS classes) before transferred in style template
|
121 | for your icons, you can use this option with glyphs metadata object.
|
122 |
|
123 | Example:
|
124 |
|
125 | ```js
|
126 | glyphTransformFn: (obj) => {
|
127 | obj.name += '_transform';
|
128 | }
|
129 | ```
|
130 |
|
131 | ### `fontId`
|
132 |
|
133 | ### `fontStyle`
|
134 |
|
135 | ### `fontWeight`
|
136 |
|
137 | ### `fixedWidth`
|
138 |
|
139 | ### `centerHorizontally`
|
140 |
|
141 | ### `normalize`
|
142 |
|
143 | ### `fontHeight`
|
144 |
|
145 | ### `round`
|
146 |
|
147 | ### `descent`
|
148 |
|
149 | ### `ascent`
|
150 |
|
151 | ### `startUnicode`
|
152 |
|
153 | ### `prependUnicode`
|
154 |
|
155 | Options that are passed directly to [svgicons2svgfont](https://github.com/nfroidure/svgicons2svgfont).
|
156 | Option `fontName` for `svgicons2svgfont` taken from above `fontName` argument.
|
157 |
|
158 | ## Command Line Interface
|
159 |
|
160 | The interface for command-line usage is fairly simplistic at this stage, as seen in the following usage section.
|
161 |
|
162 | ### Usage
|
163 |
|
164 | `webfont --help` prints the CLI documentation.
|
165 |
|
166 | ### Options
|
167 |
|
168 | ```bash
|
169 | Generator of fonts from svg icons, svg icons to svg font, svg font to ttf, ttf to eot, ttf to woff, ttf to woff2
|
170 |
|
171 | Usage
|
172 | $ webfont [input] [options]
|
173 |
|
174 | Input
|
175 | Files(s) or glob(s).
|
176 | If an input argument is wrapped in quotation marks, it will be passed to node-glob
|
177 | for cross-platform glob support.
|
178 |
|
179 | Options
|
180 | --config Path to a specific configuration file (JSON, YAML, or CommonJS)
|
181 | or the name of a module in `node_modules` that points to one.
|
182 | If no `--config` argument is provided, webfont will search for
|
183 | configuration files in the following places, in this order:
|
184 | - a `webfont` property in `package.json`
|
185 | - a `.webfontrc` file (with or without filename extension:
|
186 | `.json`, `.yaml`, and `.js` are available)
|
187 | - a `webfont.config.js` file exporting a JS object
|
188 | The search will begin in the working directory and move up the
|
189 | directory tree until a configuration file is found.
|
190 | -f, --font-name The font family name you want, default: "webfont".
|
191 | -h, --help Output usage information.
|
192 | -v, --version Output the version number.
|
193 | -r, --formats Only this formats generate.
|
194 | -d, --dest Destination for generated fonts (directory).
|
195 | -t, --template Type of styles ('css', 'scss') or path to custom template.
|
196 | -s, --dest-styles Destination for generated styles (directory). If not passed used `dest` argument.
|
197 | -c, --css-template-class-name Class name in css template.
|
198 | -p, --css-template-font-path Font path in css template.
|
199 | -n, --css-template-font-name Font name in css template.
|
200 | --verbose Tell me everything!.
|
201 |
|
202 | For "svgicons2svgfont":
|
203 | --font-id The font id you want, default as "--font-name".
|
204 | --font-style The font style you want.
|
205 | --font-weight The font weight you want.
|
206 | --fixed-width Creates a monospace font of the width of the largest input icon.
|
207 | --center-horizontally Calculate the bounds of a glyph and center it horizontally.
|
208 | --normalize Normalize icons by scaling them to the height of the highest icon.
|
209 | --font-height The outputted font height [MAX(icons.height)].
|
210 | --round Setup the SVG path rounding [10e12].
|
211 | --descent The font descent [0].
|
212 | --ascent The font ascent [height - descent].
|
213 | --start-unicode The start unicode codepoint for unprefixed files [0xEA01].
|
214 | --prepend-unicode Prefix files with their automatically allocated unicode codepoint.
|
215 | --metadata Content of the metadata tag.
|
216 | ```
|
217 |
|
218 | ### Exit codes
|
219 |
|
220 | The CLI can exit the process with the following exit codes:
|
221 |
|
222 | - 0: All ok.
|
223 | - 1: Something unknown went wrong.
|
224 | - Other: related to using packages.
|
225 |
|
226 | ## Related
|
227 |
|
228 | - [svgicons2svgfont](https://github.com/nfroidure/svgicons2svgfont) - Simple tool to merge multiple
|
229 | icons to an SVG font.
|
230 |
|
231 | - [svg2ttf](https://github.com/fontello/svg2ttf) - Converts SVG fonts to TTF format.
|
232 |
|
233 | - [ttf2eot](https://github.com/fontello/ttf2eot) - Converts TTF fonts to EOT format.
|
234 |
|
235 | - [ttf2woff](https://github.com/fontello/ttf2woff) - Converts TTF fonts to WOFF format.
|
236 |
|
237 | - [ttf2woff2](https://github.com/nfroidure/ttf2woff2) - Converts TTF fonts to WOFF2.
|
238 |
|
239 | ## Roadmap
|
240 |
|
241 | - The ability to generate from any type to any type.
|
242 | - Rewrite on ecma6, without `babel` compilation.
|
243 | - More tests, include CLI test.
|
244 | - Option `glyphTransformFn` should return object, not change passed.
|
245 | - Improved docs.
|
246 | - Reduce package size (maybe implement `ttf2woff2` with native js library).
|
247 | - Improve performance (maybe use cache for this).
|
248 | - Implement `webpack` loader.
|
249 | - Close all issues.
|
250 |
|
251 | ## Contribution
|
252 |
|
253 | Feel free to push your code if you agree with publishing under the MIT license.
|
254 |
|
255 | ## [Changelog](CHANGELOG.md)
|
256 |
|
257 | ## [License](LICENSE)
|