Skip to content

Commit 397c4cf

Browse files
committed
try to use fontforge for woff2 generation
1 parent 37a3558 commit 397c4cf

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/tasks/webfonts.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,10 @@ module.exports = function webFonts(grunt) {
333333
* @param {Function} done
334334
*/
335335
function generateWoff2Font(done) {
336-
if (!has(defaultOptions.types, 'woff2')) {
336+
if (
337+
!has(defaultOptions.types, 'woff2') ||
338+
fs.existsSync(wf.getFontPath(defaultOptions, 'woff2'))
339+
) {
337340
done();
338341
return;
339342
}

tasks/engines/fontforge/generate.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,24 @@ def generate(filename):
118118
if 'woff' in args['types']:
119119
generate(fontfile + '.woff')
120120

121+
# WOFF2
122+
woff2_generated = False
123+
if ('woff2' in args['types']):
124+
try:
125+
generate(fontfile + '.woff2')
126+
woff2_generated = True
127+
except Exception as ext:
128+
print('Current version of FontForge seems to be unable to generate woff2 font, falling back to ttf2woff2, reason is %s', ext)
129+
else:
130+
woff2_generated = True
131+
121132
# EOT
122133
if 'eot' in args['types']:
123134
# eotlitetool.py script to generate IE7-compatible .eot fonts
124135
call('python "%(path)s/../../bin/eotlitetool.py" "%(font)s.ttf" --output "%(font)s.eot"' % {'path': scriptPath, 'font': fontfile}, shell=True)
125136

126137
# Delete TTF if not needed
127-
if ('ttf' not in args['types']) and ('woff2' not in args['types']):
138+
if ('ttf' not in args['types']) and woff2_generated:
128139
os.remove(fontfile + '.ttf')
129140

130141
print(json.dumps({'file': fontfile}))

0 commit comments

Comments
 (0)