<commit_before># Based on https://github.com/FontCustom/fontcustom/blob/master/lib/fontcustom/scripts/generate.py

import fontforge
import os
import argparse
import md5
import json
from subprocess import call
from distutils.spawn import find_executable


parser = argparse.ArgumentParser(description='Convert a directory of SVG and EPS files into a unified font file.')
parser.add_argument('input_dir', metavar='directory', type=unicode, help='directory of vector files')
parser.add_argument('output_dir', metavar='directory', type=unicode, help='output directory')
parser.add_argument('font', metavar='font', type=unicode, help='font name')
parser.add_argument('types', metavar='types', type=lambda s: s.split(','), help='output types')
parser.add_argument('--hashes', action='store_true', help='add hashes to file names')
parser.add_argument('--ligatures', action='store_true', help='add hashes to file names')
args = parser.parse_args()


f = fontforge.font()
f.encoding = 'UnicodeFull'
f.design_size = 16
f.em = 512
f.ascent = 448
f.descent = 64

m = md5.new()
cp = 0xf100
files = []

KERNING = 15

def empty_char(f, c):
	pen = f.createChar(ord(c), c).glyphPen()
	pen.moveTo((0,0))
	pen = None

if args.ligatures:
	f.addLookup("liga", "gsub_ligature", (), (("liga",(("latn",("dflt")),)),))
	f.addLookupSubtable("liga", "liga")

for dirname, dirnames, filenames in os.walk(args.input_dir):
	for filename in filenames:
		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: Remove <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()

			m.update(filename + str(size) + ';')
			if args.ligatures:
				[empty_char(f,c) for c in name]
				glyph = f.createChar(cp, name)
				glyph.addPosSub("liga", tuple(name))
			else:
				glyph = f.createChar(cp)
			glyph.importOutlines(filePath)

			# glyph.left_side_bearing = KERNING
			# glyph.right_side_bearing = KERNING
			glyph.width = 512

			# possible optimization?
			# glyph.simplify()
			# glyph.round()

			files.append(name)
			cp += 1

fontfile = args.output_dir + '/' + args.font
if args.hashes:
	fontfile += '-' + m.hexdigest()

f.fontname = args.font
f.familyname = args.font
f.fullname = args.font

if args.ligatures:
	def generate(filename):
		f.generate(filename, flags=("opentype"))
else:
	def generate(filename):
		f.generate(filename)
	

# TTF
generate(fontfile + '.ttf')

# SVG
if 'svg' in args.types:
	generate(fontfile + '.svg')

	# Fix SVG header for webkit (from: https://github.com/fontello/font-builder/blob/master/bin/fontconvert.py)
	svgfile = open(fontfile + '.svg', 'r+')
	svgtext = svgfile.read()
	svgfile.seek(0)
	svgfile.write(svgtext.replace('<svg>', '<svg xmlns="http://www.w3.org/2000/svg">'))
	svgfile.close()

scriptPath = os.path.dirname(os.path.realpath(__file__))

# WOFF
if 'woff' in args.types:
	generate(fontfile + ".woff")
<commit_msg>Changing help string for --ligature option and cleaning up code style.<commit_after># Based on https://github.com/FontCustom/fontcustom/blob/master/lib/fontcustom/scripts/generate.py

import fontforge
import os
import argparse
import md5
import json
from subprocess import call
from distutils.spawn import find_executable


parser = argparse.ArgumentParser(description='Convert a directory of SVG and EPS files into a unified font file.')
parser.add_argument('input_dir', metavar='directory', type=unicode, help='directory of vector files')
parser.add_argument('output_dir', metavar='directory', type=unicode, help='output directory')
parser.add_argument('font', metavar='font', type=unicode, help='font name')
parser.add_argument('types', metavar='types', type=lambda s: s.split(','), help='output types')
parser.add_argument('--hashes', action='store_true', help='add hashes to file names')
parser.add_argument('--ligatures', action='store_true', help='add opentype ligatures to generated font files')
args = parser.parse_args()


f = fontforge.font()
f.encoding = 'UnicodeFull'
f.design_size = 16
f.em = 512
f.ascent = 448
f.descent = 64

m = md5.new()
cp = 0xf100
files = []

KERNING = 15

def empty_char(f, c):
	pen = f.createChar(ord(c), c).glyphPen()
	pen.moveTo((0,0))
	pen = None

if args.ligatures:
	f.addLookup('liga', 'gsub_ligature', (), (('liga',(('latn',('dflt')),)),))
	f.addLookupSubtable('liga', 'liga')

for dirname, dirnames, filenames in os.walk(args.input_dir):
	for filename in filenames:
		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: Remove <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()

			m.update(filename + str(size) + ';')
			if args.ligatures:
				[empty_char(f,c) for c in name]
				glyph = f.createChar(cp, name)
				glyph.addPosSub('liga', tuple(name))
			else:
				glyph = f.createChar(cp)
			glyph.importOutlines(filePath)

			# glyph.left_side_bearing = KERNING
			# glyph.right_side_bearing = KERNING
			glyph.width = 512

			# possible optimization?
			# glyph.simplify()
			# glyph.round()

			files.append(name)
			cp += 1

fontfile = args.output_dir + '/' + args.font
if args.hashes:
	fontfile += '-' + m.hexdigest()

f.fontname = args.font
f.familyname = args.font
f.fullname = args.font

if args.ligatures:
	def generate(filename):
		f.generate(filename, flags=('opentype'))
else:
	def generate(filename):
		f.generate(filename)
	

# TTF
generate(fontfile + '.ttf')

# SVG
if 'svg' in args.types:
	generate(fontfile + '.svg')

	# Fix SVG header for webkit (from: https://github.com/fontello/font-builder/blob/master/bin/fontconvert.py)
	svgfile = open(fontfile + '.svg', 'r+')
	svgtext = svgfile.read()
	svgfile.seek(0)
	svgfile.write(svgtext.replace('<svg>', '<svg xmlns="http://www.w3.org/2000/svg">'))
	svgfile.close()

scriptPath = os.path.dirname(os.path.realpath(__file__))

# WOFF
if 'woff' in args.types:
	generate(fontfile + '.woff')

{'fraction_non_alphanumeric': 0.15767448811836796, 'fraction_numerical': 0.009266178448662381, 'mean_word_length': 4.449511400651466, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2942053', 'n_tokens_mistral': 2598, 'n_tokens_neox': 2333, 'n_words': 548}