summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xwfs.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/wfs.py b/wfs.py
index 43a365f..94b29df 100755
--- a/wfs.py
+++ b/wfs.py
@@ -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))