2424# TODO 2013-04-08 ensure the menu files are as compact as possible by default, similar to subset.pl
2525# TODO 2013-05-22 in Arimo, the latin subset doesn't include ; but the greek does. why on earth is this happening?
2626from __future__ import print_function
27- import fontforge
28- import sys
27+
2928import getopt
3029import os
31- import subprocess
3230import struct
31+ import subprocess
32+ import sys
33+
34+ import fontforge
35+
3336
3437def log_namelist (nam , unicode ):
3538 if nam and isinstance (unicode , int ):
@@ -46,7 +49,7 @@ def select_with_refs(font, unicode, newfont, pe = None, nam = None):
4649 log_namelist (nam , ref [0 ])
4750 if pe :
4851 print ('SelectMore("%s")' % ref [0 ], file = pe )
49- except :
52+ except Exception :
5053 print ('Resolving references on u+%04x failed' % unicode )
5154
5255def subset_font_raw (font_in , font_out , unicodes , opts ):
@@ -56,18 +59,18 @@ def subset_font_raw(font_in, font_out, unicodes, opts):
5659 # and invert comments on following 2 lines
5760 # nam_fn = opts['--namelist']
5861 nam_fn = font_out + '.nam'
59- nam = file (nam_fn , 'w' )
62+ nam = open (nam_fn , 'w' )
6063 else :
6164 nam = None
6265 if '--script' in opts :
6366 pe_fn = "/tmp/script.pe"
64- pe = file (pe_fn , 'w' )
67+ pe = open (pe_fn , 'w' )
6568 else :
6669 pe = None
6770 font = fontforge .open (font_in )
6871 if pe :
69- print ('Open("' + font_in + '")' , file = pe )
70- extract_vert_to_script (font_in , pe )
72+ print ('Open("' + font_in + '")' , file = pe )
73+ extract_vert_to_script (font_in , pe )
7174 for i in unicodes :
7275 select_with_refs (font , i , font , pe , nam )
7376
@@ -161,7 +164,7 @@ def subset_font_raw(font_in, font_out, unicodes, opts):
161164def subset_font (font_in , font_out , unicodes , opts ):
162165 font_out_raw = font_out
163166 if not font_out_raw .endswith ('.ttf' ):
164- font_out_raw += '.ttf' ;
167+ font_out_raw += '.ttf'
165168 subset_font_raw (font_in , font_out_raw , unicodes , opts )
166169 if font_out != font_out_raw :
167170 os .rename (font_out_raw , font_out )
@@ -340,7 +343,8 @@ def set_os2_vert(pe, name, val):
340343# http://sourceforge.net/mailarchive/forum.php?thread_name=20100906085718.GB1907%40khaled-laptop&forum_name=fontforge-users
341344
342345def extract_vert_to_script (font_in , pe ):
343- data = file (font_in , 'rb' ).read ()
346+ with open (font_in , 'rb' ) as in_file :
347+ data = in_file .read ()
344348 sfnt = Sfnt (data )
345349 hhea = sfnt .hhea ()
346350 os2 = sfnt .os2 ()
0 commit comments