Skip to content

Commit e070ec1

Browse files
author
Adam Bradley
committed
build hash
1 parent 1bf1676 commit e070ec1

File tree

6 files changed

+50
-37
lines changed

6 files changed

+50
-37
lines changed

builder/manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"build_hash": "cd2da65727042f2c6181be7bc958a281",
23
"prefix": "ion-",
34
"version": "1.3.0",
45
"name": "Ionicons",

builder/scripts/generate_font.py

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fontforge
22
import os
3+
import md5
34
import subprocess
45
import tempfile
56
import json
@@ -12,6 +13,7 @@
1213
KERNING = 15
1314

1415
cp = 0xf100
16+
m = md5.new()
1517

1618
f = fontforge.font()
1719
f.encoding = 'UnicodeFull'
@@ -31,6 +33,7 @@
3133
for filename in filenames:
3234
name, ext = os.path.splitext(filename)
3335
filePath = os.path.join(dirname, filename)
36+
size = os.path.getsize(filePath)
3437

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

@@ -83,6 +86,7 @@
8386
filePath = tmpsvgfile.name
8487
# end hack
8588

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

@@ -104,40 +108,48 @@
104108

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

107-
f.fontname = font_name
108-
f.familyname = font_name
109-
f.fullname = font_name
110-
f.generate(fontfile + '.ttf')
111-
f.generate(fontfile + '.svg')
112-
113-
# Fix SVG header for webkit
114-
# from: https://github.com/fontello/font-builder/blob/master/bin/fontconvert.py
115-
svgfile = open(fontfile + '.svg', 'r+')
116-
svgtext = svgfile.read()
117-
svgfile.seek(0)
118-
svgfile.write(svgtext.replace('''<svg>''', '''<svg xmlns="http://www.w3.org/2000/svg">'''))
119-
svgfile.close()
120-
121-
scriptPath = os.path.dirname(os.path.realpath(__file__))
122-
try:
123-
subprocess.Popen([scriptPath + '/sfnt2woff', fontfile + '.ttf'], stdout=subprocess.PIPE)
124-
except OSError:
125-
# If the local version of sfnt2woff fails (i.e., on Linux), try to use the
126-
# global version. This allows us to avoid forcing OS X users to compile
127-
# sfnt2woff from source, simplifying install.
128-
subprocess.call(['sfnt2woff', fontfile + '.ttf'])
129-
130-
# eotlitetool.py script to generate IE7-compatible .eot fonts
131-
subprocess.call('python ' + scriptPath + '/eotlitetool.py ' + fontfile + '.ttf -o ' + fontfile + '.eot', shell=True)
132-
subprocess.call('mv ' + fontfile + '.eotlite ' + fontfile + '.eot', shell=True)
133-
134-
# Hint the TTF file
135-
subprocess.call('ttfautohint -s -f -n ' + fontfile + '.ttf ' + fontfile + '-hinted.ttf > /dev/null 2>&1 && mv ' + fontfile + '-hinted.ttf ' + fontfile + '.ttf', shell=True)
136-
137-
manifest_data['icons'] = sorted(manifest_data['icons'], key=lambda k: k['name'])
138-
139-
print "Save Manifest, Icons: %s" % ( len(manifest_data['icons']) )
140-
manifest_file = open(MANIFEST_PATH, 'w')
141-
manifest_file.write( json.dumps(manifest_data, indent=2, separators=(',', ': ')) )
142-
manifest_file.close()
111+
build_hash = m.hexdigest()
112+
113+
if build_hash == manifest_data.get('build_hash'):
114+
print "Source files unchanged, did not rebuild fonts"
115+
116+
else:
117+
manifest_data['build_hash'] = build_hash
118+
119+
f.fontname = font_name
120+
f.familyname = font_name
121+
f.fullname = font_name
122+
f.generate(fontfile + '.ttf')
123+
f.generate(fontfile + '.svg')
124+
125+
# Fix SVG header for webkit
126+
# from: https://github.com/fontello/font-builder/blob/master/bin/fontconvert.py
127+
svgfile = open(fontfile + '.svg', 'r+')
128+
svgtext = svgfile.read()
129+
svgfile.seek(0)
130+
svgfile.write(svgtext.replace('''<svg>''', '''<svg xmlns="http://www.w3.org/2000/svg">'''))
131+
svgfile.close()
132+
133+
scriptPath = os.path.dirname(os.path.realpath(__file__))
134+
try:
135+
subprocess.Popen([scriptPath + '/sfnt2woff', fontfile + '.ttf'], stdout=subprocess.PIPE)
136+
except OSError:
137+
# If the local version of sfnt2woff fails (i.e., on Linux), try to use the
138+
# global version. This allows us to avoid forcing OS X users to compile
139+
# sfnt2woff from source, simplifying install.
140+
subprocess.call(['sfnt2woff', fontfile + '.ttf'])
141+
142+
# eotlitetool.py script to generate IE7-compatible .eot fonts
143+
subprocess.call('python ' + scriptPath + '/eotlitetool.py ' + fontfile + '.ttf -o ' + fontfile + '.eot', shell=True)
144+
subprocess.call('mv ' + fontfile + '.eotlite ' + fontfile + '.eot', shell=True)
145+
146+
# Hint the TTF file
147+
subprocess.call('ttfautohint -s -f -n ' + fontfile + '.ttf ' + fontfile + '-hinted.ttf > /dev/null 2>&1 && mv ' + fontfile + '-hinted.ttf ' + fontfile + '.ttf', shell=True)
148+
149+
manifest_data['icons'] = sorted(manifest_data['icons'], key=lambda k: k['name'])
150+
151+
print "Save Manifest, Icons: %s" % ( len(manifest_data['icons']) )
152+
manifest_file = open(MANIFEST_PATH, 'w')
153+
manifest_file.write( json.dumps(manifest_data, indent=2, separators=(',', ': ')) )
154+
manifest_file.close()
143155

fonts/ionicons.eot

0 Bytes
Binary file not shown.

fonts/ionicons.svg

Lines changed: 1 addition & 1 deletion
Loading

fonts/ionicons.ttf

0 Bytes
Binary file not shown.

fonts/ionicons.woff

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)