[subset] Fix renumbering of (Chain)ContextFormat2
Jonathan says: "It was broken."
This commit is contained in:
parent
3977d3e9e2
commit
98b60757ab
@ -557,6 +557,7 @@ def __classify_context(self):
|
||||
self.Intersect = lambda glyphs, c, r: c.intersect_class(glyphs, r)
|
||||
|
||||
self.ClassDef = 'InputClassDef' if Chain else 'ClassDef'
|
||||
self.ClassDefIndex = 1 if Chain else 0
|
||||
self.Input = 'Input' if Chain else 'Class'
|
||||
|
||||
if self.Format not in [1, 2, 3]:
|
||||
@ -676,12 +677,21 @@ def subset_glyphs(self, s):
|
||||
elif self.Format == 2:
|
||||
if not self.Coverage.subset(s.glyphs):
|
||||
return False
|
||||
indices = getattr(self, c.ClassDef).subset(self.Coverage.glyphs,
|
||||
remap=False)
|
||||
rss = getattr(self, c.RuleSet)
|
||||
rss = [rss[i] for i in indices]
|
||||
ContextData = c.ContextData(self)
|
||||
klass_maps = [x.subset(s.glyphs, remap=True) for x in ContextData]
|
||||
|
||||
# Keep rulesets for class numbers that survived.
|
||||
indices = klass_maps[c.ClassDefIndex]
|
||||
rss = getattr(self, c.RuleSet)
|
||||
rssCount = getattr(self, c.RuleSetCount)
|
||||
rss = [rss[i] for i in indices if i < rssCount]
|
||||
del rssCount
|
||||
# Delete, but not renumber, unreachable rulesets.
|
||||
indices = getattr(self, c.ClassDef).intersect(self.Coverage.glyphs)
|
||||
rss = [rss if i in indices else None for i,rss in enumerate(rss)]
|
||||
while rss and rss[-1] == None:
|
||||
del rss[-1]
|
||||
|
||||
for rs in rss:
|
||||
if not rs: continue
|
||||
ss = getattr(rs, c.Rule)
|
||||
@ -695,10 +705,6 @@ def subset_glyphs(self, s):
|
||||
for r in ss:
|
||||
c.SetRuleData(r, [[klass_map.index(k) for k in klist]
|
||||
for klass_map,klist in zip(klass_maps, c.RuleData(r))])
|
||||
# Prune empty subrulesets
|
||||
rss = [rs for rs in rss if rs and getattr(rs, c.Rule)]
|
||||
setattr(self, c.RuleSet, rss)
|
||||
setattr(self, c.RuleSetCount, len(rss))
|
||||
return bool(rss)
|
||||
elif self.Format == 3:
|
||||
return all(x.subset(s.glyphs) for x in c.RuleData(self))
|
||||
|
Loading…
x
Reference in New Issue
Block a user