@hibi_10000/grunt-webfont 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/License.md +24 -0
- package/Readme.md +695 -0
- package/bin/eotlitetool.py +474 -0
- package/bin/fontforge/generate.py +133 -0
- package/dist/engines/fontforge.js +84 -0
- package/dist/engines/fontforge.js.map +1 -0
- package/dist/engines/node.js +164 -0
- package/dist/engines/node.js.map +1 -0
- package/dist/package.js +105 -0
- package/dist/package.js.map +1 -0
- package/dist/types.d.ts +158 -0
- package/dist/util/util.js +105 -0
- package/dist/util/util.js.map +1 -0
- package/dist/webfont.d.ts +8 -0
- package/dist/webfont.js +609 -0
- package/dist/webfont.js.map +1 -0
- package/package.json +86 -0
- package/tasks/engines/fontforge.ts +124 -0
- package/tasks/engines/node.ts +213 -0
- package/tasks/engines/nodedeps.d.ts +22 -0
- package/tasks/types.ts +169 -0
- package/tasks/util/util.ts +119 -0
- package/tasks/webfont.ts +833 -0
- package/templates/bem.css +56 -0
- package/templates/bem.json +4 -0
- package/templates/bootstrap.css +114 -0
- package/templates/bootstrap.json +4 -0
- package/templates/demo.html +97 -0
- package/tsconfig.json +31 -0
package/License.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
===============
|
|
3
|
+
|
|
4
|
+
Copyright © 2025 Hibi_10000
|
|
5
|
+
Copyright © 2014 Artem Sapegin, http://sapegin.me
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
8
|
+
a copy of this software and associated documentation files (the
|
|
9
|
+
'Software'), to deal in the Software without restriction, including
|
|
10
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
11
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
12
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
13
|
+
the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be
|
|
16
|
+
included in all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
20
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
21
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
22
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
23
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
24
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/Readme.md
ADDED
|
@@ -0,0 +1,695 @@
|
|
|
1
|
+
# SVG to webfont converter for Grunt
|
|
2
|
+
|
|
3
|
+
<!-- [](http://sapegin.github.io/powered-by-you/) -->
|
|
4
|
+
[](https://github.com/Hibi-10000/grunt-webfont/actions/workflows/test.yml)
|
|
5
|
+
[](https://github.com/Hibi-10000/grunt-webfont/actions/workflows/publish.yml)
|
|
6
|
+
[](https://www.npmjs.com/package/@hibi_10000/grunt-webfont)
|
|
7
|
+
|
|
8
|
+
Forked from [sapegin/grunt-webfont](https://github.com/sapegin/grunt-webfont)
|
|
9
|
+
|
|
10
|
+
Generate custom icon webfonts from SVG files via Grunt. Inspired by [Font Custom](https://github.com/FontCustom/fontcustom).
|
|
11
|
+
|
|
12
|
+
This task will make all you need to use font-face icon on your website: font in all needed formats, CSS/Sass/Less/Stylus and HTML demo page.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
* Works on Mac, Windows and Linux.
|
|
17
|
+
* Very flexible.
|
|
18
|
+
* Supports all web font formats: WOFF, WOFF2, EOT, TTF and SVG.
|
|
19
|
+
* Semantic: uses [Unicode private use area](http://bit.ly/ZnkwaT).
|
|
20
|
+
* [Cross-browser](http://www.fontspring.com/blog/further-hardening-of-the-bulletproof-syntax/): IE8+.
|
|
21
|
+
* BEM or Bootstrap output CSS style.
|
|
22
|
+
* CSS preprocessors support.
|
|
23
|
+
* Data:uri embedding.
|
|
24
|
+
* Ligatures.
|
|
25
|
+
* HTML preview.
|
|
26
|
+
* Custom templates.
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
This plugin requires Grunt 0.4. Note that `ttfautohint` is optional, but your generated font will not be properly hinted if it’s not installed. And make sure you don’t use `ttfautohint` 0.97 because that version won’t work.
|
|
32
|
+
|
|
33
|
+
### OS X
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
brew install ttfautohint fontforge --with-python
|
|
37
|
+
npm install grunt-webfont --save-dev
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
*You may need to use `sudo` for `brew`, depending on your setup.*
|
|
41
|
+
|
|
42
|
+
*`fontforge` isn’t required for `node` engine (see below).*
|
|
43
|
+
|
|
44
|
+
### Linux
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
sudo apt-get install fontforge ttfautohint
|
|
48
|
+
npm install grunt-webfont --save-dev
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
*`fontforge` isn’t required for the `node` engine (see [below](#available-engines)).*
|
|
52
|
+
|
|
53
|
+
### Windows
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
npm install grunt-webfont --save-dev
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Then [install `ttfautohint`](http://www.freetype.org/ttfautohint/#download) (optional).
|
|
60
|
+
|
|
61
|
+
Then install `fontforge`.
|
|
62
|
+
* Download and install [fontforge](http://fontforge.github.io/en-US/downloads/windows/).
|
|
63
|
+
* Add `C:\Program Files (x86)\FontForgeBuilds\bin` to your `PATH` environment variable.
|
|
64
|
+
|
|
65
|
+
*`fontforge` isn’t required for the `node` engine (see [below](#available-engines)).*
|
|
66
|
+
|
|
67
|
+
## Available Engines
|
|
68
|
+
|
|
69
|
+
There are two font rendering engines available. See also `engine` option below.
|
|
70
|
+
|
|
71
|
+
### fontforge
|
|
72
|
+
|
|
73
|
+
#### Pros
|
|
74
|
+
|
|
75
|
+
* All features supported.
|
|
76
|
+
* The best results.
|
|
77
|
+
|
|
78
|
+
#### Cons
|
|
79
|
+
|
|
80
|
+
* You have to install `fontforge`.
|
|
81
|
+
* Really weird bugs sometimes.
|
|
82
|
+
|
|
83
|
+
### node
|
|
84
|
+
|
|
85
|
+
#### Pros
|
|
86
|
+
|
|
87
|
+
* No external dependencies (except optional `ttfautohint`).
|
|
88
|
+
* Works on all platforms.
|
|
89
|
+
|
|
90
|
+
#### Cons
|
|
91
|
+
|
|
92
|
+
* Doesn’t work [with some SVG files](https://github.com/fontello/svg2ttf/issues/25).
|
|
93
|
+
* Ligatures aren’t supported.
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
## Configuration
|
|
97
|
+
|
|
98
|
+
Add somewhere in your `Gruntfile.js`:
|
|
99
|
+
|
|
100
|
+
```javascript
|
|
101
|
+
grunt.loadNpmTasks('grunt-webfont');
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Inside your `Gruntfile.js` file add a section named `webfont`. See Parameters section below for details.
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
### Parameters
|
|
108
|
+
|
|
109
|
+
#### src
|
|
110
|
+
|
|
111
|
+
Type: `string|array`
|
|
112
|
+
|
|
113
|
+
Glyphs list: SVG. String or array. Wildcards are supported.
|
|
114
|
+
|
|
115
|
+
#### dest
|
|
116
|
+
|
|
117
|
+
Type: `string`
|
|
118
|
+
|
|
119
|
+
Directory for resulting files.
|
|
120
|
+
|
|
121
|
+
#### destCss
|
|
122
|
+
|
|
123
|
+
Type: `string` Default: _`dest` value_
|
|
124
|
+
|
|
125
|
+
Directory for resulting CSS files (if different than font directory). You can also define `destScss`, `destSass`, `destLess` and `destStyl` to specify a directory per stylesheet type.
|
|
126
|
+
|
|
127
|
+
#### Options
|
|
128
|
+
|
|
129
|
+
All options should be inside `options` object:
|
|
130
|
+
|
|
131
|
+
``` javascript
|
|
132
|
+
webfont: {
|
|
133
|
+
icons: {
|
|
134
|
+
src: 'icons/*.svg',
|
|
135
|
+
dest: 'build/fonts',
|
|
136
|
+
options: {
|
|
137
|
+
...
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### font
|
|
144
|
+
|
|
145
|
+
Type: `string` Default: `icons`
|
|
146
|
+
|
|
147
|
+
Name of font and base name of font files.
|
|
148
|
+
|
|
149
|
+
#### fontFilename
|
|
150
|
+
|
|
151
|
+
Type: `string` Default: Same as `font` option
|
|
152
|
+
|
|
153
|
+
Filename for generated font files, you can add placeholders for the same data that gets passed to the [template](#template).
|
|
154
|
+
|
|
155
|
+
For example, to get the hash to be part of the filenames:
|
|
156
|
+
|
|
157
|
+
```js
|
|
158
|
+
options: {
|
|
159
|
+
fontFilename: 'icons-{hash}'
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
#### hashes
|
|
164
|
+
|
|
165
|
+
Type: `boolean` Default: `true`
|
|
166
|
+
|
|
167
|
+
Append font file names with unique string to flush browser cache when you update your icons.
|
|
168
|
+
|
|
169
|
+
#### styles
|
|
170
|
+
|
|
171
|
+
Type: `string|array` Default: `'font,icon'`
|
|
172
|
+
|
|
173
|
+
List of styles to be added to CSS files: `font` (`font-face` declaration), `icon` (base `.icon` class), `extra` (extra stuff for Bootstrap (only for `syntax` = `'bootstrap'`).
|
|
174
|
+
|
|
175
|
+
#### types
|
|
176
|
+
|
|
177
|
+
Type: `string|array` Default: `'eot,woff,ttf'`, available: `'eot,woff2,woff,ttf,svg'`
|
|
178
|
+
|
|
179
|
+
Font files types to generate.
|
|
180
|
+
|
|
181
|
+
#### order
|
|
182
|
+
|
|
183
|
+
Type: `string|array` Default: `'eot,woff,ttf,svg'`
|
|
184
|
+
|
|
185
|
+
Order of `@font-face`’s `src` values in CSS file. (Only file types defined in `types` option will be generated.)
|
|
186
|
+
|
|
187
|
+
#### syntax
|
|
188
|
+
|
|
189
|
+
Type: `string` Default: `bem`
|
|
190
|
+
|
|
191
|
+
Icon classes syntax. `bem` for double class names: `icon icon_awesome` or `bootstrap` for single class names: `icon-awesome`.
|
|
192
|
+
|
|
193
|
+
#### template
|
|
194
|
+
|
|
195
|
+
Type: `string` Default: ``
|
|
196
|
+
|
|
197
|
+
Custom CSS template path (see `templates` for some examples). Should be used instead of `syntax`. (You probably need to define `htmlDemoTemplate` option too.)
|
|
198
|
+
|
|
199
|
+
Template is a pair of CSS and JSON (optional) files with the same name.
|
|
200
|
+
|
|
201
|
+
For example, your Gruntfile:
|
|
202
|
+
|
|
203
|
+
```js
|
|
204
|
+
options: {
|
|
205
|
+
template: 'my_templates/tmpl.css'
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
`my_templates/tmpl.css`:
|
|
210
|
+
|
|
211
|
+
```css
|
|
212
|
+
@font-face {
|
|
213
|
+
font-family:"<%= fontBaseName %>";
|
|
214
|
+
...
|
|
215
|
+
}
|
|
216
|
+
...
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
`my_templates/tmpl.json`:
|
|
220
|
+
|
|
221
|
+
```json
|
|
222
|
+
{
|
|
223
|
+
"baseClass": "icon",
|
|
224
|
+
"classPrefix": "icon_"
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Some extra data is available for you in templates:
|
|
229
|
+
|
|
230
|
+
* `hash`: a unique string to flush browser cache. Available even if `hashes` option is `false`.
|
|
231
|
+
|
|
232
|
+
* `fontRawSrcs`: array of font-face’s src values not merged to a single line:
|
|
233
|
+
|
|
234
|
+
```
|
|
235
|
+
[
|
|
236
|
+
[
|
|
237
|
+
'url("icons.eot")'
|
|
238
|
+
],
|
|
239
|
+
[
|
|
240
|
+
'url("icons.eot?#iefix") format("embedded-opentype")',
|
|
241
|
+
'url("icons.woff") format("woff")',
|
|
242
|
+
'url("icons.ttf") format("truetype")'
|
|
243
|
+
]
|
|
244
|
+
]
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
#### templateOptions
|
|
249
|
+
|
|
250
|
+
Type: `object` Default: `{}`
|
|
251
|
+
|
|
252
|
+
Extends/overrides CSS template or syntax’s JSON file. Allows custom class names in default css templates.
|
|
253
|
+
|
|
254
|
+
``` javascript
|
|
255
|
+
options: {
|
|
256
|
+
templateOptions: {
|
|
257
|
+
baseClass: 'glyph-icon',
|
|
258
|
+
classPrefix: 'glyph_'
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
#### stylesheets
|
|
264
|
+
|
|
265
|
+
Type: `array` Default: `['css']` or extension of `template`
|
|
266
|
+
|
|
267
|
+
Stylesheet type. Can be `css`, `sass`, `scss` or `less`. If `sass` or `scss` is used, `_` will prefix the file (so it can be a used as a partial). You can define just `stylesheet` if you are generating just one type.
|
|
268
|
+
|
|
269
|
+
#### relativeFontPath
|
|
270
|
+
|
|
271
|
+
Type: `string` Default: `null`
|
|
272
|
+
|
|
273
|
+
Custom font path. Will be used instead of `destCss` *in* CSS file. Useful with CSS preprocessors.
|
|
274
|
+
|
|
275
|
+
#### fontPathVariables
|
|
276
|
+
|
|
277
|
+
Type: `boolean` Default: `false`
|
|
278
|
+
|
|
279
|
+
Create font-path variables for `less`, `scss` and `sass` files. Can be used to override the `relativeFontPath`
|
|
280
|
+
in custom preprocessor tasks or configs.
|
|
281
|
+
|
|
282
|
+
The variable name is a combination of the `font` name appended with `-font-path`.
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
#### version
|
|
286
|
+
|
|
287
|
+
Type: `string` Default: `false`
|
|
288
|
+
|
|
289
|
+
Version number added to `.ttf` version of the font (FontForge Engine only). Also used in the heading of the default demo.html template. Useful to align with the version of other assets that are part of a larger system.
|
|
290
|
+
|
|
291
|
+
#### htmlDemo
|
|
292
|
+
|
|
293
|
+
Type: `boolean` Default: `true`
|
|
294
|
+
|
|
295
|
+
If `true`, an HTML file will be available (by default, in `destCSS` folder) to test the render.
|
|
296
|
+
|
|
297
|
+
#### htmlDemoTemplate
|
|
298
|
+
|
|
299
|
+
Type: `string` Default: `null`
|
|
300
|
+
|
|
301
|
+
Custom demo HTML template path (see `templates/demo.html` for an example) (requires `htmlDemo` option to be true).
|
|
302
|
+
|
|
303
|
+
#### htmlDemoFilename
|
|
304
|
+
|
|
305
|
+
Type: `string` Default: _`fontBaseName` value_
|
|
306
|
+
|
|
307
|
+
Custom name for the demo HTML file (requires `htmlDemo` option to be true). Useful if you want to name the output something like `index.html` instead of the font name.
|
|
308
|
+
|
|
309
|
+
#### destHtml
|
|
310
|
+
|
|
311
|
+
Type: `string` Default: _`destCss` value_
|
|
312
|
+
|
|
313
|
+
Custom demo HTML demo path (requires `htmlDemo` option to be true).
|
|
314
|
+
|
|
315
|
+
#### embed
|
|
316
|
+
|
|
317
|
+
Type: `string|array` Default: `false`
|
|
318
|
+
|
|
319
|
+
If `true` embeds WOFF (*only WOFF*) file as data:uri.
|
|
320
|
+
|
|
321
|
+
IF `ttf` or `woff` or `ttf,woff` embeds TTF or/and WOFF file.
|
|
322
|
+
|
|
323
|
+
If there are more file types in `types` option they will be included as usual `url(font.type)` CSS links.
|
|
324
|
+
|
|
325
|
+
#### ligatures
|
|
326
|
+
|
|
327
|
+
Type: `boolean` Default: `false`
|
|
328
|
+
|
|
329
|
+
If `true` the generated font files and stylesheets will be generated with opentype ligature features. The character sequences to be replaced by the ligatures are determined by the file name (without extension) of the original SVG.
|
|
330
|
+
|
|
331
|
+
For example, you have a heart icon in `love.svg` file. The HTML `<h1>I <span class="ligature-icons">love</span> you!</h1>` will be rendered as `I ♥ you!`.
|
|
332
|
+
|
|
333
|
+
#### rename
|
|
334
|
+
|
|
335
|
+
Type: `function` Default: `path.basename`
|
|
336
|
+
|
|
337
|
+
You can use this function to change how file names translates to class names (the part after `icon_` or `icon-`). By default it’s a name of a file.
|
|
338
|
+
|
|
339
|
+
For example you can group your icons into several folders and add folder name to class name:
|
|
340
|
+
|
|
341
|
+
```js
|
|
342
|
+
options: {
|
|
343
|
+
rename: function(name) {
|
|
344
|
+
// .icon_entypo-add, .icon_fontawesome-add, etc.
|
|
345
|
+
return [path.basename(path.dirname(name)), path.basename(name)].join('-');
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
#### skip
|
|
351
|
+
|
|
352
|
+
Type: `boolean` Default: `false`
|
|
353
|
+
|
|
354
|
+
If `true` task will not be ran. In example, you can skip task on Windows (becase of difficult installation):
|
|
355
|
+
|
|
356
|
+
```javascript
|
|
357
|
+
options: {
|
|
358
|
+
skip: require('os').platform() === 'win32'
|
|
359
|
+
}
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
#### engine
|
|
363
|
+
|
|
364
|
+
Type: `string` Default: `fontforge`
|
|
365
|
+
|
|
366
|
+
Font rendering engine: `fontforge` or `node`. See comparison in [Available Engines](#available-engines) section above.
|
|
367
|
+
|
|
368
|
+
#### ie7
|
|
369
|
+
|
|
370
|
+
Type: `boolean` Default: `false`
|
|
371
|
+
|
|
372
|
+
Adds IE7 support using a `*zoom: expression()` hack.
|
|
373
|
+
|
|
374
|
+
#### optimize
|
|
375
|
+
|
|
376
|
+
Type: `boolean` Default: `true`
|
|
377
|
+
|
|
378
|
+
If `false` the SVGO optimization will not be used. This is useful in cases where the optimizer will produce faulty web fonts by removing relevant SVG paths or attributes.
|
|
379
|
+
|
|
380
|
+
#### normalize
|
|
381
|
+
|
|
382
|
+
Type: `boolean` Default: `false`
|
|
383
|
+
|
|
384
|
+
When using the fontforge engine, if false, glyphs will be generated with a fixed width equal to fontHeight. In most cases, this will produce an extra blank space for each glyph. If set to true, no extra space will be generated. Each glyph will have a width that matches its boundaries.
|
|
385
|
+
|
|
386
|
+
#### startCodepoint
|
|
387
|
+
|
|
388
|
+
Type: `integer` Default: `0xF101`
|
|
389
|
+
|
|
390
|
+
Starting codepoint used for the generated glyphs. Defaults to the start of the Unicode private use area.
|
|
391
|
+
|
|
392
|
+
#### codepoints
|
|
393
|
+
|
|
394
|
+
Type: `object` Default: `null`
|
|
395
|
+
|
|
396
|
+
Specific codepoints to use for certain glyphs. Any glyphs not specified in the codepoints block will be given incremented as usual from the `startCodepoint`, skipping duplicates.
|
|
397
|
+
|
|
398
|
+
```javascript
|
|
399
|
+
options: {
|
|
400
|
+
codepoints: {
|
|
401
|
+
single: 0xE001
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
#### codepointsFile
|
|
407
|
+
Type: `string` Default: `null`
|
|
408
|
+
|
|
409
|
+
Uses and Saves the codepoint mapping by name to this file.
|
|
410
|
+
|
|
411
|
+
NOTE: will overwrite the set codepoints option.
|
|
412
|
+
|
|
413
|
+
#### autoHint
|
|
414
|
+
|
|
415
|
+
Type: `boolean` Default: `true`
|
|
416
|
+
|
|
417
|
+
Enables font auto hinting using `ttfautohint`.
|
|
418
|
+
|
|
419
|
+
#### round
|
|
420
|
+
|
|
421
|
+
Type: `number` Default: `10e12`
|
|
422
|
+
|
|
423
|
+
Setup SVG path rounding.
|
|
424
|
+
|
|
425
|
+
#### fontHeight
|
|
426
|
+
|
|
427
|
+
Type: `number` Default: `512`
|
|
428
|
+
|
|
429
|
+
The output font height.
|
|
430
|
+
|
|
431
|
+
#### fontFamilyName
|
|
432
|
+
|
|
433
|
+
Type: `string` Default: _`font` value_
|
|
434
|
+
|
|
435
|
+
If you’d like your generated fonts to have a name that’s different than the `font` value, you can specify this as a string. This will allow a unique display name within design authoring tools when installing fonts locally. For example, your font’s name could be `GitHub Octicons` with a filename of `octicons.ttf`.
|
|
436
|
+
|
|
437
|
+
```javascript
|
|
438
|
+
options: {
|
|
439
|
+
fontFamilyName: 'GitHub Octicons',
|
|
440
|
+
}
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
#### descent
|
|
444
|
+
|
|
445
|
+
Type: `number` Default: `64`
|
|
446
|
+
|
|
447
|
+
The font descent. The descent should be a positive value. The ascent formula is: `ascent = fontHeight - descent`.
|
|
448
|
+
|
|
449
|
+
#### callback
|
|
450
|
+
|
|
451
|
+
Type: `function` Default: `null`
|
|
452
|
+
|
|
453
|
+
Allows for a callback to be called when the task has completed and passes in the filename of the generated font, an array of the various font types created, an array of all the glyphs created and the hash used to flush browser cache.
|
|
454
|
+
|
|
455
|
+
```javascript
|
|
456
|
+
options: {
|
|
457
|
+
callback: function(filename, types, glyphs, hash) {
|
|
458
|
+
// ...
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
#### customOutputs
|
|
464
|
+
|
|
465
|
+
Type: `array` Default: `undefined`
|
|
466
|
+
|
|
467
|
+
Allows for custom content to be generated and output in the same way as `htmlDemo`.
|
|
468
|
+
|
|
469
|
+
Each entry in `customOutputs` should be an object with the following parameters:
|
|
470
|
+
|
|
471
|
+
* `template` - (`string`) the path to the underscore-template you wish to use.
|
|
472
|
+
* `dest` - (`string`) the path to the destination where you want the resulting file to live.
|
|
473
|
+
* `context` \[optional\] - (`object`) a hash of values to pass into the context of the template
|
|
474
|
+
|
|
475
|
+
At compile-time each template will have access to the same context as the compile-time environment of `htmlDemoTemplate` (as extended by the `context` object, if provided. See config-example below.
|
|
476
|
+
|
|
477
|
+
#### execMaxBuffer
|
|
478
|
+
If you get stderr maxBuffer exceeded warning message, engine probably logged a lot of warning messages. To see this warnings run grunt in verbose mode `grunt --verbose`. To go over this warning you can try to increase buffer size by this option. Default value is `1024 * 200`
|
|
479
|
+
|
|
480
|
+
### Config Examples
|
|
481
|
+
|
|
482
|
+
#### Simple font generation
|
|
483
|
+
|
|
484
|
+
```javascript
|
|
485
|
+
webfont: {
|
|
486
|
+
icons: {
|
|
487
|
+
src: 'icons/*.svg',
|
|
488
|
+
dest: 'build/fonts'
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
#### Custom font name, fonts and CSS in different folders
|
|
494
|
+
|
|
495
|
+
```javascript
|
|
496
|
+
webfont: {
|
|
497
|
+
icons: {
|
|
498
|
+
src: 'icons/*.svg',
|
|
499
|
+
dest: 'build/fonts',
|
|
500
|
+
destCss: 'build/fonts/css',
|
|
501
|
+
options: {
|
|
502
|
+
font: 'ponies'
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
#### Custom CSS classes
|
|
509
|
+
|
|
510
|
+
```js
|
|
511
|
+
webfont: {
|
|
512
|
+
icons: {
|
|
513
|
+
src: 'icons/*.svg',
|
|
514
|
+
dest: 'build/fonts',
|
|
515
|
+
options: {
|
|
516
|
+
syntax: 'bem',
|
|
517
|
+
templateOptions: {
|
|
518
|
+
baseClass: 'glyph-icon',
|
|
519
|
+
classPrefix: 'glyph_'
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
#### To use with CSS preprocessor
|
|
527
|
+
|
|
528
|
+
```javascript
|
|
529
|
+
webfont: {
|
|
530
|
+
icons: {
|
|
531
|
+
src: 'icons/*.svg',
|
|
532
|
+
dest: 'build/fonts',
|
|
533
|
+
destCss: 'build/styles',
|
|
534
|
+
options: {
|
|
535
|
+
stylesheet: 'styl',
|
|
536
|
+
relativeFontPath: '/build/fonts'
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
#### Embedded font file
|
|
543
|
+
|
|
544
|
+
```javascript
|
|
545
|
+
webfont: {
|
|
546
|
+
icons: {
|
|
547
|
+
src: 'icons/*.svg',
|
|
548
|
+
dest: 'build/fonts',
|
|
549
|
+
options: {
|
|
550
|
+
types: 'woff',
|
|
551
|
+
embed: true
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
#### Custom Outputs
|
|
558
|
+
|
|
559
|
+
```javascript
|
|
560
|
+
webfont: {
|
|
561
|
+
icons: {
|
|
562
|
+
src: 'icons/*.svg',
|
|
563
|
+
dest: 'build/fonts',
|
|
564
|
+
options: {
|
|
565
|
+
customOutputs: [{
|
|
566
|
+
template: 'templates/icon-glyph-list-boilerplate.js',
|
|
567
|
+
dest: 'build/js/icon-glyph-list.js'
|
|
568
|
+
}, {
|
|
569
|
+
template: 'templates/icon-glyph-config-boilerplate.json',
|
|
570
|
+
dest: 'build/js/icon-glyphs.json'
|
|
571
|
+
}, {
|
|
572
|
+
template: 'templates/icon-web-home.html',
|
|
573
|
+
dest: 'build/',
|
|
574
|
+
context: {
|
|
575
|
+
homeHeading: 'Your Icon Font',
|
|
576
|
+
homeMessage: 'The following glyphs are available in this font:'
|
|
577
|
+
}
|
|
578
|
+
}]
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
We might then include the following corresponding templates.
|
|
585
|
+
|
|
586
|
+
The first, for `icon-glyph-list-boilerplate.js`, a file that outputs a list of icon-glyph slugs.
|
|
587
|
+
|
|
588
|
+
```
|
|
589
|
+
// file: icon-glyph-list-boilerplate.js
|
|
590
|
+
|
|
591
|
+
(function(window) {
|
|
592
|
+
'use strict';
|
|
593
|
+
|
|
594
|
+
var iconList = <%= JSON.stringify(glyphs) %>;
|
|
595
|
+
window.iconList = iconList;
|
|
596
|
+
}(this));
|
|
597
|
+
```
|
|
598
|
+
|
|
599
|
+
The second, for `icon-glyph-config-boilerplate.json`, a file that dumps all JSON data in the current template context.
|
|
600
|
+
|
|
601
|
+
```
|
|
602
|
+
// file: icon-glyph-config-boilerplate.json
|
|
603
|
+
|
|
604
|
+
<%= JSON.stringify(arguments[0], null, '\t') %>
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
And finally, the third, for `icon-web-home.html`, a file that has access to the values provided in the `context` object supplied.
|
|
608
|
+
|
|
609
|
+
```
|
|
610
|
+
// file: icon-web-home.html
|
|
611
|
+
|
|
612
|
+
<!DOCTYPE html>
|
|
613
|
+
<html class="no-js">
|
|
614
|
+
<head>
|
|
615
|
+
<meta charset="utf-8">
|
|
616
|
+
<title>Context Test</title>
|
|
617
|
+
</head>
|
|
618
|
+
<body>
|
|
619
|
+
<h1><%= homeHeading %></h1>
|
|
620
|
+
<p><%= homeMessage %></p>
|
|
621
|
+
<ul>
|
|
622
|
+
<% for (var i = 0; i < glyphs.length; i++) { %>
|
|
623
|
+
<li><a href="#"><%= glyphs[i] %></a></li>
|
|
624
|
+
<% } %>
|
|
625
|
+
</ul>
|
|
626
|
+
</body>
|
|
627
|
+
</html>
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
## CSS Preprocessors Caveats
|
|
631
|
+
|
|
632
|
+
You can change CSS file syntax using `stylesheet` option (see above). It change file extension (so you can specify any) with some tweaks. Replace all comments with single line comments (which will be removed after compilation).
|
|
633
|
+
|
|
634
|
+
### Dynamic font-path
|
|
635
|
+
You can enable the `fontPathVariables` in combination with `relativeFontPath` to create a overridable font-path.
|
|
636
|
+
|
|
637
|
+
For example scss:
|
|
638
|
+
```scss
|
|
639
|
+
$icons-font-path : "/relativeFontPath/" !default;
|
|
640
|
+
@font-face {
|
|
641
|
+
font-family:"icons";
|
|
642
|
+
src:url($icons-font-path + "icons.eot");
|
|
643
|
+
src:url($icons-font-path + "icons.eot?#iefix") format("embedded-opentype"),
|
|
644
|
+
url($icons-font-path + "icons.woff") format("woff"),
|
|
645
|
+
url($icons-font-path + "icons.ttf") format("truetype");
|
|
646
|
+
font-weight:normal;
|
|
647
|
+
font-style:normal;
|
|
648
|
+
}
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
### Sass
|
|
652
|
+
|
|
653
|
+
If `stylesheet` option is `sass` or `scss`, `_` will prefix the file (so it can be a used as a partial).
|
|
654
|
+
|
|
655
|
+
### Less
|
|
656
|
+
|
|
657
|
+
If `stylesheet` option is `less`, regular CSS icon classes will be expanded with corresponding Less mixins.
|
|
658
|
+
|
|
659
|
+
The Less mixins then may be used like so:
|
|
660
|
+
|
|
661
|
+
```css
|
|
662
|
+
.profile-button {
|
|
663
|
+
.icon-profile;
|
|
664
|
+
}
|
|
665
|
+
```
|
|
666
|
+
|
|
667
|
+
## Troubleshooting
|
|
668
|
+
|
|
669
|
+
### I have problems displaying the font in Firefox
|
|
670
|
+
|
|
671
|
+
Firefox doesn’t allow cross-domain fonts: [Specifications](http://www.w3.org/TR/css3-fonts/#font-fetching-requirements), [Bugzilla Ticket](https://bugzilla.mozilla.org/show_bug.cgi?id=604421), [How to fix it](https://coderwall.com/p/v4uwyq).
|
|
672
|
+
|
|
673
|
+
### My images are getting corrupted
|
|
674
|
+
|
|
675
|
+
#### Using the node engine
|
|
676
|
+
|
|
677
|
+
* Certain SVG's are not supported. See the [svg2ttf](https://github.com/fontello/svg2ttf) project which is used to convert from SVG to TTF (which is then converted forward to WOFF and WOFF2).
|
|
678
|
+
* `autoHint` also adjusts the font file and can cause your font to look different to the SVG, so you could try switching it off (though it may make windows view of the font worse).
|
|
679
|
+
|
|
680
|
+
#### Using fontforge
|
|
681
|
+
|
|
682
|
+
Check the following...
|
|
683
|
+
|
|
684
|
+
* Your paths are clockwise. Anti-clockwise paths may cause fills to occur differently.
|
|
685
|
+
* Your paths are not overlapping. Overlapping paths will cause one of the areas to be inverted rather than combined. Use an editor to union your two paths together.
|
|
686
|
+
* `autoHint` also adjusts the font file and can cause your font to look different to the SVG, so you could try switching it off (though it may make windows view of the font worse).
|
|
687
|
+
* If you get stderr maxBuffer exceeded warning message, fontforge probably logged a lot of warning messages. To see this warnings run grunt in verbose mode `grunt --verbose`. To go over this warning you can try to increase buffer size by [execMaxBuffer](#execMaxBuffer).
|
|
688
|
+
|
|
689
|
+
## Changelog
|
|
690
|
+
|
|
691
|
+
The changelog can be found on the [Releases page](https://github.com/Hibi-10000/grunt-webfont/releases).
|
|
692
|
+
|
|
693
|
+
## License
|
|
694
|
+
|
|
695
|
+
The MIT License, see the included [LICENSE.md](LICENSE.md) file.
|