diff options
author | Alex Xu (Hello71) <alex_y_xu@yahoo.ca> | 2021-08-13 20:38:37 -0400 |
---|---|---|
committer | Alex Xu (Hello71) <alex_y_xu@yahoo.ca> | 2021-08-13 20:38:37 -0400 |
commit | 7b82460ff5fe21fc4d2a98bb425d77bcb44dce7b (patch) | |
tree | ec1ccfa6d8090cf498bdb612cd40d7b1a6c0c8a3 | |
parent | 5b1c4639f058d04a0089b3b323c8fad39c4a97a3 (diff) | |
download | wfs-7b82460ff5fe21fc4d2a98bb425d77bcb44dce7b.tar.xz wfs-7b82460ff5fe21fc4d2a98bb425d77bcb44dce7b.zip |
configurable flavor, switch font arg order
-rwxr-xr-x | wfs.py | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -129,7 +129,7 @@ def get_fontdesc(fonts, fontspec): return font return None -def subset(fontdesc, text, fts_opts): +def subset(fontdesc, text, flavors, fts_opts): fontfile = fontdesc['fontfile'] logger.info('subsetting %s', fontfile) font = load_font(fontfile, fts_opts, dontLoadGlyphNames=True) @@ -139,7 +139,7 @@ def subset(fontdesc, text, fts_opts): subsetter.populate(text=text) subsetter.subset(font) ret = [] - for flavor in ['woff', 'woff2']: + for flavor in flavors: if 'outfile' in fontdesc and flavor in fontdesc['outfile']: outfile = fontdesc['outfile'][flavor] else: @@ -182,7 +182,8 @@ def main(argv): parser = argparse.ArgumentParser(description='Web Font Subsetter', epilog='see pyftsubset --help for additional options') parser.add_argument('--driver', help='selenium driver name (chrome or firefox)', default='chrome') parser.add_argument('--no-screenshots', help='skip screenshot validation', action='store_true') - parser.add_argument('--font', help='add font (family:weight:style:fontfile)', action='append') + parser.add_argument('--font', help='add font (fontfile:family:weight:style)', action='append') + parser.add_argument('--flavor', help='add flavor (woff or woff2)', action='append', default=['woff2']) parser.add_argument('file', help='html files', nargs='+') args, leftover = parser.parse_known_intermixed_args(argv) options = Options() @@ -194,7 +195,7 @@ def main(argv): from fontTools.ttLib import sfnt sfnt.USE_ZOPFLI = True ncpus = len(os.sched_getaffinity(0)) - fonts = [dict(zip(['family', 'weight', 'style', 'fontfile'], font.split(':'))) for font in args.font] + fonts = [dict(zip(['fontfile', 'family', 'weight', 'style'], font.split(':'))) for font in args.font] nwworkers = min(len(files), ncpus) nfworkers = min(len(fonts) * 2, ncpus) logger.info('starting %d web workers, %d font workers', nwworkers, nfworkers) @@ -221,7 +222,7 @@ def main(argv): logger.info('shutting down web workers early') wpool.close() subset_args = ( - (get_fontdesc(fonts, fontspec), ''.join(text), options) + (get_fontdesc(fonts, fontspec), ''.join(text), args.flavor, options) for fontspec, text in all_font_texts.items()) subsetted = fpool.starmap(subset, subset_args) fpool.starmap(write_subset, chain(*subsetted)) |