def generate_fonts(): print("FontForge version: " + ff.version()) print("Python version: " + platform.python_version()) for name in FONT_NAME_LIST: font_name = FONT_FAMILY_NAME + "-" + name project_file = CURRENT_DIR + "/" + font_name + ".sfd" font_file = OUTPUT_PATH + "/" + font_name + ".ttf" _generate_font(project_file, font_file, font_name)
def dumpFontForgeAPI(testFontPath, printModule=False, printFont=False, printGlyph=False, printLayer=False, printContour=False, printPoint=False): def printAPI(item, name): print print "-"*80 print "API of", item names = dir(item) names.sort() print if printAPI: for n in names: print print "%s.%s"%(name, n) try: print getattr(item, n).__doc__ except: print "# error showing", n # module if printModule: print "module file:", fontforge.__file__ print "version:", fontforge.version() print "module doc:", fontforge.__doc__ print "has User Interface:", fontforge.hasUserInterface() print "has Spiro:", fontforge.hasSpiro() printAPI(fontforge, "fontforge") # font fontObj = fontforge.open(testFontPath) if printFont: printAPI(fontObj, "font") # glyph glyphObj = fontObj["A"] if printGlyph: printAPI(glyphObj, "glyph") # layer layerObj = glyphObj.foreground if printLayer: printAPI(layerObj, "layer") # contour contourObj = layerObj[0] if printContour: printAPI(contourObj, "contour") # point if printPoint: pointObj = contourObj[0] printAPI(pointObj, "point") # other objects penObj = glyphObj.glyphPen() printAPI(penObj, "glyphPen")
def generate_fonts(hint_flag, font_ext=".otf"): print("FontForge version: " + ff.version()) print("Python version: " + platform.python_version()) print("Platform: " + platform.platform() + "\n") for weight in WEIGHT_LIST: font_name = FAMILY_NAME + "-" + weight sfd_file = SFD_PATH + "/" + font_name + ".sfd" feature_file = FEATURE_PATH + "/" + font_name + ".fea" otf_file = OTF_PATH + "/" + font_name + font_ext _generate_font(font_name, sfd_file, feature_file, otf_file, hint_flag)
def generate_fonts(): print("FontForge version: " + fontforge.version()) print("Python version: " + platform.python_version()) print("Platform: " + platform.platform() + "\n") for i in weights: font_name = family_name + "-" + i.capitalize() font_name_full = family_name_full + "-" + i font = fontforge.open(sfd_path + font_name_full + ".sfdir") font.mergeFeature(feature_path + font_name_full + ".fea") font.generate(otf_path + font_name + ".otf", flags=("opentype")) print(datetime.datetime.now().strftime('[%Y-%m-%d %H:%M:%S.%f]') + " '" + font_name + "' " + "generated successfully.")
def generate_fonts(): print("FontForge version: " + fontforge.version()) print("Python version: " + platform.python_version()) print("Platform: " + platform.platform() + "\n") for i in WEIGHT_LIST: font_name = FAMILY_NAME + "-" + i sfdir = SFD_PATH + "/" + font_name + ".sfdir" feature_file = FEATURE_PATH + "/" + font_name + ".fea" otf_file = OTF_PATH + "/" + font_name + ".otf" font = fontforge.open(sfdir) font.mergeFeature(feature_file) font.generate(otf_file, flags=("opentype")) print(datetime.datetime.now().strftime('[%Y-%m-%d %H:%M:%S.%f]') + " '" + font_name + "' " + "generated successfully.")
def check_fontforge_min_version(): """ Verifies installed FontForge version meets minimum requirement. """ minimumVersion = 20141231 actualVersion = int(fontforge.version()) # un-comment following line for testing invalid version error handling # actualVersion = 20120731 # versions tested: 20150612, 20150824 if actualVersion < minimumVersion: sys.stderr.write( "{}: You seem to be using an unsupported (old) version of fontforge: {}\n" .format(projectName, actualVersion)) sys.stderr.write("{}: Please use at least version: {}\n".format( projectName, minimumVersion)) sys.exit(1)
def make_suite(path, definedTarget): """ path - is full path to file, definedTarget is filter to only select small subset of tests """ suite = unittest.TestSuite() for TestCase in TestRegistry.list(): if definedTarget in TestCase.targets: TestCase.path = path if getattr(TestCase, 'tool', '').lower() == 'fontforge': if path.lower().endswith('.ufo'): # dev branch of fontforge python library has a bug # when opening ufo fonts, so we ignore all fontforge tests # for UFO import fontforge if int(fontforge.version()) > int('20140402'): continue suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(TestCase)) return suite
def make_suite(path, definedTarget): """ path - is full path to file, definedTarget is filter to only select small subset of tests """ suite = unittest.TestSuite() for TestCase in TestRegistry.list(): if definedTarget in TestCase.targets: TestCase.path = path if getattr(TestCase, '__generateTests__', None): TestCase.__generateTests__() if getattr(TestCase, 'tool', '').lower() == 'fontforge': if path.lower().endswith('.ufo'): # dev branch of fontforge python library has a bug # when opening ufo fonts, so we ignore all fontforge tests # for UFO import fontforge if int(fontforge.version()) > int('20140402'): continue suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(TestCase)) return suite
#!/usr/bin/python # # With the SFDs in the current directory, run this with # $ python generate.py import fontforge, sys required_version = "20090923" if fontforge.version() < required_version: print ("Your version of FontForge is too old - %s or newer is required" % (required_version)); print ("Current fontforge version:") print fontforge.version() files = [ 'Puritan-BoldItalic.sfd', 'Puritan-Bold.sfd', 'Puritan-Italic.sfd', 'Puritan-Regular.sfd' ] for font in files: f = fontforge.open(font) print ("Building ") + f.fullname + ( " ") + f.weight + (" from sfd sources with fontforge") f.generate(f.fontname + ".otf",flags=("opentype")) f.em = 1024 f.is_quadratic = True f.round() f.selection.all() f.autoHint() f.autoInstr()
# ./generate.pe *.sfd import fontforge, sys required_version = "20080330" # font generation flags: # omit-instructions => do not include TT instructions (for experimental typefaces) # opentype => include OpenType tables # glyph-comments => generate a 'PfEd' table and store glyph comments # glyph-colors => generate a 'PfEd' table and store glyph colors # old-kern => generate old fashioned kern tables. # - this one is important because it generates correct kerning tables for legacy # applications def_gen_flags = ("opentype", "glyph-comments", "glyph-colors", "old-kern") exp_gen_flags = def_gen_flags + ("omit-instructions", ) if fontforge.version() < required_version: print("Your version of FontForge is too old - %s or newer is required" % (required_version)) # FoundryName is not used in TTF generation fontforge.setPrefs("FoundryName", "DejaVu") # first 4 characters of TTFFoundry are used for achVendId fontforge.setPrefs("TTFFoundry", "DejaVu") i = 1 while i < len(sys.argv): font = fontforge.open(sys.argv[i]) gen_flags = def_gen_flags # Serif Italic and Serif Bold Italic are experimental if font.fontname.rfind("Serif") > -1 and font.fontname.rfind( "Italic") > -1: gen_flags = exp_gen_flags
fontforge.defaultOtherSubrs() # fontforge.readOtherSubrsFile() foo = fontforge.hasSpiro() # fontforge.loadEncodingFile() # fontforge.loadNamelist() # fontforge.loadNamelistDir() # fontforge.preloadCidmap() fontforge.printSetup("lpr") if (fontforge.unicodeFromName("A")!=65) or (fontforge.unicodeFromName("uni030D")!=0x30D): raise ValueError("Wrong return from unicodeFromName") foo = fontforge.version() ambrosia = sys.argv[1] fonts = fontforge.fonts() if ( len(fonts)!=0 ) : raise ValueError("Wrong return from fontforge.fonts") fontforge.activeFont() fontforge.activeGlyph() fontforge.activeLayer() fontnames= fontforge.fontsInFile(ambrosia) if len(fontnames)!=1 or fontnames[0]!='Ambrosia': raise ValueError("Wrong return from fontforge.fontsInFile") font = fontforge.open(ambrosia) morefonts = fontforge.fonts()
dest='careful', action='store_true', help='Do not overwrite existing glyphs if detected', default=False) parser.add_argument('-out', '--outputdir', type=str, nargs='?', dest='outputdir', help='The directory to output the patched font file to', default=".") args = parser.parse_args() #changelog = open("changelog.md", "r") minimumVersion = 20141231 actualVersion = int(fontforge.version()) # un-comment following line for testing invalid version error handling #actualVersion = 20120731 # 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) sys.exit(1) verboseAdditionalFontNameSuffix = " " + projectNameSingular if args.windows: # attempt to shorten here on the additional name BEFORE trimming later additionalFontNameSuffix = " " + projectNameAbbreviation
#!/usr/bin/env python from __future__ import print_function import fontforge import psMat import pickle print(fontforge.__version__, fontforge.version()) fontforge.font() print(pickle.loads(pickle.dumps(fontforge.point())))
def dumpFontForgeAPI(testFontPath, printModule=False, printFont=False, printGlyph=False, printLayer=False, printContour=False, printPoint=False): def printAPI(item, name): print print "-" * 80 print "API of", item names = dir(item) names.sort() print if printAPI: for n in names: print print "%s.%s" % (name, n) try: print getattr(item, n).__doc__ except: print "# error showing", n # module if printModule: print "module file:", fontforge.__file__ print "version:", fontforge.version() print "module doc:", fontforge.__doc__ print "has User Interface:", fontforge.hasUserInterface() print "has Spiro:", fontforge.hasSpiro() printAPI(fontforge, "fontforge") # font fontObj = fontforge.open(testFontPath) if printFont: printAPI(fontObj, "font") # glyph glyphObj = fontObj["A"] if printGlyph: printAPI(glyphObj, "glyph") # layer layerObj = glyphObj.foreground if printLayer: printAPI(layerObj, "layer") # contour contourObj = layerObj[0] if printContour: printAPI(contourObj, "contour") # point if printPoint: pointObj = contourObj[0] printAPI(pointObj, "point") # other objects penObj = glyphObj.glyphPen() printAPI(penObj, "glyphPen")
--input=FILE file name of input font --output=FILE file name of output font --features=FILE file name of features file --version=VALUE set font version to VALUE --slant=VALUE autoslant --css output is a CSS file --web output is web version -h, --help print this message and exit """ % os.path.basename(sys.argv[0]) print message sys.exit(code) if __name__ == "__main__": if fontforge.version() < min_ff_version: print "You need FontForge %s or newer to build Amiri fonts" %min_ff_version sys.exit(-1) try: opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ["help", "input=", "output=", "features=", "version=", "slant=", "css", "web", "quran"]) except getopt.GetoptError, err: usage(str(err), -1) infile = None outfile = None feafile = None version = None slant = False
def fontPreProcessing ( font ) : if fontforge.version() < '20150827' : raise RuntimeError( 'Unsupported fontforge version. Must be 20150827 or later.' )