From 9de25ea628bd9cf68c747090e27d2c0d485fde57 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Mon, 26 Sep 2016 19:13:04 +0100 Subject: [PATCH 1/2] [subset] add --passthrough-tables option to keep any tables that the subsetter does not know how to subset --- Lib/fontTools/subset/__init__.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Lib/fontTools/subset/__init__.py b/Lib/fontTools/subset/__init__.py index a1c1ccb5d..e8ee6fc38 100644 --- a/Lib/fontTools/subset/__init__.py +++ b/Lib/fontTools/subset/__init__.py @@ -216,11 +216,17 @@ Font table options: they do not need subsetting (ignore the fact that 'loca' is listed here): 'gasp', 'head', 'hhea', 'maxp', 'vhea', 'OS/2', 'loca', 'name', 'cvt ', 'fpgm', 'prep', 'VMDX', 'DSIG' and 'CPAL'. - Tables that the tool does not know how to subset and are not specified - here will be dropped from the font. + By default, tables that the tool does not know how to subset and are not + specified here will be dropped from the font, unless --passthrough-tables + option is passed. Example: --no-subset-tables+=FFTM * Keep 'FFTM' table in the font by preventing subsetting. + --passthrough-tables + Do not drop tables that the tool does not know how to subset. + --no-passthrough-tables + Tables that the tool does not know how to subset and are not specified + in --no-subset-tables will be dropped from the font. [default] --hinting-tables[-]=[,
...] Specify (=), add to (+=) or exclude from (-=) the list of font-wide hinting tables that will be dropped if --no-hinting is specified, @@ -2444,6 +2450,7 @@ class Options(object): self.drop_tables = self._drop_tables_default[:] self.no_subset_tables = self._no_subset_tables_default[:] + self.passthrough_tables = False # keep/drop tables we can't subset self.hinting_tables = self._hinting_tables_default[:] self.legacy_kern = False # drop 'kern' table if GPOS available self.layout_features = self._layout_features_default[:] @@ -2722,6 +2729,8 @@ class Subsetter(object): del font[tag] else: log.info("%s subsetted", tag) + elif self.options.passthrough_tables: + log.info("%s NOT subset; don't know how to subset", tag) else: log.info("%s NOT subset; don't know how to subset; dropped", tag) del font[tag] From 4ae7bba184dbc3b60122924995162e41845c7b7a Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Mon, 26 Sep 2016 19:13:56 +0100 Subject: [PATCH 2/2] [subset_test] add tests for --passthrough-tables option --- Lib/fontTools/subset/subset_test.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Lib/fontTools/subset/subset_test.py b/Lib/fontTools/subset/subset_test.py index 348d43de5..97260eef3 100644 --- a/Lib/fontTools/subset/subset_test.py +++ b/Lib/fontTools/subset/subset_test.py @@ -1,7 +1,7 @@ from __future__ import print_function, division, absolute_import from fontTools.misc.py23 import * from fontTools import subset -from fontTools.ttLib import TTFont +from fontTools.ttLib import TTFont, newTable import contextlib import difflib import logging @@ -204,6 +204,29 @@ class SubsetTest(unittest.TestCase): self.assertTrue(filter(lambda l: l.args['msg'] == "subset 'cmap'", logs)) self.assertTrue(filter(lambda l: l.args['msg'] == "subset 'glyf'", logs)) + def test_passthrough_tables(self): + _, fontpath = self.compile_font(self.getpath("TestTTF-Regular.ttx"), ".ttf") + font = TTFont(fontpath) + unknown_tag = 'ZZZZ' + unknown_table = newTable(unknown_tag) + unknown_table.data = b'\0'*10 + font[unknown_tag] = unknown_table + font.save(fontpath) + + subsetpath = self.temp_path(".ttf") + subset.main([fontpath, "--output-file=%s" % subsetpath]) + subsetfont = TTFont(subsetpath) + + # tables we can't subset are dropped by default + self.assertFalse(unknown_tag in subsetfont) + + subsetpath = self.temp_path(".ttf") + subset.main([fontpath, "--passthrough-tables", "--output-file=%s" % subsetpath]) + subsetfont = TTFont(subsetpath) + + # unknown tables are kept if --passthrough-tables option is passed + self.assertTrue(unknown_tag in subsetfont) + if __name__ == "__main__": unittest.main()