lib/fontcustom/scripts/generate.py in fontcustom-0.1.2 vs lib/fontcustom/scripts/generate.py in fontcustom-0.1.3
- old
+ new
@@ -8,19 +8,21 @@
import argparse
parser = argparse.ArgumentParser(description='Convert a directory of svg and eps files into a unified font file.')
parser.add_argument('dir', metavar='directory', type=unicode, nargs=2, help='directory of vector files')
parser.add_argument('--name', metavar='fontname', type=unicode, nargs='?', default='fontcustom', help='reference name of the font (no spaces)')
parser.add_argument('--nohash', '-n', action='store_true', help='disable hash fingerprinting of font files')
+ parser.add_argument('--debug', '-d', action='store_true', help='display debug messages')
args = parser.parse_args()
indir = args.dir[0]
outdir = args.dir[1]
except ImportError:
# Older Pythons don't have argparse, so we use optparse instead
import optparse
parser = optparse.OptionParser(description='Convert a directory of svg and eps files into a unified font file.')
parser.add_option('--name', metavar='fontname', type='string', nargs='?', default='fontcustom', help='reference name of the font (no spaces)')
parser.add_option('--nohash', '-n', action='store_true', help='disable hash fingerprinting of font files')
+ parser.add_argument('--debug', '-d', action='store_true', help='display debug messages')
(args, posargs) = parser.parse_args()
indir = posargs[0]
outdir = posargs[1]
f = fontforge.font()
@@ -37,10 +39,27 @@
name, ext = os.path.splitext(filename)
filePath = os.path.join(dirname, filename)
size = os.path.getsize(filePath)
if ext in ['.svg', '.eps']:
+ if ext in ['.svg']:
+ # hack removal of <switch> </switch> tags
+ svgfile = open(filePath, 'r+')
+ svgtext = svgfile.read()
+ svgfile.seek(0)
+
+ # replace the <switch> </switch> tags with 'nothing'
+ svgtext = svgtext.replace('<switch>', '')
+ svgtext = svgtext.replace('</switch>', '')
+
+ # remove all contents of file so that we can write out the new contents
+ svgfile.truncate()
+ svgfile.write(svgtext)
+
+ svgfile.close()
+ # end hack
+
m.update(filename + str(size) + ';')
glyph = f.createChar(cp)
glyph.importOutlines(filePath)
glyph.left_side_bearing = KERNING
@@ -80,9 +99,11 @@
# 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'])
-subprocess.call('mkeot ' + fontfile + '.ttf > ' + fontfile + '.eot', shell=True)
+# 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 -n ' + fontfile + '.ttf ' + fontfile + '-hinted.ttf > /dev/null 2>&1 && mv ' + fontfile + '-hinted.ttf ' + fontfile + '.ttf', shell=True)