lib/fontcustom/scripts/generate.py in fontcustom-1.3.8 vs lib/fontcustom/scripts/generate.py in fontcustom-2.0.0
- old
+ new
@@ -37,10 +37,11 @@
font.ascent = options['font_ascent']
font.descent = options['font_descent']
font.fontname = options['font_name']
font.familyname = options['font_name']
font.fullname = options['font_name']
+font.copyright = options['copyright']
if options['autowidth']:
font.autoWidth(0, 0, options['font_em'])
#
# Glyphs
@@ -51,21 +52,21 @@
svgtext = svgfile.read()
svgfile.close()
tmpsvgfile = tempfile.NamedTemporaryFile(suffix=".svg", delete=False)
svgtext = svgtext.replace('<switch>', '')
svgtext = svgtext.replace('</switch>', '')
- tmpsvgfile.file.write(svgtext)
+ tmpsvgfile.file.write(svgtext.encode('utf-8'))
tmpsvgfile.file.close()
return tmpsvgfile.name
def createGlyph( name, source, code ):
frag, ext = os.path.splitext(source)
if ext == '.svg':
temp = removeSwitchFromSvg(source)
- glyph = font.createChar(code)
+ glyph = font.createChar(code, name)
glyph.importOutlines(temp)
os.unlink(temp)
if options['autowidth']:
glyph.left_side_bearing = glyph.right_side_bearing = 0
@@ -81,11 +82,11 @@
# Add valid space glyph to avoid "unknown character" box on IE11
glyph = font.createChar(32)
glyph.width = 200
-for glyph, data in manifest['glyphs'].iteritems():
+for glyph, data in manifest['glyphs'].items():
name = createGlyph(glyph, data['source'], data['codepoint'])
#
# Generate Files
#
@@ -110,21 +111,33 @@
svgfile.close()
# Convert WOFF
scriptPath = os.path.dirname(os.path.realpath(__file__))
try:
- subprocess.Popen([scriptPath + '/sfnt2woff', fontfile + '.ttf'], stdout=subprocess.PIPE)
+ # check if on windows
+ if os.name == 'nt':
+ subprocess.Popen([scriptPath + '/sfnt2woff.exe', fontfile + '.ttf'], stdout=subprocess.PIPE)
+ else:
+ 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'])
manifest['fonts'].append(fontfile + '.woff')
# Convert EOT for IE7
subprocess.call('python ' + scriptPath + '/eotlitetool.py ' + fontfile + '.ttf -o ' + fontfile + '.eot', shell=True)
- subprocess.call('mv ' + fontfile + '.eotlite ' + fontfile + '.eot', shell=True)
+ # check if windows
+ if os.name == 'nt':
+ subprocess.call('move ' + fontfile + '.eotlite ' + fontfile + '.eot', shell=True)
+ else:
+ subprocess.call('mv ' + fontfile + '.eotlite ' + fontfile + '.eot', shell=True)
manifest['fonts'].append(fontfile + '.eot')
+
+ # Convert TTF to WOFF2
+ subprocess.call('woff2_compress \'' + fontfile + '.ttf\'', shell=True)
+ manifest['fonts'].append(fontfile + '.woff2')
finally:
manifestfile.seek(0)
manifestfile.write(json.dumps(manifest, indent=2, sort_keys=True))
manifestfile.truncate()