From d7ac0ad3597dc0eaeb04a89a1f477ff40beaa36c Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Sat, 21 Jul 2018 18:28:33 +0100 Subject: [PATCH] subset: write default file extension based on --flavor or sfntVersion Fixes https://github.com/fonttools/fonttools/issues/1298 --- Lib/fontTools/subset/__init__.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Lib/fontTools/subset/__init__.py b/Lib/fontTools/subset/__init__.py index 8468b7a3a..53d1dc3b7 100644 --- a/Lib/fontTools/subset/__init__.py +++ b/Lib/fontTools/subset/__init__.py @@ -3137,8 +3137,6 @@ def load_font(fontFile, @timer("compile and save font") def save_font(font, outfile, options): - if options.flavor and not hasattr(font, 'flavor'): - raise Exception("fonttools version does not support flavors.") if options.with_zopfli and options.flavor == "woff": from fontTools.ttLib import sfnt sfnt.USE_ZOPFLI = True @@ -3215,8 +3213,7 @@ def main(args=None): args = args[1:] subsetter = Subsetter(options=options) - basename, extension = splitext(fontfile) - outfile = basename + '.subset' + extension + outfile = None glyphs = [] gids = [] unicodes = [] @@ -3268,6 +3265,14 @@ def main(args=None): dontLoadGlyphNames = not options.glyph_names and not glyphs font = load_font(fontfile, options, dontLoadGlyphNames=dontLoadGlyphNames) + if outfile is None: + basename, _ = splitext(fontfile) + if options.flavor is not None: + ext = "." + options.flavor.lower() + else: + ext = ".ttf" if font.sfntVersion == "\0\1\0\0" else ".otf" + outfile = basename + ".subset" + ext + with timer("compile glyph list"): if wildcard_glyphs: glyphs.extend(font.getGlyphOrder())