Giter Site home page Giter Site logo

grunt-webfont's Introduction

SVG to webfont converter for Grunt

Powered by You Build Status Downloads on npm

Generate custom icon webfonts from SVG files via Grunt. Inspired by Font Custom.

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.

Features

  • Works on Mac, Windows and Linux.
  • Very flexible.
  • Supports all web font formats: WOFF, WOFF2, EOT, TTF and SVG.
  • Semantic: uses Unicode private use area.
  • Cross-browser: IE8+.
  • BEM or Bootstrap output CSS style.
  • CSS preprocessors support.
  • Data:uri embedding.
  • Ligatures.
  • HTML preview.
  • Custom templates.

Installation

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.

OS X

brew install ttfautohint fontforge --with-python
npm install grunt-webfont --save-dev

You may need to use sudo for brew, depending on your setup.

fontforge isn’t required for node engine (see below).

Linux

sudo apt-get install fontforge ttfautohint
npm install grunt-webfont --save-dev

fontforge isn’t required for the node engine (see below).

Windows

npm install grunt-webfont --save-dev

Then install ttfautohint (optional).

Then install fontforge.

  • Download and install fontforge.
  • Add C:\Program Files (x86)\FontForgeBuilds\bin to your PATH environment variable.

fontforge isn’t required for the node engine (see below).

Available Engines

There are two font rendering engines available. See also engine option below.

fontforge

Pros

  • All features supported.
  • The best results.

Cons

  • You have to install fontforge.
  • Really weird bugs sometimes.

node

Pros

  • No external dependencies (except optional ttfautohint).
  • Works on all platforms.

Cons

Configuration

Add somewhere in your Gruntfile.js:

grunt.loadNpmTasks('grunt-webfont');

Inside your Gruntfile.js file add a section named webfont. See Parameters section below for details.

Parameters

src

Type: string|array

Glyphs list: SVG. String or array. Wildcards are supported.

dest

Type: string

Directory for resulting files.

destCss

Type: string Default: dest value

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.

Options

All options should be inside options object:

webfont: {
	icons: {
		src: 'icons/*.svg',
		dest: 'build/fonts',
		options: {
			...
		}
	}
}

font

Type: string Default: icons

Name of font and base name of font files.

fontFilename

Type: string Default: Same as font option

Filename for generated font files, you can add placeholders for the same data that gets passed to the template.

For example, to get the hash to be part of the filenames:

options: {
	fontFilename: 'icons-{hash}'
}

hashes

Type: boolean Default: true

Append font file names with unique string to flush browser cache when you update your icons.

styles

Type: string|array Default: 'font,icon'

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').

types

Type: string|array Default: 'eot,woff,ttf', available: 'eot,woff2,woff,ttf,svg'

Font files types to generate.

order

Type: string|array Default: 'eot,woff,ttf,svg'

Order of @font-face’s src values in CSS file. (Only file types defined in types option will be generated.)

syntax

Type: string Default: bem

Icon classes syntax. bem for double class names: icon icon_awesome or bootstrap for single class names: icon-awesome.

template

Type: string Default: ``

Custom CSS template path (see tasks/templates for some examples). Should be used instead of syntax. (You probably need to define htmlDemoTemplate option too.)

Template is a pair of CSS and JSON (optional) files with the same name.

For example, your Gruntfile:

options: {
	template: 'my_templates/tmpl.css'
}

my_templates/tmpl.css:

@font-face {
	font-family:"<%= fontBaseName %>";
	...
}
...

my_templates/tmpl.json:

{
	"baseClass": "icon",
	"classPrefix": "icon_"
}

Some extra data is available for you in templates:

  • hash: a unique string to flush browser cache. Available even if hashes option is false.

  • fontRawSrcs: array of font-face’s src values not merged to a single line:

[
	[
		'url("icons.eot")'
	],
	[
		'url("icons.eot?#iefix") format("embedded-opentype")',
		'url("icons.woff") format("woff")',
		'url("icons.ttf") format("truetype")'
	]
]

templateOptions

Type: object Default: {}

Extends/overrides CSS template or syntax’s JSON file. Allows custom class names in default css templates.

options: {
	templateOptions: {
		baseClass: 'glyph-icon',
		classPrefix: 'glyph_'
	}
}

stylesheets

Type: array Default: ['css'] or extension of template

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.

relativeFontPath

Type: string Default: null

Custom font path. Will be used instead of destCss in CSS file. Useful with CSS preprocessors.

fontPathVariables

Type: boolean Default: false

Create font-path variables for less, scss and sass files. Can be used to override the relativeFontPath in custom preprocessor tasks or configs.

The variable name is a combination of the font name appended with -font-path.

version

Type: string Default: false

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.

htmlDemo

Type: boolean Default: true

If true, an HTML file will be available (by default, in destCSS folder) to test the render.

htmlDemoTemplate

Type: string Default: null

Custom demo HTML template path (see tasks/templates/demo.html for an example) (requires htmlDemo option to be true).

htmlDemoFilename

Type: string Default: fontBaseName value

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.

destHtml

Type: string Default: destCss value

Custom demo HTML demo path (requires htmlDemo option to be true).

embed

Type: string|array Default: false

If true embeds WOFF (only WOFF) file as data:uri.

IF ttf or woff or ttf,woff embeds TTF or/and WOFF file.

If there are more file types in types option they will be included as usual url(font.type) CSS links.

ligatures

Type: boolean Default: false

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.

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!.

rename

Type: function Default: path.basename

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.

For example you can group your icons into several folders and add folder name to class name:

options: {
	rename: function(name) {
		// .icon_entypo-add, .icon_fontawesome-add, etc.
		return [path.basename(path.dirname(name)), path.basename(name)].join('-');
	}
}

skip

Type: boolean Default: false

If true task will not be ran. In example, you can skip task on Windows (becase of difficult installation):

options: {
	skip: require('os').platform() === 'win32'
}

engine

Type: string Default: fontforge

Font rendering engine: fontforge or node. See comparison in Available Engines section above.

ie7

Type: boolean Default: false

Adds IE7 support using a *zoom: expression() hack.

optimize

Type: boolean Default: true

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.

normalize

Type: boolean Default: false

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.

startCodepoint

Type: integer Default: 0xF101

Starting codepoint used for the generated glyphs. Defaults to the start of the Unicode private use area.

codepoints

Type: object Default: null

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.

options: {
	codepoints: {
		single: 0xE001
	}
}

codepointsFile

Type: string Default: null

Uses and Saves the codepoint mapping by name to this file.

NOTE: will overwrite the set codepoints option.

autoHint

Type: boolean Default: true

Enables font auto hinting using ttfautohint.

round

Type: number Default: 10e12

Setup SVG path rounding.

fontHeight

Type: number Default: 512

The output font height.

fontFamilyName

Type: string Default: font value

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.

options: {
	fontFamilyName: 'GitHub Octicons',
}

descent

Type: number Default: 64

The font descent. The descent should be a positive value. The ascent formula is: ascent = fontHeight - descent.

callback

Type: function Default: null

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.

options: {
	callback: function(filename, types, glyphs, hash) {
		// ...
	}
}

customOutputs

Type: array Default: undefined

Allows for custom content to be generated and output in the same way as htmlDemo.

Each entry in customOutputs should be an object with the following parameters:

  • template - (string) the path to the underscore-template you wish to use.
  • dest - (string) the path to the destination where you want the resulting file to live.
  • context [optional] - (object) a hash of values to pass into the context of the template

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.

execMaxBuffer

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

Config Examples

Simple font generation

webfont: {
	icons: {
		src: 'icons/*.svg',
		dest: 'build/fonts'
	}
}

Custom font name, fonts and CSS in different folders

webfont: {
	icons: {
		src: 'icons/*.svg',
		dest: 'build/fonts',
		destCss: 'build/fonts/css',
		options: {
			font: 'ponies'
		}
	}
}

Custom CSS classes

webfont: {
	icons: {
		src: 'icons/*.svg',
		dest: 'build/fonts',
		options: {
			syntax: 'bem',
			templateOptions: {
				baseClass: 'glyph-icon',
				classPrefix: 'glyph_'
			}
		}
	}
}

To use with CSS preprocessor

webfont: {
	icons: {
		src: 'icons/*.svg',
		dest: 'build/fonts',
		destCss: 'build/styles',
		options: {
			stylesheet: 'styl',
			relativeFontPath: '/build/fonts'
		}
	}
}

Embedded font file

webfont: {
	icons: {
		src: 'icons/*.svg',
		dest: 'build/fonts',
		options: {
			types: 'woff',
			embed: true
		}
	}
}

Custom Outputs

webfont: {
	icons: {
		src: 'icons/*.svg',
		dest: 'build/fonts',
		options: {
			customOutputs: [{
				template: 'templates/icon-glyph-list-boilerplate.js',
				dest: 'build/js/icon-glyph-list.js'
			}, {
				template: 'templates/icon-glyph-config-boilerplate.json',
				dest: 'build/js/icon-glyphs.json'
			}, {
				template: 'templates/icon-web-home.html',
				dest: 'build/',
				context: {
					homeHeading: 'Your Icon Font',
					homeMessage: 'The following glyphs are available in this font:'
				}
			}]
		}
	}
}

We might then include the following corresponding templates.

The first, for icon-glyph-list-boilerplate.js, a file that outputs a list of icon-glyph slugs.

// file: icon-glyph-list-boilerplate.js

(function(window) {
	'use strict';

	var iconList = <%= JSON.stringify(glyphs) %>;
	window.iconList = iconList;
}(this));

The second, for icon-glyph-config-boilerplate.json, a file that dumps all JSON data in the current template context.

// file: icon-glyph-config-boilerplate.json

<%= JSON.stringify(arguments[0], null, '\t') %>

And finally, the third, for icon-web-home.html, a file that has access to the values provided in the context object supplied.

// file: icon-web-home.html

<!DOCTYPE html>
<html class="no-js">
    <head>
        <meta charset="utf-8">
        <title>Context Test</title>
    </head>
    <body>
        <h1><%= homeHeading %></h1>
        <p><%= homeMessage %></p>
        <ul>
        	<% for (var i = 0; i < glyphs.length; i++) { %>
        	<li><a href="#"><%= glyphs[i] %></a></li>
        	<% } %>
        </ul>
    </body>
</html>

CSS Preprocessors Caveats

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).

Dynamic font-path

You can enable the fontPathVariables in combination with relativeFontPath to create a overridable font-path.

For example scss:

$icons-font-path : "/relativeFontPath/" !default;
@font-face {
	font-family:"icons";
	src:url($icons-font-path + "icons.eot");
	src:url($icons-font-path + "icons.eot?#iefix") format("embedded-opentype"),
		url($icons-font-path + "icons.woff") format("woff"),
		url($icons-font-path + "icons.ttf") format("truetype");
	font-weight:normal;
	font-style:normal;
}

Sass

If stylesheet option is sass or scss, _ will prefix the file (so it can be a used as a partial).

Less

If stylesheet option is less, regular CSS icon classes will be expanded with corresponding Less mixins.

The Less mixins then may be used like so:

.profile-button {
	.icon-profile;
}

Troubleshooting

I have problems displaying the font in Firefox

Firefox doesn’t allow cross-domain fonts: Specifications, Bugzilla Ticket, How to fix it.

My images are getting corrupted

Using the node engine

  • Certain SVG's are not supported. See the svg2ttf project which is used to convert from SVG to TTF (which is then converted forward to WOFF and WOFF2).
  • 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).

Using fontforge

Check the following...

  • Your paths are clockwise. Anti-clockwise paths may cause fills to occur differently.
  • 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.
  • 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).
  • 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.

Changelog

The changelog can be found on the Releases page.

License

The MIT License, see the included License.md file.

grunt-webfont's People

Contributors

alampros avatar andreu86 avatar area73 avatar bloodyowl avatar borodean avatar danforys avatar duncanbeevers avatar eddiemonge avatar jantimon avatar kayoub5 avatar kevinmpowell avatar landru29 avatar lukeapage avatar moox avatar mrhyde avatar mstorus avatar mtgibbs avatar nicdacosta avatar peter-mouland avatar prehnra avatar rickpastoor avatar rubenof avatar sapegin avatar sbeator avatar scanieso avatar scottyeck avatar tauren avatar timhettler avatar tylerbeck avatar web-mi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grunt-webfont's Issues

Cannot call method 'split' of undefined error while generating fonts

xxxxxx@production:~/Bureau/xxxxxx$ grunt dist --verbose --stack
Initializing
Command-line options: --verbose, --stack

Reading "Gruntfile.js" Gruntfile...OK

Registering Gruntfile tasks.

Registering "grunt-webfont" local Npm module tasks.
Reading /home/xxxxxx/Bureau/xxxxxx/node_modules/grunt-webfont/package.json...OK
Parsing /home/xxxxxx/Bureau/xxxxxx/node_modules/grunt-webfont/package.json...OK
Loading "webfont.js" tasks...OK
+ webfont
Initializing config...OK
Loading "Gruntfile.js" tasks...OK
+ dist

Running tasks: dist

Running "dist" task

Running "webfont" task
Running "webfont:src" (webfont) task
Verifying property webfont.src exists in config...OK
Files: documents/icons/account.svg, documents/icons/arrow-down.svg, documents/icons/arrow-left.svg, documents/icons/arrow-right.svg, documents/icons/arrow-up.svg, documents/icons/basket.svg, documents/icons/close.svg, documents/icons/minus.svg, documents/icons/plus.svg, documents/icons/search.svg -> src
Verifying property webfont.src.src exists in config...OK
Verifying property webfont.src.dest exists in config...OK
Fatal error: Cannot call method 'split' of undefined
TypeError: Cannot call method 'split' of undefined
    at Object.file.mkdir (/home/xxxxxx/Bureau/xxxxxx/node_modules/grunt/lib/grunt/file.js:187:11)
    at createOutputDirs (/home/xxxxxx/Bureau/xxxxxx/node_modules/grunt-webfont/tasks/webfont.js:147:15)
    at fn (/home/xxxxxx/Bureau/xxxxxx/node_modules/grunt/node_modules/async/lib/async.js:517:34)
    at /home/xxxxxx/Bureau/xxxxxx/node_modules/grunt/node_modules/async/lib/async.js:441:34
    at process._tickCallback (node.js:415:13)
    at Function.Module.runMain (module.js:499:11)
    at startup (node.js:119:16)
    at node.js:901:3

I made the following checks:

  • files permissions are okay
  • detsCss / dest /src folders/files exists
  • my grunfile: http://pastebin.com/nLKP4iAD (removing the trailing slashes had no effect).

ImportError: No module named argparse

$ grunt webfont

Running "webfont:icons" (webfont) task
Warning: Traceback (most recent call last):
File "/home/ec2-user/Uniware/UniwareWebapp/node_modules/grunt-webfont/tasks/scripts/generate.py", line 5, in
import argparse
ImportError: No module named argparse Use --force to continue.

Aborted due to warnings.

I am using python2.6.8 ,
This might be the issue, I am trying to build it on Amazon AMI
I have tried to install python2.7 on AMI but it got messed up and things are still not working !!
I am unable to find that When I run web-font , which path it takes !

Handle duplicate svg names

I use grunt-webfont to merge multiple web fonts library.

For this reason I usually end up with the following structure to store my svgs:

src
 |-- entypo
 |       user.svg
 |       add.svg
 |       ...
 |
 |-- fontawesome
         alert.svg
         add.svg
         add-2.svg
         ...

 Gruntfile.js src option : src/**/*.svg

When running the grunt task to compile the svg, only the first svg file is compiled when there is a duplicate name in another folder.

In the previous example, after the task is run the fontawesome's add.svg glyph will not be created. Only the add.svg of the entypo will be compiled.

Of course, I can manually rename the svg files, but I want to keep the svg files in sync with the online repository where they are hosted. So avoid renaming it.

So, it could be great to add an option to permit the handling of duplicate names.

The script should increment the svg number.

In the given example we will get the following glyphs :
Entypo : icon_add
Fontawesome: icon_add-2, icon_add-3

ttfautohint doesn’t work

Weird error and I can’t google it. And it’s not related to node engine as I thought.

Error: ttfautohint(35930,0x7fff76dfe310) malloc: * error for object 0x7f8979c063f8: incorrect checksum for freed object - object was probably modified after being freed.
* set a breakpoint in malloc_error_break to debug
❯ ttfautohint --version
ttfautohint 0.97
Copyright (C) 2011-2013 Werner Lemberg <[email protected]>.
License: FreeType License (FTL) or GNU GPLv2.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

“No glyphs” warning could be in any language

Russian for example:

Running "webfont:icons" (webfont) task 
Warning: Предупреждение: в шрифтовом файле не было глифов Use --force to continue. 

We have to find another way to check it. Maybe check whether files was created.

Unexpected end of input

I'm trying to run grunt-webfont on windows.

I installed all needed executables, and they are in the path.
I cloned this repo, and launched a grunt build. But I got this error.

grunt-webfont>grunt --verbose
Initializing
Command-line options: --verbose

Reading "Gruntfile.js" Gruntfile...OK

Registering Gruntfile tasks.
Initializing config...OK

Registering "tasks" tasks.
Loading "webfont.js" tasks...OK
+ webfont

Registering "grunt-contrib-jshint" local Npm module tasks.
Reading C:\Users\ggautreau\Perso\grunt-webfont\node_modules\grunt-contrib-jshint\package.json...OK
Parsing C:\Users\ggautreau\Perso\grunt-webfont\node_modules\grunt-contrib-jshint\package.json...OK
Loading "jshint.js" tasks...OK
+ jshint

Registering "grunt-contrib-nodeunit" local Npm module tasks.
Reading C:\Users\ggautreau\Perso\grunt-webfont\node_modules\grunt-contrib-nodeunit\package.json...OK
Parsing C:\Users\ggautreau\Perso\grunt-webfont\node_modules\grunt-contrib-nodeunit\package.json...OK
Loading "nodeunit.js" tasks...OK
+ nodeunit
Loading "Gruntfile.js" tasks...OK
+ clean, default

No tasks specified, running default tasks.
Running tasks: default

Running "default" task

Running "clean" task

Running "webfont" task

Running "webfont:test1" (webfont) task
Verifying property webfont.test1 exists in config...OK
Files: test/src/mailru.svg, test/src/odnoklassniki.svg, test/src/pinterest.svg -> test/tmp
Verifying property webfont.test1.src exists in config...OK
Verifying property webfont.test1.dest exists in config...OK
Reading test/src/mailru.svg...OK
Writing C:\Users\GGAUTR~1\AppData\Local\Temp\d-11302-11332-1ug7vya\test\src\mailru.svg...OK
Reading test/src/odnoklassniki.svg...OK
Writing C:\Users\GGAUTR~1\AppData\Local\Temp\d-11302-11332-1ug7vya\test\src\odnoklassniki.svg...OK
Reading test/src/pinterest.svg...OK
Writing C:\Users\GGAUTR~1\AppData\Local\Temp\d-11302-11332-1ug7vya\test\src\pinterest.svg...OK
Fatal error: Unexpected end of input

Can you help me?

Very small generated font

Hello,

I've just tried to generate a custom webfont with this grunt task, but the generated font looks weird (ie. very small) to me. So I wanted to know if it was a bug or a misuse of the script.

Basically, here is the (ttf) font generated with fontforge:
font-fontforge

And this is the one generated with IcoMoon (with the same svg icons):
font-icomoon

The icons appear very small in the grunt demo page, and I have to put a huge font-size (like 120px) to see them "normally".

I'm running on OSX, fontforge 20120731, and ttfautohint 0.95 (installed via brew).

IE9 .eot font file - blank glyphs

The generated EOT file doesn't display the font in IE9. Looks fine in IE8/WinXP and IE10/Win8. When I compile using fontcustom the font displays properly in IE9. Has anyone ran into this issue?

Ligature and custom Unicode mapping

I love what you're doing here. I would be very interested in having the ability to map each icon to a specific Unicode value. I'd also like to set up ligatures - even if it's by being able to point to a .fea file.

Incorrect font height output

Hi all,
I am currently fighting with grunt-webfont as I am facing an issue with the generated font. It seems that few pixels are added to the font height and I did not manage to find where this is coming from.
On the screenshot, you'll notice that the icon is 36px height instead of being 32px. My inputs are all 512*512px svg files.
Cheers,

EDIT: I have tried to generate the webfont using the FontCustom gem on a ruby based project and everything was fine. Width and height were 32px as expected.

screen shot 2013-11-04 at 10 17 07

generate.py line: 4 Undefined variable: import ?

I am getting this error:
Warning: ~/node_modules/grunt-webfont/tasks/scripts/generate.py line: 4 Undefined variable: import

python and fontforget seem to be installed correctly and everything was working before.

Sass-variables for icons

i use grunt-webfont with sass and create a file with variables for each icon by hand - something like this:

$icon-close: "\f105";
$icon-single-arrow: "\f116";

so i can use them like this:

content: $icon-close;

It would be cool if those variables are generated automatically.

Make the template json file optional

Since the templateOptions were introduced it can overwrite or extend the template json config. What about to make the json file optional ?

Example 1:
my-icons.json

{
    "baseClass": "icon-",
    "classPrefix": "icon-"
}

Gruntfile.js

options: {
    // ...
    template: 'path/to/template/my-icons.css',
    // ...
}

Example 2:
Gruntfile.js

options: {
    // ...
    template: 'path/to/template/my-icons.css',
    templateOptions: {
        "baseClass": "icon-",
        "classPrefix": "icon-"
    }
    // ...
}

In example 2 is not json config file

What do you think about it ?

Generate the 'space' character

I've been testing the inline-block fix from this article and I'd wish the fonts generated via the grunt-webfont task include the 'space' character (zero width).

I tried adding it with Fontlab after generating the font and it seems to do the trick.

Would it be possible?

List of icons

Would it be possible to create some sort of list.md for showing which characters map to which svg file? I realise the generated CSS sort of does this, but I don't wish to use the current naming conventions / selectors it currently offers.

Any help would be appreciated!

Provide option for URL helpers

This may be a bit outside the scope of the project but I'd like to see an option to compile to src:font-url("foo.ttf") instead of just src:url("foo.ttf"). For the sake of automation, this would fit nicely in with different compass configurations for different environments.

My recommendation would be a srcPrefix option that defaults to simply src but can be changed to handle other preprocessors (I speak solely on behalf of compass/sass and don't know what other syntaxes are).

eotlitetool fails with fontforge

Hi,

I'm using grunt-webfont through happyplan, a static website generator.

I'm using fontforge 20120731_b-6 (from the official ArchLinux package) and there seems to be an error when running the eotlitetool.py script.

Here's the output when I run the task:

Warning:   File "/home/madx/Code/PutainDeCode/website/node_modules/happyplan/node_modules/grunt-webfont/tasks/scripts/eotlitetool.py", line 292
    raise FontError, 'truncated font data'
                   ^
SyntaxError: invalid syntax
mv: cannot stat ‘dist/assets/fonts/icons.eotlite’: No such file or directory Use --force to continue.

Aborted due to warnings.

This runs perfectly fine when using fontforge 20110222-1 on a Debian box (reported by @kud) or on OS X (reported by @MoOx)

Use more conventions in the options

Use template as a object in the options?
Example:

options: {
    template: {
        src: 'some/path/to/tpl.css',
        parameters: {
            baseClass: 'glyph-icon',
            classPrefix: 'glyph_',
            mixinPrefix: 'glyph-'
        }
    }
}

Make the htmlDemo option simpler and use it as an optional parameter?
Just renaming the option htmlDemo to demo and use it as an object.
If the option demo is not set the original htmlDemo would be false. So you don't need this extra parameter.

Example:

options: {
    demo: {
        template: '/some/path/to/tpl.html',
        dest: '/dest/path/of/tpl.html'
    }
}

Rename the syntax option into something familiar
Syntax, in my opinion, is something like css, scss and not the class name convention or a framework name.
So it would be better to rename it into something thats more verbose.

Remove obsolete styles option
Since templates have been introduced the styles option is obsolete, because the you can use own templates to generate such partials if you want to.

I felt really confusing to use these irritating option parameters instead of the common pattern which is used in grunt tasks normally. So what do you think about it ?

Of cause i really would like to see these changes coming, so I would create a PR for it.

Why so many dependencies ?

Why do you need others (more?) dependencies than just fontcustom requirements. It seems fontcustom already handle the 4 formats woff, svg, eot, ttf)

On linux, ttf2eot need to be downloaded manually & make install... (no hard to do, but we want to use grunt-webfont on Happy-Plan & be linux compatible without too many requirements for the end-user.

/cc @kud

EnvironmentError: Could not load image file

Verifying property webfont.test exists in config...OK
Files: assets/icons/0000xx/mailru.svg, assets/icons/0000xx/odnoklassniki.svg, assets/icons/0000xx/pinterest.svg -> assets/icons/0000xx/build
Verifying property webfont.test.src exists in config...OK
Verifying property webfont.test.dest exists in config...OK
Reading assets/icons/0000xx/mailru.svg...OK
Writing /private/var/folders/n7/zd9vhm9j09vgqz1cdwsdykdw0000gn/T/d-11372-4052-1dwp4th/mailru.svg...OK
Reading assets/icons/0000xx/odnoklassniki.svg...OK
Writing /private/var/folders/n7/zd9vhm9j09vgqz1cdwsdykdw0000gn/T/d-11372-4052-1dwp4th/odnoklassniki.svg...OK
Reading assets/icons/0000xx/pinterest.svg...OK
Writing /private/var/folders/n7/zd9vhm9j09vgqz1cdwsdykdw0000gn/T/d-11372-4052-1dwp4th/pinterest.svg...OK
fontforge output ignored: Copyright (c) 2000-2012 by George Williams.
fontforge output ignored:  Executable based on sources from 14:57 GMT 31-Jul-2012-D.
fontforge output ignored:  Library based on sources from 14:57 GMT 31-Jul-2012.
Warning: Traceback (most recent call last):
  File "/Users/dwiklund/Desktop/grunt-webfont-test/node_modules/grunt-webfont/tasks/scripts/generate.py", line 73, in <module>
    glyph.importOutlines(filePath)
EnvironmentError: Could not load image file /private/var/folders/n7/zd9vhm9j09vgqz1cdwsdykdw0000gn/T/d-11372-4052-1dwp4th/mailru.svg Use --force to continue.

Keep getteting this error when trying to run the task... i can't figure out why, and can't find any solution to it?

I'm running gunt on Mac OSX v. 10.8.4

EOT font cannot be generated when the project's folder parent's name contains a space.

I use grunt-webfont in a project, let's call it "foo" and this project is inside a folder I called "design guideline" on my hard drive.

When I call the command "grunt webfont -v" a python error is thrown while it tries to generate the ".eot" file (no issues for the other extension). I tried to rename the parent's folder from "design guideline" to "designguideline" without space and everything works fine.

Here is a copy of the trace:

fontforge output ignored: Copyright (c) 2000-2012 by George Williams.
fontforge output ignored:  Executable based on sources from 14:57 GMT 31-Jul-2012-D.
fontforge output ignored:  Library based on sources from 14:57 GMT 31-Jul-2012.
Warning: python: can't open file '/Users/mab/ring/design': [Errno 2] No such file or directory
mv: rename ./debug/assets/fonts/foo-webfont.eotlite to ./debug/assets/fonts/foo-webfont.eot: No such file or directory Use --force to continue.

Error on `grunt webfont`

Copyright (c) 2000-2012 by George Williams.
 Executable based on sources from 14:57 GMT 31-Jul-2012-NoPython-D.
 Library based on sources from 14:57 GMT 31-Jul-2012.
/path/to/node_modules/grunt-webfont/tasks/scripts/generate.py line: 4 Undefined variable: import

installed fontforge by Homebrew (#86)

Setting KERNING = 0 seems to improve antialiasing of icons

Hi!

I was looking into some of the different options for improving antialiasing for some of my square icons.

During my tests, setting KERNING to 0 in generate.py seems to greatly improve anti aliasing, while also making icons sticking more true to their original size in the original SVG:s (i.e no extra spacing added).

With KERNING = 0
0 KERNING

With KERNING = 15
15 KERNING

As you can see, the antialiasing around the edges is much better with KERNING set to 0.

For icons that aren't square this doesn't really seem to make a difference (I've tried with more icons, but included these in the example).

Is there a reason for setting KERNING to 15 that I'm not aware of? Otherwise, my suggestion is to change this it to 0 for improved antialiasing on non-retina displays.

Is ttfautohint optional ?

I'm trying to learn Travis CI too :)
And I get this message on my website build (which include grunt-webfont)

Running "webfont:icons" (webfont) task
Warning: /bin/sh: 1: ttfautohint: not found� Use --force to continue.

Aborted due to warnings.

Done. Build script exited with 1

In the README you tell that if ttfautohint is not here, the font will 'just' not be properly hinted. Is that supposed to be that way ?

error occurred while processing a template: eot is not defined

user$ grunt
Running "clean:0" (clean) task
Cleaning build/fonts...OK
Cleaning build/icons.css...OK

Running "webfont:icons" (webfont) task
Warning: An error occurred while processing a template (eot is not defined). Use --force to continue.

Aborted due to warnings.

All tasks running normal only the webfont task gets an error... maybe someone of you know what to do...

If you need further information, let me know. Thanks in advance :)

How to put custom templates outside of node_modules?

First of all I want to thank you for the work on Grunt webfont. This has really helped in my projects.

I have a fairly extensive system that generates 3 different webfonts, it uses 3 different templates.

Here is a part of the Gruntfile I use to generate the fonts:

# generate 3 webfonts, one for Android system, once for iOS system, one for the app itself
webfont:
    iconsapp:
        src: 'images/icons_svg_source/app/*.svg'
        dest: '.tmp/fonts'
        destCss: 'scss/clank/icon-fonts'
        options:
            font: 'app-icons'
            hashes: false
            htmlDemo: false
            stylesheet: 'scss'
            relativeFontPath: '../fonts'
            syntax: 'custom-app'
    iconsandroid:
        src: 'images/icons_svg_source/android/*.svg'
        dest: '.tmp/fonts'
        destCss: 'scss/clank/icon-fonts'
        options:
            font: 'android-icons'
            hashes: false
            htmlDemo: false
            stylesheet: 'scss'
            relativeFontPath: '../fonts'
            syntax: 'custom-android'
    iconsios:
        src: 'images/icons_svg_source/ios/*.svg'
        dest: '.tmp/fonts'
        destCss: 'scss/clank/icon-fonts'
        options:
            font: 'ios-icons'
            hashes: false
            htmlDemo: false
            stylesheet: 'scss'
            relativeFontPath: '../fonts'
            syntax: 'custom-ios'

As you can see 3 different fonts are generated with 3 different custom templates.

Now, I want to put the custom syntaxes somewhere else than in node-modules/grunt-webfont/tasks/templates.

You're not supposed project info in node-modules for obvious reasons: the folder is often not versioned, and needs to update separately from your project.

If I set syntax to a custom path for example "/font-generation-templates/custom-app" I can't seem to "leave" the node-modules folder using '/' or '../'

For example, setting syntax to `/font-generation-templates/custom-app' returns this error:

Error: ENOENT, no such file or directory '/Users/noone/Sites/pyxbyb/node_modules/grunt-webfont/tasks/templates/font-generation-templates/custom-app.css'

Obviously the directory does not exist, but what I really want to do is reference a directory in the root of my folder.

Am I missing something or is it not possible to have templates live outside the node-modules/grunt-webfont/tasks/templates folder?

Firefox displays font wrong

I generated normally the webfont with grunt webfont with these settings:

            icons: {
                src: '<%= dirs.img %>/icons/*.svg',
                dest: 'fonts',
                destCss: 'src/scss/base',
                options: {
                    embed: false, // woff inline
                    htmlDemo: false,
                    stylesheet: 'scss',
                    syntax: 'bootstrap',
                    relativeFontPath: '/assets/fonts'
                }
            }

And it gets displayed very wired.
bildschirmfoto 2014-01-15 um 00 42 37

Any idea why that happens ?

Data URI embedding

embed: true

Don’t forget to remove generated font files after embedding.

class names associated with incorrect icon

I have noticed when using v0.3.0 the ordering of the class names are now alphabetical (nice touch), but unfortunately the wrong icons are displayed next to the class name.

The icons seem to be in the same order they would have been in 0.2.2.

Font contained no glyphs, really?

Running "webfont:icons" (webfont) task
Verifying property webfont.icons exists in config...OK
Files: src/assets/svg-to-fonts/home.svg -> /icons
Verifying property webfont.icons.src exists in config...OK
Verifying property webfont.icons.dest exists in config...OK
Reading src/assets/svg-to-fonts/home.svg...OK
Writing /tmp/d-11326-25019-5je5k5/src/assets/svg-to-fonts/home.svg...OK
Warning: Warning: Font contained no glyphs Use --force to continue.

Aborted due to warnings.

On ubuntu server.

poke @MoOx

Bus error

Hi all,

Several weeks ago, I have set a gruunt project to generate a font from several eps files with a watch tasks that was looking at the folder where I placed the svg and so on...
So far everything was working well but since I switched to OS X Mavericks, I am facing a major issue that I could not manage to fix on my own so I am coming to seek some help.
Everytime, I add a new icon to my icon source folder, the watch task registers the change and triggers the webfont task but suddenly the process breaks and it throughs me a bus error as the following:

Running "watch" task
[D] Task source: /Users/me/design guideline/gecko/node_modules/grunt-contrib-watch/tasks/watch.js
Waiting...[D] server GET / 200 1154 - 6 ms
[D] server GET /assets/js/gecko.js 200 - - 2 ms
[D] server GET /assets/css/gecko.css 200 75908 - 3 ms
[D] server GET /assets/js/jquery.js 200 261746 - 3 ms
[D] server GET /assets/fonts/museo/museosans_500-webfont.ttf 200 43772 - - ms
OK
>> File "src/_svg/_700/ui-templates.svg" changed.


Running "webfont:gecko300" (webfont) task
[D] Task source: /Users/me/design guideline/gecko/node_modules/grunt-webfont/tasks/webfont.js
[1]    5222 bus error  grunt gecko:debug --debug

Thanks for your help

Add travis-CI

Everything is in the title. Only repo owner can activate that on travis-ci.org :)

Zero glyphs created; no errors reported

I've followed your instructions to a tee, but I can't seem to get any glyphs created with this tool.

Here are my grunt instructions:

webfont: {
    icons: {
        src: 'src/icons/*.svg',
        dest: 'output',
        destCss: 'src/css',
        options: {
            font: 'font-icons',
            hashes: false,
            styles: 'font,icon',
            types: 'woff,ttf,svg',
            syntax: 'bootstrap',
            stylesheet: 'scss',
            htmlDemo: false,
            embed: false
        }
    }
}

Grunt results using verbose mode:

Running "webfont:icons" (webfont) task
Verifying property webfont.icons exists in config...OK
Files: ../themes/modern/src/icons/moreSquares.svg, ../themes/modern/src/icons/squares.svg -> ../themes/modern/publish/
Verifying property webfont.icons.src exists in config...OK
Verifying property webfont.icons.dest exists in config...OK
Reading ../themes/modern/src/icons/moreSquares.svg...OK
Writing /tmp/themes/modern/src/icons/moreSquares.svg...OK
Reading ../themes/modern/src/icons/squares.svg...OK
Writing /tmp/themes/modern/src/icons/squares.svg...OK
Writing ../themes/modern/src/css/objects/_font-icons.scss...OK
Font 'font-icons' with 0 glyphs created.

The weird part:

I was concerned that my SVG may not be fontcustom compatible, but that doesn't seem to be a problem. If I cd to my glyphs folder, icons, and then run fontcustom compile ., everything works fine. The fontcustom tool builds everything properly in that directory. It's just a problem when I use the Grunt way of doing things. :(

Any ideas on what the problem might be?

IE7/8 issues?

It seems the generated EOT isn't compatible. Is anyone getting this issue?

(I have tried the actual unicode characters in HTML, so it's not a CSS issue.)

IE7 stylesheet

Could you add an option to generate a stylesheet for IE7 (like Font Awesome has).

If this is not a priority for you, would you accept a pull request if I did the code?

Thanks for making this grunt task! It is excellent :)

Can & should I output two stylesheets?

I want to create an SCSS stylesheet that incorporates mixins and/or extends. I do not want to write vanilla CSS classes into this stylesheet because I don't need them in my project and don't want unnecessary bulk in my stylesheet. However, in order for the demo HTML template to work, I will need vanilla CSS classes that can be plugged into the HTML document, without precompiling.

Maybe the way to do this is to be able to output multiple stylesheets based on different templates, so I can output one vanilla CSS stylesheet that is loaded into my demo HTML but ignored by the project; and an SCSS stylesheet for the actual project.

Or maybe there's a better way?

Here is the template I'm using: https://gist.github.com/MisterGrumpyPants/6244560

Grunt 0.4 Release

I'm posting this issue to let you know that we will be publishing Grunt 0.4 on Monday, February 18th.

If your plugin is not already Grunt 0.4 compatible, would you please consider updating it? For an overview of what's changed, please see our migration guide.

If you'd like to develop against the final version of Grunt before Monday, please specify "grunt": "0.4.0rc8" as a devDependency in your project. After Monday's release, you'll be able to use "grunt": "~0.4.0" to actually publish your plugin. If you depend on any plugins from the grunt-contrib series, please see our list of release candidates for compatible versions. All of these will be updated to final status when Grunt 0.4 is published.

Also, in an effort to reduce duplication of effort and fragmentation in the developer community, could you review the grunt-contrib series of plugins to see if any of your functionality overlaps significantly with them? Grunt-contrib is community maintained with 40+ contributors—we'd love to discuss any additions you'd like to make.

Finally, we're working on a new task format that doesn't depend on Grunt: it's called node-task. Once this is complete, there will be one more conversion, and then we'll never ask you to upgrade your plugins to support our changes again. Until that happens, thanks for bearing with us!

If you have any questions about how to proceed, please respond here, or join us in #grunt on irc.freenode.net.

Thanks, we really appreciate your work!

Making this as a generic node library & create a grunt task using it

I'm trying gulp right now, & the idea I have in mind is not to fork & modify grunt-webfont to create gulp-webfont.
@sapegin what do you think about creating a node-svg2webfont package that can be reused for this task or without grunt ?

  • Remove Grunt API calls from font generation code.
  • Remove Grunt API calls from font tests.
  • Move as much code as possible to (kinda) lib folder.
  • Create webfont node module, move code there and use it here as dependency.

Patch for truetype font embedding

I have made the following patch to embed ttf-fonts when the embed option is set to true:

file: tasks/webfont.js
line: #159

Maybe you can integrate this feature in the next release.

if (types.indexOf('ttf') !== -1) {
    var fontUrl;
    if (embed) {
        var fontFile = path.join(params.dest, fontName + '.ttf');
        // Convert to data:uri
        var dataUri = fs.readFileSync(fontFile, 'base64');
        fontUrl = 'data:application/x-font-ttf;charset=utf-8;base64,' + dataUri;
        // Remove WOFF file
        fs.unlinkSync(fontFile);
    }
    else {
        fontUrl = '"' + relativeFontPath + fontName + '.ttf"';
    }
    fontSrc2.push('url("' + relativeFontPath + fontName + '.ttf") format("truetype")');
}

Creates every font file except the SVG version

I've been using this plugin for a while and it's really great.
Today i've installed in a new project, where im having an issue thought.

The task task creates all font files except one, the svg file. Im not declaring the order option so it should be the default which includes svg.

The compiled css also doesn't have any mention to the svg file:

@font-face {
    font-family:"icons";
    src:url("fonts/icons-c684a8177ba92804b3dfeba3dd1397c0.eot");
    src:url("fonts/icons-c684a8177ba92804b3dfeba3dd1397c0.eot?#iefix") format("embedded-opentype"),
        url("fonts/icons-c684a8177ba92804b3dfeba3dd1397c0.woff") format("woff"),
        url("fonts/icons-c684a8177ba92804b3dfeba3dd1397c0.ttf") format("truetype");
    font-weight:normal;
    font-style:normal;
}

Am I missing something here?

Font file src order

Any way to define the order of the src links, so that I can have SVG before WOFF files in the generated output, like this:

    src:url("../css-src/global/iconfont/icons-659ac64f9fa83eaea1830d648b806fd1.eot?#iefix") format("embedded-opentype"),
        url("../css-src/global/iconfont/icons-659ac64f9fa83eaea1830d648b806fd1.svg?#icons") format("svg"),
        url("../css-src/global/iconfont/icons-659ac64f9fa83eaea1830d648b806fd1.woff") format("woff"),
        url("../css-src/global/iconfont/icons-659ac64f9fa83eaea1830d648b806fd1.ttf") format("truetype");

The reason im doing this manually every time I compile my webfont is because Chrome on windows has terrible font-rendering with any other format than SVG.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.