Never reuse class=0 in ClassDef

That means "not found".
This commit is contained in:
Behdad Esfahbod 2013-08-06 11:12:49 -04:00
parent 0befd6ba0b
commit dd6fc84f35

View File

@ -58,8 +58,8 @@ def subset (self, glyphs):
@add_method(fontTools.ttLib.tables.otTables.ClassDef) @add_method(fontTools.ttLib.tables.otTables.ClassDef)
def intersect (self, glyphs): def intersect (self, glyphs):
"Returns ascending list of matching class values." "Returns ascending list of matching class values. Always includes class 0."
return unique_sorted (v for g,v in self.classDefs.items() if g in glyphs) return unique_sorted ([0] + [v for g,v in self.classDefs.items() if g in glyphs])
@add_method(fontTools.ttLib.tables.otTables.ClassDef) @add_method(fontTools.ttLib.tables.otTables.ClassDef)
def intersects_class (self, glyphs, klass): def intersects_class (self, glyphs, klass):
@ -72,9 +72,9 @@ def intersects_class (self, glyphs, klass):
@add_method(fontTools.ttLib.tables.otTables.ClassDef) @add_method(fontTools.ttLib.tables.otTables.ClassDef)
def subset (self, glyphs, remap=False): def subset (self, glyphs, remap=False):
"Returns ascending list of remaining classes." "Returns ascending list of remaining classes. Doesn't reuse class 0."
self.classDefs = {g:v for g,v in self.classDefs.items() if g in glyphs} self.classDefs = {g:v for g,v in self.classDefs.items() if g in glyphs}
indices = unique_sorted (self.classDefs.values ()) indices = unique_sorted ([0] + self.classDefs.values ())
if remap: if remap:
self.remap (indices) self.remap (indices)
return indices return indices
@ -393,7 +393,7 @@ def closure_glyphs (self, s):
indices = self.Coverage.intersect (s.glyphs) indices = self.Coverage.intersect (s.glyphs)
rss = getattr (self, c.RuleSet) rss = getattr (self, c.RuleSet)
return sum ((s.table.LookupList.Lookup[ll.LookupListIndex].closure_glyphs (s) \ return sum ((s.table.LookupList.Lookup[ll.LookupListIndex].closure_glyphs (s) \
for i in indices \ for i in indices if rss[i] \
for r in getattr (rss[i], c.Rule) \ for r in getattr (rss[i], c.Rule) \
if r and all (g in s.glyphs for g in c.RuleData (r)) \ if r and all (g in s.glyphs for g in c.RuleData (r)) \
for ll in getattr (r, c.LookupRecord) if ll \ for ll in getattr (r, c.LookupRecord) if ll \
@ -404,7 +404,7 @@ def closure_glyphs (self, s):
indices = getattr (self, c.ClassDef).intersect (s.glyphs) indices = getattr (self, c.ClassDef).intersect (s.glyphs)
rss = getattr (self, c.RuleSet) rss = getattr (self, c.RuleSet)
return sum ((s.table.LookupList.Lookup[ll.LookupListIndex].closure_glyphs (s) \ return sum ((s.table.LookupList.Lookup[ll.LookupListIndex].closure_glyphs (s) \
for i in indices \ for i in indices if rss[i] \
for r in getattr (rss[i], c.Rule) \ for r in getattr (rss[i], c.Rule) \
if r and all (cd.intersects_class (s.glyphs, k) \ if r and all (cd.intersects_class (s.glyphs, k) \
for cd,k in zip (c.ContextData (self), c.RuleData (r))) \ for cd,k in zip (c.ContextData (self), c.RuleData (r))) \