• Stars
    star
    854
  • Rank 53,369 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 11 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create icon fonts from several SVG icons

gulp-iconfont

Create SVG/TTF/EOT/WOFF/WOFF2 fonts from several SVG icons with Gulp.

NPM version Build status Dependency Status devDependency Status Coverage Status Code Climate

You can test this library with the frontend generator.

Warning: While this plugin may still be useful for fonts generation or old browser support, you should consider using SVG icons directly. Indeed, when i created gulp-iconfont and all its related modules, using SVG icons was just not realistic for a wide browser suppport but i was already conviced that SVG was the future, that's why i wanted my SVG source files to sit separated in a folder. So, now, just enjoy switching to SVG with almost no effort :). Was a great open source journey with you all!

More info on with using SVG over icon fonts.

Usage

First, install gulp-iconfont as a development dependency:

npm install --save-dev gulp-iconfont

Then, add it to your gulpfile.js:

var iconfont = require('gulp-iconfont');
var runTimestamp = Math.round(Date.now()/1000);

gulp.task('Iconfont', function(){
  return gulp.src(['assets/icons/*.svg'])
    .pipe(iconfont({
      fontName: 'myfont', // required
      prependUnicode: true, // recommended option
      formats: ['ttf', 'eot', 'woff'], // default, 'woff2' and 'svg' are available
      timestamp: runTimestamp, // recommended to get consistent builds when watching files
    }))
      .on('glyphs', function(glyphs, options) {
        // CSS templating, e.g.
        console.log(glyphs, options);
      })
    .pipe(gulp.dest('www/fonts/'));
});

gulp-iconfont bundles several plugins to bring a simpler API (gulp-svgicons2svgfont, gulp-svg2tff, gulp-ttf2eot, gulp-ttf2woff) for more flexibility, feel free to use them separately.

If some font glyphs aren't converted properly you should add the normalize:true option and a fontHeight greater than 1000 (fontHeight: 1001).

Make your CSS

To use this font in your CSS, you could add a mixin like in this real world example. You can also generate your CSS automatically with gulp-iconfont-css.

It's also easy to make a CSS template by yourself. Like this example, gulp-consolidate is useful to handling such a template. The template is outdated, change every occurrence of glyph.codepoint.toString(16).toUpperCase() to glyph.unicode[0].charCodeAt(0).toString(16).toUpperCase(), otherwise it will not work.

var async = require('async');
var gulp = require('gulp');
var iconfont = require('gulp-iconfont');
var consolidate = require('gulp-consolidate');

gulp.task('Iconfont', function(done){
  var iconStream = gulp.src(['assets/icons/*.svg'])
    .pipe(iconfont({ fontName: 'myfont' }));

  async.parallel([
    function handleGlyphs (cb) {
      iconStream.on('glyphs', function(glyphs, options) {
        gulp.src('templates/myfont.css')
          .pipe(consolidate('lodash', {
            glyphs: glyphs,
            fontName: 'myfont',
            fontPath: '../fonts/',
            className: 's'
          }))
          .pipe(gulp.dest('www/css/'))
          .on('finish', cb);
      });
    },
    function handleFonts (cb) {
      iconStream
        .pipe(gulp.dest('www/fonts/'))
        .on('finish', cb);
    }
  ], done);
});

Issues

Add issues to the right repos:

  • the plugin doesn't work at all, submit your issue in this repo.
  • every font doesn't display as expected: submit the issue to the svgicons2svgfont repository.
  • only some fonts are damaged? Please look at the font format the targeted browser actually use and then, submit your issue to one of those projects: svg2ttf, ttf2eot, ttf2woff.

API

iconfont(options)

options.formats

Type: Array Default value: ['ttf', 'eot', 'woff'] Possible values: ['svg', 'ttf', 'eot', 'woff', 'woff2']

Since SVG fonts are deprecated in some (every ?) browsers, they are disabled per default.

Also the WOFF2 fonts are disabled since it seems to cause issues on some setup (see #64).

options.autohint

Type: Boolean|String Default value: false

If ttfautohint is installed on your system, you may want to auto hint your fonts. Beware that this is an experimental and untested feature (beware to use at least the 0.93 version).

If the value is a string, it is taken to be the path to the ttfautohint binary. Otherwise, ttfautohint is searched in $PATH.

options.*

The svgicons2svgfont are available:

  • options.fontName (required)
  • options.fontWeight
  • options.fontStyle
  • options.fixedWidth
  • options.centerHorizontally
  • options.normalize
  • options.fontHeight
  • options.round
  • options.descent
  • options.metadata
  • options.log

So are the gulp-svgicons2svgfont:

  • options.startUnicode
  • options.prependUnicode

And the gulp-svg2ttf:

  • options.timestamp

Preparing SVG's

Beware that your SVG icons must have a high enough height. 500 is a minimum. If you do not want to resize them, you can try to combine the fontHeight and the normalize option to get them in a correct size.

Inkscape

Degroup every shapes (Ctrl+Shift+G), convert to pathes (Ctrl+Maj+C) and merge them (Ctrl++). Then save your SVG, prefer 'simple SVG' file type.

Illustrator

Save your file as SVG with the following settings:

  • SVG Profiles: SVG 1.1
  • Fonts Type: SVG
  • Fonts Subsetting: None
  • Options Image Location: Embed
  • Advanced Options
    • CSS Properties: Presentation Attributes
    • Decimal Places: 1
    • Encoding: UTF-8
    • Output fewer elements: check

Leave the rest unchecked.

More in-depth information: http://www.adobe.com/inspire/2013/09/exporting-svg-illustrator.html

Sketch

Sketch is a relatively new drawing tool on Mac. With help of Sketch Tools and gulp-sketch, you can directly create fonts from your Sketch file. No need to export intermediate SVGs.

Directly create fonts from your Sketch file

Here is a sample repo "Symbols for Sketch".

  1. Download the zipped repo and extract it.
  2. Go to the directory. $ cd path/to/dir
  3. Install some tools. $ npm install
  4. Create fonts and CSS $ gulp symbols

Contributing

Feel free to push your code if you agree with publishing under the MIT license.

Stats

NPM NPM

More Repositories

1

svgicons2svgfont

Concatenate SVG icons and ouput an SVG font
TypeScript
337
star
2

ttf2woff2

Convert ttf files to woff2.
C
302
star
3

midifile

A MIDI file parser/writer using ArrayBuffers
JavaScript
199
star
4

svg-pathdata

Parse SVG PathDatas
TypeScript
182
star
5

streamqueue

Pipe queued streams progressively.
TypeScript
62
star
6

gulp-streamify

Wrap old plugins to support streams.
JavaScript
59
star
7

midiplayer

Play MIDI file right in your browser with the WebMIDIAPI
JavaScript
57
star
8

gulp-svgicons2svgfont

Bundle several SVG icons to a single SVG font
JavaScript
45
star
9

buildbranch

Publish a folder to the given build branch (like gh-pages).
JavaScript
43
star
10

midievents

MIDI events parser/encoder.
JavaScript
35
star
11

knifecycle

Manage your NodeJS processes's lifecycle automatically with an unobtrusive dependency injection implementation.
TypeScript
31
star
12

whook

Build strong and efficient REST web services.
TypeScript
31
star
13

streamtest

Streams test toolbelt
TypeScript
30
star
14

metapak

NPM meta package
TypeScript
26
star
15

bufferstreams

Abstract streams to deal with the whole buffered contents.
TypeScript
26
star
16

jsarch

A simple module to extract architecture notes from your code.
TypeScript
25
star
17

svgiconfont

PoC of SVG font generation in the browser
JavaScript
23
star
18

gulp-svg2ttf

Create a TTF font from an SVG font
TypeScript
20
star
19

utf-8

A simple JavaScript library to manage UTF8 strings contained in ArrayBuffers
JavaScript
19
star
20

VarStream

VarStream is an elegant alternative to JSON to exchange datas between apps.
JavaScript
17
star
21

gulp-ttf2woff2

Create WOFF2 fonts from TTF ones.
TypeScript
16
star
22

gulp-ttf2woff

Create a WOFF font from a TTF font with Gulp
TypeScript
16
star
23

svgfont2svgicons

Extract SVG icons from an SVG font
JavaScript
15
star
24

yerror

🚨 It helps to know Y you got an Error.
TypeScript
13
star
25

openapi-ts-sdk-builder

Create a TypeScript SDK from an OpenAPI 3 definition
TypeScript
10
star
26

http-auth-utils

Parse, build and deal with HTTP auth headers.
TypeScript
10
star
27

WebSockIPC

Interprocessus communication with the help of NodeJS, WebSockets and VarStream.
JavaScript
9
star
28

gulp-ttf2eot

Create an EOT font from a TTF font with Gulp
TypeScript
9
star
29

BugMeBack

This extension allows you to report bugs to webmasters with a complete description of the bug, the user agent, viewport details, JavaScript errors and a screenshot.
JavaScript
9
star
30

TripStory

Storify your journeys.
JavaScript
8
star
31

gulp-cond

Ternary operator for Gulp.
JavaScript
7
star
32

gulp-vartree

Create a variable tree with the files that are passed in.
JavaScript
7
star
33

schema2dts

A very simple JSONSchema to TypeScript types generator
TypeScript
6
star
34

grunt-ttf2woff

Convert a TTF font to a WOFF font
JavaScript
6
star
35

watchdeps

Watch your NodeJS project dependencies on GitHub
JavaScript
6
star
36

Promise

A minimalist JavaScript Promises/A implementation
JavaScript
5
star
37

grunt-svg2ttf

Convert an SVG font to a TTF font
JavaScript
5
star
38

streamfilter

A function based filter for streams
TypeScript
5
star
39

Hexa

Full web hexadecimal editor
JavaScript
5
star
40

gulp-minify-css

A Gulp plugin that minifies css with clean-css:
JavaScript
5
star
41

strict-qs

A stricter query string parser
TypeScript
4
star
42

politics

My political blog
TypeScript
4
star
43

belotere

A simple solo Belote game
TypeScript
4
star
44

midikaraoke

MIDI Karaoke files player
JavaScript
4
star
45

swagger-http-router

A HTTP router based on your Swagger definition.
JavaScript
4
star
46

Liar

A simple multiplayer game where you must lie to your competitors.
JavaScript
3
star
47

jwt-service

A simple wrapper around `jsonwebtoken`
TypeScript
3
star
48

siso

A routing utility allowing to map a path to a value
TypeScript
3
star
49

KGen

Keyword scanner for Firefox (SEO tool). It scan web pages to retrieve the strongest keywords by using many different concepts (repeats, weights and average position).
JavaScript
3
star
50

asttpl

JavaScript AST templating
JavaScript
2
star
51

CanImage

Image manipulation add-on for Firefox
JavaScript
2
star
52

plexer

A streams2 duplexer.
TypeScript
2
star
53

phone-coop

Recycle your phone and get a voucher
TypeScript
2
star
54

neatequal

Neat deepEqual
JavaScript
2
star
55

Memory

A simple multi-player Memory
JavaScript
2
star
56

metapak-nfroidure

A metapak module for my open source projects.
TypeScript
2
star
57

BBComposer

BBComposer is an universal WYSIWYG editor for Firefox
JavaScript
2
star
58

ftp-service

A very simple FTP service
TypeScript
2
star
59

Commandor

Web Application Commands Mediator
JavaScript
2
star
60

cloud-pages

Push your pages to cloud buckets (S3 for now)
JavaScript
1
star
61

HelpMe

Orange hackaton project allowing you to get help and declare your skills to give some.
HTML
1
star
62

whook-perf

Naive benchmak for whook vs other frameworks
JavaScript
1
star
63

CapsKiller

Thunderbird extension removing all caps messages.
JavaScript
1
star
64

mdvars

Extract vars from markdown files and output the markdown.
JavaScript
1
star