[feaLib] Refactor almost duplicated subtable code
Also make the code a little less ugly.
This commit is contained in:
parent
226f5518b7
commit
10cad7be3a
@ -1168,6 +1168,16 @@ class LookupBuilder(object):
|
|||||||
coverage = otl.buildCoverage(g, self.glyphMap)
|
coverage = otl.buildCoverage(g, self.glyphMap)
|
||||||
subtable.InputCoverage.append(coverage)
|
subtable.InputCoverage.append(coverage)
|
||||||
|
|
||||||
|
def build_subst_subtables(self, mapping, klass):
|
||||||
|
substitutions = [{}]
|
||||||
|
for key in mapping:
|
||||||
|
if key[0] == self.SUBTABLE_BREAK_:
|
||||||
|
substitutions.append({})
|
||||||
|
else:
|
||||||
|
substitutions[-1][key] = mapping[key]
|
||||||
|
subtables = [klass(s) for s in substitutions]
|
||||||
|
return subtables
|
||||||
|
|
||||||
def add_subtable_break(self, location):
|
def add_subtable_break(self, location):
|
||||||
raise FeatureLibError(
|
raise FeatureLibError(
|
||||||
'unsupported "subtable" statement for lookup type',
|
'unsupported "subtable" statement for lookup type',
|
||||||
@ -1185,16 +1195,8 @@ class AlternateSubstBuilder(LookupBuilder):
|
|||||||
self.alternates == other.alternates)
|
self.alternates == other.alternates)
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
subtables = []
|
subtables = self.build_subst_subtables(self.alternates,
|
||||||
alternates = {}
|
otl.buildAlternateSubstSubtable)
|
||||||
for key in self.alternates:
|
|
||||||
if key[0] == self.SUBTABLE_BREAK_:
|
|
||||||
subtables.append(otl.buildAlternateSubstSubtable(alternates))
|
|
||||||
alternates = {}
|
|
||||||
else:
|
|
||||||
alternates[key] = self.alternates[key]
|
|
||||||
if alternates:
|
|
||||||
subtables.append(otl.buildAlternateSubstSubtable(alternates))
|
|
||||||
return self.buildLookup_(subtables)
|
return self.buildLookup_(subtables)
|
||||||
|
|
||||||
def getAlternateGlyphs(self):
|
def getAlternateGlyphs(self):
|
||||||
@ -1320,15 +1322,8 @@ class LigatureSubstBuilder(LookupBuilder):
|
|||||||
self.ligatures == other.ligatures)
|
self.ligatures == other.ligatures)
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
subtables = []
|
subtables = self.build_subst_subtables(self.ligatures,
|
||||||
ligatures = {}
|
otl.buildLigatureSubstSubtable)
|
||||||
for key in self.ligatures:
|
|
||||||
if key[0] == self.SUBTABLE_BREAK_:
|
|
||||||
subtables.append(otl.buildLigatureSubstSubtable(ligatures))
|
|
||||||
ligatures = {}
|
|
||||||
else:
|
|
||||||
ligatures[key] = self.ligatures[key]
|
|
||||||
subtables.append(otl.buildLigatureSubstSubtable(ligatures))
|
|
||||||
return self.buildLookup_(subtables)
|
return self.buildLookup_(subtables)
|
||||||
|
|
||||||
def add_subtable_break(self, location):
|
def add_subtable_break(self, location):
|
||||||
@ -1345,15 +1340,8 @@ class MultipleSubstBuilder(LookupBuilder):
|
|||||||
self.mapping == other.mapping)
|
self.mapping == other.mapping)
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
subtables = []
|
subtables = self.build_subst_subtables(self.mapping,
|
||||||
mapping = {}
|
otl.buildMultipleSubstSubtable)
|
||||||
for key in self.mapping:
|
|
||||||
if key[0] == self.SUBTABLE_BREAK_:
|
|
||||||
subtables.append(otl.buildMultipleSubstSubtable(mapping))
|
|
||||||
mapping = {}
|
|
||||||
else:
|
|
||||||
mapping[key] = self.mapping[key]
|
|
||||||
subtables.append(otl.buildMultipleSubstSubtable(mapping))
|
|
||||||
return self.buildLookup_(subtables)
|
return self.buildLookup_(subtables)
|
||||||
|
|
||||||
def add_subtable_break(self, location):
|
def add_subtable_break(self, location):
|
||||||
@ -1509,15 +1497,8 @@ class SingleSubstBuilder(LookupBuilder):
|
|||||||
self.mapping == other.mapping)
|
self.mapping == other.mapping)
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
subtables = []
|
subtables = self.build_subst_subtables(self.mapping,
|
||||||
mapping = {}
|
otl.buildSingleSubstSubtable)
|
||||||
for key in self.mapping:
|
|
||||||
if key[0] == self.SUBTABLE_BREAK_:
|
|
||||||
subtables.append(otl.buildSingleSubstSubtable(mapping))
|
|
||||||
mapping = {}
|
|
||||||
else:
|
|
||||||
mapping[key] = self.mapping[key]
|
|
||||||
subtables.append(otl.buildSingleSubstSubtable(mapping))
|
|
||||||
return self.buildLookup_(subtables)
|
return self.buildLookup_(subtables)
|
||||||
|
|
||||||
def getAlternateGlyphs(self):
|
def getAlternateGlyphs(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user