Skip to content

Commit

Permalink
build hash
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Bradley committed Nov 5, 2013
1 parent 1bf1676 commit e070ec1
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 37 deletions.
1 change: 1 addition & 0 deletions builder/manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"build_hash": "cd2da65727042f2c6181be7bc958a281",
"prefix": "ion-",
"version": "1.3.0",
"name": "Ionicons",
Expand Down
84 changes: 48 additions & 36 deletions builder/scripts/generate_font.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fontforge
import os
import md5
import subprocess
import tempfile
import json
Expand All @@ -12,6 +13,7 @@
KERNING = 15

cp = 0xf100
m = md5.new()

f = fontforge.font()
f.encoding = 'UnicodeFull'
Expand All @@ -31,6 +33,7 @@
for filename in filenames:
name, ext = os.path.splitext(filename)
filePath = os.path.join(dirname, filename)
size = os.path.getsize(filePath)

if ext in ['.svg', '.eps']:

Expand Down Expand Up @@ -83,6 +86,7 @@
filePath = tmpsvgfile.name
# end hack

m.update(name + str(size) + ';')
glyph = f.createChar( int(chr_code, 16) )
glyph.importOutlines(filePath)

Expand All @@ -104,40 +108,48 @@

fontfile = '%s/%s' % (OUTPUT_FONT_DIR, font_name.lower())

f.fontname = font_name
f.familyname = font_name
f.fullname = font_name
f.generate(fontfile + '.ttf')
f.generate(fontfile + '.svg')

# Fix SVG header for webkit
# from: https://github.com/fontello/font-builder/blob/master/bin/fontconvert.py
svgfile = open(fontfile + '.svg', 'r+')
svgtext = svgfile.read()
svgfile.seek(0)
svgfile.write(svgtext.replace('''<svg>''', '''<svg xmlns="http://www.w3.org/2000/svg">'''))
svgfile.close()

scriptPath = os.path.dirname(os.path.realpath(__file__))
try:
subprocess.Popen([scriptPath + '/sfnt2woff', fontfile + '.ttf'], stdout=subprocess.PIPE)
except OSError:
# If the local version of sfnt2woff fails (i.e., on Linux), try to use the
# global version. This allows us to avoid forcing OS X users to compile
# sfnt2woff from source, simplifying install.
subprocess.call(['sfnt2woff', fontfile + '.ttf'])

# eotlitetool.py script to generate IE7-compatible .eot fonts
subprocess.call('python ' + scriptPath + '/eotlitetool.py ' + fontfile + '.ttf -o ' + fontfile + '.eot', shell=True)
subprocess.call('mv ' + fontfile + '.eotlite ' + fontfile + '.eot', shell=True)

# Hint the TTF file
subprocess.call('ttfautohint -s -f -n ' + fontfile + '.ttf ' + fontfile + '-hinted.ttf > /dev/null 2>&1 && mv ' + fontfile + '-hinted.ttf ' + fontfile + '.ttf', shell=True)

manifest_data['icons'] = sorted(manifest_data['icons'], key=lambda k: k['name'])

print "Save Manifest, Icons: %s" % ( len(manifest_data['icons']) )
manifest_file = open(MANIFEST_PATH, 'w')
manifest_file.write( json.dumps(manifest_data, indent=2, separators=(',', ': ')) )
manifest_file.close()
build_hash = m.hexdigest()

if build_hash == manifest_data.get('build_hash'):
print "Source files unchanged, did not rebuild fonts"

else:
manifest_data['build_hash'] = build_hash

f.fontname = font_name
f.familyname = font_name
f.fullname = font_name
f.generate(fontfile + '.ttf')
f.generate(fontfile + '.svg')

# Fix SVG header for webkit
# from: https://github.com/fontello/font-builder/blob/master/bin/fontconvert.py
svgfile = open(fontfile + '.svg', 'r+')
svgtext = svgfile.read()
svgfile.seek(0)
svgfile.write(svgtext.replace('''<svg>''', '''<svg xmlns="http://www.w3.org/2000/svg">'''))
svgfile.close()

scriptPath = os.path.dirname(os.path.realpath(__file__))
try:
subprocess.Popen([scriptPath + '/sfnt2woff', fontfile + '.ttf'], stdout=subprocess.PIPE)
except OSError:
# If the local version of sfnt2woff fails (i.e., on Linux), try to use the
# global version. This allows us to avoid forcing OS X users to compile
# sfnt2woff from source, simplifying install.
subprocess.call(['sfnt2woff', fontfile + '.ttf'])

# eotlitetool.py script to generate IE7-compatible .eot fonts
subprocess.call('python ' + scriptPath + '/eotlitetool.py ' + fontfile + '.ttf -o ' + fontfile + '.eot', shell=True)
subprocess.call('mv ' + fontfile + '.eotlite ' + fontfile + '.eot', shell=True)

# Hint the TTF file
subprocess.call('ttfautohint -s -f -n ' + fontfile + '.ttf ' + fontfile + '-hinted.ttf > /dev/null 2>&1 && mv ' + fontfile + '-hinted.ttf ' + fontfile + '.ttf', shell=True)

manifest_data['icons'] = sorted(manifest_data['icons'], key=lambda k: k['name'])

print "Save Manifest, Icons: %s" % ( len(manifest_data['icons']) )
manifest_file = open(MANIFEST_PATH, 'w')
manifest_file.write( json.dumps(manifest_data, indent=2, separators=(',', ': ')) )
manifest_file.close()

Binary file modified fonts/ionicons.eot
Binary file not shown.
2 changes: 1 addition & 1 deletion fonts/ionicons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fonts/ionicons.ttf
Binary file not shown.
Binary file modified fonts/ionicons.woff
Binary file not shown.

0 comments on commit e070ec1

Please sign in to comment.