def main(*ffargs): lgh = log_setup('Log/' + __file__[:-3] + '.log') logging.info('version %s', bfVersion) args = [] for a in ffargs[0]: logging.debug(a) args.append(a) if len(args) == 3: infile = args[1] outfile = args[2][:-4] + '.txt' else: logging.warning("\nsyntax: fontforge -script back2doc.py output.txt") logging.warning( "\nCreates a backfont text file for verification of word alignment" ) return 1 rc = read_csv(infile, outfile) if rc == 0: #convett2odt(outfile) logging.info("Done! The backdoc file is in %s", outfile) else: logging.error('Failed %d', rc) #closeLogFile(lgh) #sys.exit(rc) return (rc)
def main(*ffargs): lgh = log_setup('Log/' + __file__[:-3] + '.log') logging.info('version %s', bfVersion) args = [] rc = 0 for a in ffargs[0]: logging.info('%s', a) args.append(a) if len(args) > 2: csvFile = args[1] #alias = sys.argv[2].upper().strip() ttfFont = args[2].lower() #cg = getConfig('langinfo', language) namelist = "" if len(args) > 3: index = 0 for arg in args: #log_info(index, arg) if index > 2: namelist = namelist + '+' + arg.strip() index += 1 if len(namelist) < 4: namelist = "" print('csvfile', csvFile) status = read_list(ttfFont, csvFile, namelist.lower()) logging.info('read_list status %s', status) rc = status else: logging.warning("\nSYNTAX Error") logging.warning( "\nsyntax: fontforge -script bfv2svg.py csvfile ttffile [unicode list]\n" ) logging.warning( " - script Python script file, csvfile language fontfile\n") logging.warning( " optional space separated unicode list i.e. e000 eda5\n") logging.warning("\nCreates svg files in the /svg directory using\n") logging.warning("the names in the csv file\n") logging.warning("The csv file format \n") logging.warning(" glyph, unicode(hex), name\n") logging.warning("Optionally limits build to list of unicodes\n") rc = 1 if rc == 0: logging.info('Done SVG files are in Svg directory') else: logging.error('Failed %d', rc) #closeLogFile(lgh) #sys.exit(rc) return (rc)
def main(*ffargs): lgh = log_setup('Log/' + __file__[:-3] + '.log') logging.info('version %s', bfVersion) args = [] for a in ffargs[0]: logging.debug('input ffargs %s', a) args.append(a) rc = 0 if len(args) > 2: fontName = args[1] kmfile = args[2] outfile = args[3] try: refList = readKmnCSV(kmfile) font = fontforge.open(fontName) cfg["sunFontName"] = font.fontname saveCfg(cfg) #make font name rc, glyphs = listGlyphs(font, refList) if rc == 0: rc = writeGlyphs(glyphs, outfile) if rc == 0: array2xlsx(glyphs, outfile[:-4] + '.ods') except Exception as e: #log_err("fatal error ",e) #traceback.print_exc() #logging.exception("Deliberate divide by zero traceback") logging.exception(e) rc = 1 else: logging.warning( "\n SYNTAX: fontforge -script sfd2csv.py fontforgefile.sfd keyman_csvfile csvfile.csv" ) logging.warning( " i.e. fontforge -script sfd2csv.py fontfile.sfd keyman.csv pwlist.csv" ) logging.warning( " Takes data from fontforge file to generate a csv file of symbols and names," ) logging.warning(" unicodes and names") logging.warning(" i.e. symbol,eb08,Athens, reference") rc = 1 if rc != 0: logging.error("failed status = %s", rc) else: logging.info("Done! The csv file is in %s", outfile) #closeLogFile(lgh) #sys.exit(rc) return rc
def main(*ffargs): lgh = log_setup('Log/' + __file__[:-3] + '.log') logging.info('version %s', bfVersion) rc = 0 args = [] cnt = 0 for a in ffargs[0]: logging.debug('%d %s', cnt, a) args.append(a) cnt += 1 print('args', cnt, a) if len(args) == 3: namelist = args[1] outFile = args[2] try: kmnAry = read_kmn(namelist) if kmnAry: if kmnAry == 1: rc = 1 else: cfg = readCfg() array2xlsx(kmnAry, outFile[:-4] + '.ods', csv=True) else: rc = 1 except Exception as e: logging.exception("fatal error %s", e) rc = 3 else: logging.error( "\nsyntax: fontforge -script kmn2csv.py %kmn%.kmn kmn%kmn%.csv") logging.error( " i.e. - script Python script file, SUN7_251.kmn kmnSUN7_251.csv" ) rc = 1 if rc == 0: logging.info('done file is in %s', outFile[:-4] + '.ods') else: logging.error("failed status = %s", rc) #closeLogFile(lgh) #sys.exit(rc) return (rc)
def main(*ffargs): #print('file',__file__) #base=os.path.basename(__file__) lgh = log_setup('Log/' + __file__[:-3] + '.log') logging.info('version %s', bfVersion) rc = 0 curdir = os.getcwd() try: cfg = readCfg() #removeFiles = cfg["debug"] # change to dist directory to so zip file won't have sub directory os.chdir('dist') fileList = createFileList(cfg) #logging.info('createlist %s', rc) if fileList: rc = createReadMe(cfg, fileList) if rc == 0: rc = writeZip(cfg, fileList) ''' if rc == 0: if removeFiles: # delete original files for file in fileList: os.remove(file[0]) ''' except Exception as e: logging.exception('exception %s', e) rc = 1 os.chdir(curdir) # CHANGE back to runninc dir for future commands if rc == 0: logging.info("Done! The zipfile file is in %s", cfg["zipFile"]) else: logging.error("Error could not complete commands status = %d", rc) #closeLogFile(lgh) #sys.exit(rc) return rc
def main(*ffargs): lgh = log_setup('Log/' + __file__[:-3] + '.log') logging.info('version %s', bfVersion) args = [] rc = 0 for a in ffargs[0]: logging.debug(a) args.append(a) if len(args) == 3: csv_file = args[1] outFile = args[2] rc, csv_data = read_csv_data(csv_file) logging.debug('read_csv %d %d', rc, len(csv_data)) if rc == 0: #name_sort = sorted(csv_data, key=lambda x: x[LANGNAMEPOS].lower()) ary = csv2_4x16(csv_data) logging.debug('csv24x16 %d', len(ary)) arry2xlsx(ary, outFile) rc = 0 else: logging.warning('\n>> fontforge -script imageref.py infile outfile') logging.warning( '>> Example: fontforge -script genesis.csv genout.csv\n') logging.warning( 'Creates a condensed view of the dictionary with the unicode') logging.warning('and name in same cell.') rc = 1 if rc == 0: logging.info('** done ** files are in %s', outFile) else: logging.error("Error could not complete commands status = %d", rc) #closeLogFile(lgh) return (rc)
def main(*ffargs): lgh = log_setup('Log/' + __file__[:-3] + '.log') logging.info('version %s', bfVersion) rc = 0 args = [] for a in ffargs[0]: logging.debug(a) args.append(a) if len(args) > 4: csvData = read_csv(args[1]) logging.debug('csvdata len %d', len(csvData)) if csvData: version = args[2] alias = args[3] outFile = args[4] name = outFile.split('.')[0] hdr = get_header(name) rc = write_kmn(hdr, csvData, outFile) else: logging.error('csvdata not valid') rc = 1 else: logging.error("Create SUN kmn file from SUN csv dictionary.") logging.error( " i.e fontforge -script csv2kmn.py infile.csv version alias outfile.kmn" ) rc = 1 if rc == 0: logging.info('Done saved kmn file in %s \n', outFile) else: logging.error('finished with Errors status %d \n', status) #closeLogFile(lgh) #sys.exit(rc) return (rc)
def main(*ffargs): lgh = log_setup('Log/' + __file__[:-3] + '.log') logging.info('version %s', bfVersion) args = [] for a in ffargs[0]: logging.debug(a) args.append(a) rc = 0 if len(args) > 4: try: csvFile = args[1] ttfFile = args[2] alias = args[3].upper() #backFont = args[4].split('.')[0] backFont = args[4][:-3] + '_' + alias print('arg4', backFont) #ttfFont = fontforge.open(ttfFile) ttfFont = ff.open(ttfFile) getMetrics(ttfFile, ttfFont) font = createFont(backFont) #, ver, section) namelist = "" if len(args) > 5: index = 0 for arg in args: #log_info(index, arg) if index > 4: namelist = namelist + '+' + arg.strip().lower() #log_info('namelist =',namelist, len(namelist)) index += 1 if len(namelist) < 4: namelist = "" logging.info('namelist = %s, %d', namelist, len(namelist)) rc = read_list(font, csvFile, alias, namelist) if rc == 0: logging.info('Saving %s.sfd %d', backFont, rc) status = font.save(backFont + ".sfd") logging.info('status = %s', status) logging.info('Generating %s.ttf', backFont) #if not namelist: status = font.generate(backFont + ".ttf") logging.info('status = %s', status) logging.info('Generating %s.woff', backFont) #if not namelist: status = font.generate(backFont + ".woff") logging.info('status = %s', status) except Exception as e: logging.exception('exception %s', e) #traceback.print_exc() rc = 1 else: logging.error( "\nsyntax: fontforge -script svg2Font.py backFont.sfd csvfile fontfile alias [unicode list]" ) logging.error( " Creates a back font from the svg files in /svg directory") logging.error( " using the names in the pw file for font characteristics") logging.error(" Optionally limits build to list of unicodes") logging.error( " -script Python script file, Fontforge file csvfile( The dictionary file)" ) logging.error(" language 2 character i.e. EN") logging.error( " optional space separated unicode list i.e. e000 eda5") logging.error(" The csv file is expected to have:") logging.error( " symbol in column 0, unicode in column 1 english word in column 2 and" ) logging.error( " language words in column 3. \n Optionally limits build to list of unicodes" ) rc = 1 if rc == 0: logging.info('\nDone saved font files in %s .ttf |.woff |.sfd', backFont) else: logging.error('Failed %d', rc) #closeLogFile(lgh) return rc
line = [] #ary.append([unicode+','+ name +',"'+ altname.strip(',')+'"']) line.append(unicode) line.append(name) line.append(altname.strip(',')) ary.append(line) name_sort = sorted(ary, key=lambda x: x[1].lower()) with open(outfile, 'w', encoding='utf8') as f: for v in name_sort: f.write(v[0] + ',' + v[1] + ',"' + v[2] + '"\n') logging.info('saved to %s', outfile) if len(sys.argv) > 3: lgh = log_setup('Log/' + __file__[:-3] + '.log') logging.info('version %s', bfVersion) priData = read_pri(sys.argv[1]) #primary word list kmnData = read_kmn(sys.argv[2], priData) # kmn file list writeAlt(sys.argv[3], kmnData) # outfile else: print( "\nsyntax: fontforge -script alternative.py primary.csv kmn.csv output.csv" ) print("Creates a list of unicodes and names with alternative names") print('\n*** done ****')
def main(*ffargs): lgh = log_setup('Log/' + __file__[:-3] + '.log') logging.info('version %s', bfVersion) rc = 0 args = [] #logging.debug('args %s %s',len(ffargs[0]), ffargs[0]) logging.debug(*ffargs) for a in ffargs[0]: #ogger.debug( a) args.append(a) if len(args) > 2: pwFile = args[1] langFile = 'input/' + os.path.basename(args[2]) pwLangFile = 'dist/' + os.path.basename(args[3]) logging.info('pwFile %s', pwFile) logging.info('langFile %s', langFile) logging.info('pwLangFile %s', pwLangFile) try: lExt = langFile[-3:].strip().lower() logging.debug('ext %s', '|' + lExt + '|') if lExt == '.csv': lcsvFile = langFile elif lExt == 'ods': lcsvFile = convert2csv(langFile, 'dist') else: logging.exception( 'Wrong type of File only csv or ods files accepted') rc = 2 if rc == 0: lcsvFile = 'dist/' + os.path.basename(lcsvFile) logging.info('***%s', lcsvFile) enList = readENPri(pwFile) logging.info('****') langList = readLang(lcsvFile, enList) if langList: #dicFile = cfg["langFile"] #langList = fixLangList(langList) if langList: mList = mergeLists(enList, langList) if mList: array2xlsx(mList, pwLangFile) fods = pwLangFile.split('.')[0] + '.ods' fcsv = convert2csv(fods, 'dist') if fcsv == 1: rc = 1 else: rc = 1 else: rc = 1 else: rc = 1 except Exception as e: logging.exception('Error %s', e) rc = 1 else: logging.error( "\n SYNTAX: fontforge -quiet -script langpri.py pw%ver%_EN.csv %langFile%, outfile" ) logging.error( "Creates 'langpw.csv' as a list of all primary words in language") rc = 1 if rc == 0: logging.info('done file in %s', pwLangFile) else: logging.error("Error could not complete commands status = %d", rc) #closeLogFile(lgh) return (rc)