def test_run(): cl = "psfglyphs2ufo --nofea tests/input/font-psf-test/source/PsfTestRoman.glyphs " \ "local/testresults/ufo/psfglyphs2ufo -l local/testresults/ufo/psfglyphs2ufo.log" sys.argv = cl.split(" ") (args, font) = execute("UFO", psfglyphs2ufo.doit, psfglyphs2ufo.argspec, chain="first") args.logger.logfile.close() exp_counts = (0, 0) actual_counts = (args.logger.errorcount, args.logger.warningcount) # Now normalize the output ufos for weight in ("Regular", "Bold"): fontname = "local/testresults/ufo/psfglyphs2ufo/PsfTest-" + weight + ".ufo" cl = "psfnormalize " + fontname sys.argv = cl.split(" ") (args, font) = execute("UFO", psfnormalize.doit, psfnormalize.argspec, chain="first") font.write(fontname) if exp_counts == actual_counts: assert True else: print("Mis-match of logger errors/warnings: " + str(exp_counts) + " vs " + str(actual_counts)) assert False
def test_run(tool, commandline, testcommand, outfont, exp_errors, exp_warnings): # Used by tests to run commands sys.argv = commandline.split(" ") (args, font) = execute(tool, testcommand.doit, testcommand.argspec, chain="first") if outfont: if tool in ("FT", "FP"): font.save(outfont) else: # Must be Pyslifont Ufont font.write(outfont) args.logger.logfile.close() # Need to close the log so that the diff test can be run exp_counts = (exp_errors, exp_warnings) actual_counts = (args.logger.errorcount, args.logger.warningcount) result = exp_counts == actual_counts if not result: print("Mis-match of logger errors/warnings: " + str(exp_counts) + " vs " + str(actual_counts)) return result
def test_run(): cl = "psfsyncmasters -n tests/input/font-psf-test/source/PsfTestRoman.designspace " \ "tests/input/font-psf-test/source/PsfTestItalic.designspace -l local/testresults/ufo/psfsyncmasters.log" sys.argv = cl.split(" ") (args, font) = execute("UFO", psfsyncmasters.doit, psfsyncmasters.argspec, chain="first") args.logger.logfile.close() exp_counts = (0, 6) actual_counts = (args.logger.errorcount, args.logger.warningcount) if exp_counts == actual_counts: assert True else: print("Mis-match of logger errors/warnings: " + str(exp_counts) + " vs " + str(actual_counts)) assert False
def cmd(): execute("UFO", doit, argspec)
def cmd(): execute(None, doit, argspec)
def cmd(): execute(None, doit, argspec) if __name__ == '__main__': cmd()
def cmd(): execute("UFO", doit, argspec) if __name__ == "__main__": cmd()
def cmd(): execute("FF", doit, argspec)
SILtogid2 = {} for glyph in font2.glyphs(): SILtogid2[glyph.glyphname] = glyph.originalgid # Combine all the mappings via ttf1! cnt1 = 0 cnt2 = 0 for glyph in font1.glyphs(): gid1 = glyph.originalgid gname1 = glyph.glyphname gname2 = SILnames[gname1] gid2 = SILtogid2[gname2] oldgrname = oldgrnames[gid1] if gid1 in oldgrnames else None newgrname = newgrnames[gid2] if gid2 in newgrnames else None if oldgrname is None or newgrname is None: print type(gid1), gname1, oldgrname print gid2, gname2, newgrname cnt2 += 1 if cnt2 > 10: break else: outfile.write(oldgrname + "," + newgrname + "\n") cnt1 += 1 print cnt1, cnt2 outfile.close() return execute("FF", doit, argspec)
def cmd() : execute("UFO",doit,argspec) if __name__ == "__main__": cmd()
def cmd(): execute("FT", doit, argspec) if __name__ == '__main__': cmd()
def cmd(): execute('FT', doit, argspec)
#!/usr/bin/env python 'Normalize an FTML file' __url__ = 'http://github.com/silnrsi/pysilfont' __copyright__ = 'Copyright (c) 2016 SIL International (http://www.sil.org)' __license__ = 'Released under the MIT License (http://opensource.org/licenses/MIT)' __author__ = 'David Raymond' from silfont.core import execute import silfont.ftml as ftml from xml.etree import cElementTree as ET argspec = [ ('infile',{'help': 'Input ftml file'}, {'type': 'infile'}), ('outfile',{'help': 'Output ftml file', 'nargs': '?'}, {'type': 'outfile', 'def': '_new.xml'}), ('-l','--log',{'help': 'Log file'}, {'type': 'outfile', 'def': '_ftmltest.log'}) ] def doit(args) : f = ftml.Fxml(args.infile) f.save(args.outfile) def cmd() : execute("",doit,argspec) if __name__ == "__main__": cmd()execute("", doit, argspec)
if type == "copy": sourcedir = "local/ufotests/source/" + ufoname shutil.copytree(ufo, sourcedir) elif type == "insitu": sourcedir = ufo else: print("Invlaid type '" + type + "' for " + ufo) continue sys.argv = [ "psfnormalize", sourcedir, "-l", "local/ufotests/results/" + logname, "-q", "-p", "checkfix=fix" ] print("Normalizing " + sourcedir + " for reference") (args, font) = execute("UFO", psfnormalize.doit, psfnormalize.argspec, chain="first") font.write("local/ufotests/results/" + ufoname) # Move from results to reference - originally written to results to get reference log file correct os.rename("local/ufotests/results/" + ufoname, "local/ufotests/reference/" + ufoname) os.rename("local/ufotests/results/" + logname, "local/ufotests/reference/" + logname) #errorcount = args.logger.errorcount -1 if args.logger.errorcount else 0 # If there is an error, reduce count for extra error reporting that there were errors! ufolist.append((sourcedir, ufoname[:-4], str(args.logger.errorcount), str(args.logger.warningcount))) args.logger.logfile.close() # Make sure final log file is closed # Create ufolist.csv ufofile = open("local/ufotests/ufolist.csv", "w") for line in ufolist:
os.rename("update_headers_temp.txt", fulln) else: for varn in updatevars: logger.log( fulln + ": Header variable " + varn + " will be " + updatevars[varn], "I") for varn in reportvars: reason = reportvars[varn] if reason == "non-standard": logger.log( fulln + ": Non-standard header variable " + varn + " present", "W") else: logger.log(fulln + ": No author header variable", "I") print "\n" + "Non-python files" + "\n" for filen in otherfiles: print filen return def nextline(): global file line = file.readline() line = ("EOF" if line == "" else line.strip()) return line execute(None, doit, argspec)
# Map SIL name to gids in font 2 SILtogid2={} for glyph in font2.glyphs(): SILtogid2[glyph.glyphname] = glyph.originalgid # Combine all the mappings via ttf1! cnt1 = 0 cnt2 = 0 for glyph in font1.glyphs(): gid1 = glyph.originalgid gname1 = glyph.glyphname gname2 = SILnames[gname1] gid2 = SILtogid2[gname2] oldgrname = oldgrnames[gid1] if gid1 in oldgrnames else None newgrname = newgrnames[gid2] if gid2 in newgrnames else None if oldgrname is None or newgrname is None : print type(gid1), gname1, oldgrname print gid2, gname2, newgrname cnt2 += 1 if cnt2 > 10 : break else: outfile.write(oldgrname + "," + newgrname+"\n") cnt1 += 1 print cnt1,cnt2 outfile.close() return execute("FF",doit, argspec)