Optimize TTF fonts and make font subsets with Grunt
This plugin requires Grunt ~0.4.1
and Perl
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-font-optimizer --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-font-optimizer');
In your project's Gruntfile, add a section named font_optimizer
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
font_optimizer: {
default: {
options: {
// Characters to include
chars: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
// Features to include.
includeFeatures: ['kern']
},
files: {
'fonts/font-optimized.ttf': ['fonts/font.ttf'],
},
},
},
})
Type: String
Default value: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
List of characters to include in the optimized subset of font.
Type: Array
Default value: ['kern']
Font features to include in the optimized font.
See list of all supported font features: http://en.wikipedia.org/wiki/OpenType_feature_tag_list#OpenType_typographic_features
Default behaviour is to add each font as it's own row to the option.files
grunt.initConfig({
font_optimizer: {
default: {
options: {},
files: {
'fonts/font-optimized.ttf': ['fonts/font.ttf'],
'fonts/font2-optimized.ttf': ['fonts/font2.ttf'],
},
},
},
})
You can also describe a wildcard selector to include e.g. the whole directory.
In That case, describe a folder (ending with /
) as the target:
grunt.initConfig({
font_optimizer: {
default: {
options: {},
files: {
'optimized-fonts/': ['fonts/*.ttf'],
},
},
},
})
Uses Font Optimizer perl script
by Philip Taylor to do the optimization.
Font Optimizer script licensed under MIT license (found in
/lib/font-optimizer/LICENSE
).