Skip to content

Commit

Permalink
Make font-patcher Python 3 compatible.
Browse files Browse the repository at this point in the history
Fedora's fontforge modules only work on Python 3. The small changes in
this patch make font-patcher work on Python 3 so I can run the script on
Fedora (26 at least, I don't know about older versions)
  • Loading branch information
agriffis authored and ryanoasis committed May 19, 2017
1 parent f6f10b1 commit bbc922e
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions font-patcher
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env python2
#!/usr/bin/env python
# coding=utf8
# version: 1.0.0

from __future__ import absolute_import, print_function, unicode_literals

version = "1.0.0"
projectName = "Nerd Fonts"
projectNameAbbreviation = "NF"
Expand Down Expand Up @@ -71,8 +73,8 @@ actualVersion = int(fontforge.version())
# versions tested: 20150612, 20150824

if actualVersion < minimumVersion:
print projectName + ": You seem to be using an unsupported (old) version of fontforge: " + str(actualVersion)
print projectName + ": Please use at least version: " + str(minimumVersion)
print("{}: You seem to be using an unsupported (old) version of fontforge: {}".format(projectName, actualVersion))
print("{}: Please use at least version: {}".format(projectName, minimumVersion))
sys.exit(1)

verboseAdditionalFontNameSuffix = " " + projectNameSingular
Expand Down Expand Up @@ -151,7 +153,7 @@ try:
# now we have the correct item:
subFamily = sourceFont.sfnt_names[subFamilyTupleIndex][sfntNamesStringIDIndex]
except IndexError:
print projectName + ": Could not find 'SubFamily' for given font, falling back to parsed fontname"
print("{}: Could not find 'SubFamily' for given font, falling back to parsed fontname".format(projectName))
subFamily = fallbackStyle

# some fonts have inaccurate 'SubFamily', if it is Regular let us trust the filename more:
Expand All @@ -178,7 +180,7 @@ fontname += '-' + subFamily
# rename font

def replace_all(text, dic):
for i, j in dic.iteritems():
for i, j in dic.items():
text = text.replace(i, j)
return text

Expand Down Expand Up @@ -222,9 +224,9 @@ sourceFont.comment = projectInfo
sourceFont.fontlog = projectInfo + "\n\n" + changelog.read()

# todo version not being set for all font types (e.g. ttf)
#print "Version was " + sourceFont.version
#print("Version was {}".format(sourceFont.version))
sourceFont.version += ";" + projectName + " " + version
#print "Version now is " + sourceFont.version
#print("Version now is {}".format(sourceFont.version))

# Prevent glyph encoding position conflicts between glyph sets

Expand Down Expand Up @@ -466,7 +468,7 @@ def copy_glyphs(sourceFont, sourceFontStart, sourceFontEnd, symbolFont, symbolFo
sourceFontList = []
sourceFontCounter = 0

for i in xrange(sourceFontStart, sourceFontEnd + 1):
for i in range(sourceFontStart, sourceFontEnd + 1):
sourceFontList.append(format(i, 'X'))

scale_factor = 0
Expand Down Expand Up @@ -510,7 +512,7 @@ def copy_glyphs(sourceFont, sourceFontStart, sourceFontEnd, symbolFont, symbolFo
sourceFontCounter += 1

if int(copiedToSlot, 16) < 0:
print "Found invalid glyph slot number. Skipping."
print("Found invalid glyph slot number. Skipping.")
continue

if args.quiet == False:
Expand All @@ -532,7 +534,7 @@ def copy_glyphs(sourceFont, sourceFontStart, sourceFontEnd, symbolFont, symbolFo
codepoint = int("0x" + copiedToSlot, 16)
if codepoint in sourceFont:
if args.quiet == False:
print " Found existing Glyph at "+ copiedToSlot +". Skipping..."
print(" Found existing Glyph at {}. Skipping...".format(copiedToSlot))
# We don't want to touch anything so move to next Glyph
continue

Expand Down Expand Up @@ -687,15 +689,15 @@ for patch in PATCH_SET:
if symfont:
symfont.close()

print "\nDone with Path Sets, generating font..."
print("\nDone with Path Sets, generating font...")

# the `PfEd-comments` flag is required for Fontforge to save
# '.comment' and '.fontlog'.
sourceFont.generate(args.outputdir + "/" + sourceFont.fullname + extension, flags=('opentype', 'PfEd-comments'))

print "\nGenerated: " + sourceFont.fullname
print("\nGenerated: {}".format(sourceFont.fullname))

if args.postprocess:
subprocess.call([args.postprocess, args.outputdir + "/" + sourceFont.fullname + extension])
print "\nPost Processed: " + sourceFont.fullname
print("\nPost Processed: {}".format(sourceFont.fullname))

0 comments on commit bbc922e

Please sign in to comment.