[subset] Retain GSUB ScriptRecords, even if they are empty
This slightly bloats subset fonts, but fixes: https://bugzilla.mozilla.org/show_bug.cgi?id=1080739#c15 https://github.com/behdad/fonttools/issues/518 At some point we might want to do something smarter based on Unicode script of retained characters.
This commit is contained in:
parent
809698611e
commit
74e629e600
@ -1308,9 +1308,9 @@ def collect_features(self):
|
||||
return _uniq_sort(sum(feature_indices, []))
|
||||
|
||||
@_add_method(otTables.ScriptList)
|
||||
def subset_features(self, feature_indices):
|
||||
def subset_features(self, feature_indices, retain_empty):
|
||||
self.ScriptRecord = [s for s in self.ScriptRecord
|
||||
if s.Script.subset_features(feature_indices)]
|
||||
if s.Script.subset_features(feature_indices) or retain_empty]
|
||||
self.ScriptCount = len(self.ScriptRecord)
|
||||
return bool(self.ScriptCount)
|
||||
|
||||
@ -1373,6 +1373,13 @@ def subset_glyphs(self, s):
|
||||
self.subset_lookups(lookup_indices)
|
||||
return True
|
||||
|
||||
@_add_method(ttLib.getTableClass('GSUB'),
|
||||
ttLib.getTableClass('GPOS'))
|
||||
def retain_empty_scripts(self):
|
||||
# https://github.com/behdad/fonttools/issues/518
|
||||
# https://bugzilla.mozilla.org/show_bug.cgi?id=1080739#c15
|
||||
return self.__class__ == ttLib.getTableClass('GSUB')
|
||||
|
||||
@_add_method(ttLib.getTableClass('GSUB'),
|
||||
ttLib.getTableClass('GPOS'))
|
||||
def subset_lookups(self, lookup_indices):
|
||||
@ -1385,7 +1392,7 @@ def subset_lookups(self, lookup_indices):
|
||||
else:
|
||||
feature_indices = []
|
||||
if self.table.ScriptList:
|
||||
self.table.ScriptList.subset_features(feature_indices)
|
||||
self.table.ScriptList.subset_features(feature_indices, self.retain_empty_scripts())
|
||||
|
||||
@_add_method(ttLib.getTableClass('GSUB'),
|
||||
ttLib.getTableClass('GPOS'))
|
||||
@ -1426,7 +1433,7 @@ def subset_feature_tags(self, feature_tags):
|
||||
else:
|
||||
feature_indices = []
|
||||
if self.table.ScriptList:
|
||||
self.table.ScriptList.subset_features(feature_indices)
|
||||
self.table.ScriptList.subset_features(feature_indices, self.retain_empty_scripts())
|
||||
|
||||
@_add_method(ttLib.getTableClass('GSUB'),
|
||||
ttLib.getTableClass('GPOS'))
|
||||
@ -1439,7 +1446,7 @@ def prune_features(self):
|
||||
if self.table.FeatureList:
|
||||
self.table.FeatureList.subset_features(feature_indices)
|
||||
if self.table.ScriptList:
|
||||
self.table.ScriptList.subset_features(feature_indices)
|
||||
self.table.ScriptList.subset_features(feature_indices, self.retain_empty_scripts())
|
||||
|
||||
@_add_method(ttLib.getTableClass('GSUB'),
|
||||
ttLib.getTableClass('GPOS'))
|
||||
|
Loading…
x
Reference in New Issue
Block a user