|
1 | 1 | import fontforge |
2 | 2 | import os |
| 3 | +import md5 |
3 | 4 | import subprocess |
4 | 5 | import tempfile |
5 | 6 | import json |
|
12 | 13 | KERNING = 15 |
13 | 14 |
|
14 | 15 | cp = 0xf100 |
| 16 | +m = md5.new() |
15 | 17 |
|
16 | 18 | f = fontforge.font() |
17 | 19 | f.encoding = 'UnicodeFull' |
|
31 | 33 | for filename in filenames: |
32 | 34 | name, ext = os.path.splitext(filename) |
33 | 35 | filePath = os.path.join(dirname, filename) |
| 36 | + size = os.path.getsize(filePath) |
34 | 37 |
|
35 | 38 | if ext in ['.svg', '.eps']: |
36 | 39 |
|
|
83 | 86 | filePath = tmpsvgfile.name |
84 | 87 | # end hack |
85 | 88 |
|
| 89 | + m.update(name + str(size) + ';') |
86 | 90 | glyph = f.createChar( int(chr_code, 16) ) |
87 | 91 | glyph.importOutlines(filePath) |
88 | 92 |
|
|
104 | 108 |
|
105 | 109 | fontfile = '%s/%s' % (OUTPUT_FONT_DIR, font_name.lower()) |
106 | 110 |
|
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() |
143 | 155 |
|
0 commit comments