From 28735a6d0a96c998de75393317ca9a53bc1c33b4 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Sat, 11 Nov 2023 01:31:49 +0200 Subject: [PATCH] [subset] Add --prune-codepage-ranges --- Lib/fontTools/subset/__init__.py | 14 ++++++++++++++ Tests/subset/data/NotoSansCJKjp-Regular.subset.ttx | 2 +- Tests/subset/data/TestContextSubstFormat3.ttx | 4 ++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Lib/fontTools/subset/__init__.py b/Lib/fontTools/subset/__init__.py index bd826ed22..d9da900fe 100644 --- a/Lib/fontTools/subset/__init__.py +++ b/Lib/fontTools/subset/__init__.py @@ -407,6 +407,10 @@ Other font-specific options *not* be switched on if an intersection is found. [default] --no-prune-unicode-ranges Don't change the 'OS/2 ulUnicodeRange*' bits. +--prune-codepage-ranges + Update the 'OS/2 ulCodePageRange*' bits after subsetting. [default] +--no-prune-codepage-ranges + Don't change the 'OS/2 ulCodePageRange*' bits. --recalc-average-width Update the 'OS/2 xAvgCharWidth' field after subsetting. --no-recalc-average-width @@ -3086,6 +3090,7 @@ class Options(object): self.recalc_bounds = False # Recalculate font bounding boxes self.recalc_timestamp = False # Recalculate font modified timestamp self.prune_unicode_ranges = True # Clear unused 'ulUnicodeRange' bits + self.prune_codepage_ranges = True # Clear unused 'ulCodePageRange' bits self.recalc_average_width = False # update 'xAvgCharWidth' self.recalc_max_context = False # update 'usMaxContext' self.canonical_order = None # Order tables as recommended @@ -3450,6 +3455,15 @@ class Subsetter(object): log.info( "%s Unicode ranges pruned: %s", tag, sorted(new_uniranges) ) + if self.options.prune_codepage_ranges: + old_codepages = font[tag].getCodePageRanges() + new_codepages = font[tag].recalcCodePageRanges(font, pruneOnly=True) + if old_codepages != new_codepages: + log.info( + "%s CodePage ranges pruned: %s", + tag, + sorted(new_codepages), + ) if self.options.recalc_average_width: old_avg_width = font[tag].xAvgCharWidth new_avg_width = font[tag].recalcAvgCharWidth(font) diff --git a/Tests/subset/data/NotoSansCJKjp-Regular.subset.ttx b/Tests/subset/data/NotoSansCJKjp-Regular.subset.ttx index 4dfc0b23c..2f9501d63 100644 --- a/Tests/subset/data/NotoSansCJKjp-Regular.subset.ttx +++ b/Tests/subset/data/NotoSansCJKjp-Regular.subset.ttx @@ -98,7 +98,7 @@ - + diff --git a/Tests/subset/data/TestContextSubstFormat3.ttx b/Tests/subset/data/TestContextSubstFormat3.ttx index 0ed43ee24..c24ac164a 100644 --- a/Tests/subset/data/TestContextSubstFormat3.ttx +++ b/Tests/subset/data/TestContextSubstFormat3.ttx @@ -117,8 +117,8 @@ - - + +