[feaLib] don't de-duplicate lookups

keep original lookup order and preserve the feature file's semantics

Fixes https://github.com/fonttools/fonttools/issues/448
This commit is contained in:
Cosimo Lupo 2017-05-30 10:28:40 +01:00 committed by Sascha Brawer
parent 0f1de0873f
commit 12b90f073e
5 changed files with 72 additions and 22 deletions

View File

@ -451,22 +451,9 @@ class Builder(object):
for lookup in self.lookups_:
lookup.lookup_index = None
lookups = []
for i, lookup in enumerate(self.lookups_):
for lookup in self.lookups_:
if lookup.table != tag:
continue
# TODO: https://github.com/behdad/fonttools/issues/448
# If multiple lookup builders would build equivalent lookups,
# emit them only once. This is quadratic in the number of lookups,
# but the checks are cheap. If performance ever becomes an issue,
# we could hash the lookup content and only compare those with
# the same hash value.
equivalent = None
for other in self.lookups_[:i]:
if lookup.equals(other):
equivalent = other
if equivalent is not None:
lookup.lookup_index = equivalent.lookup_index
continue
lookup.lookup_index = len(lookups)
lookups.append(lookup)
return [l.build() for l in lookups]

View File

@ -31,12 +31,12 @@
<FeatureTag value="f2 "/>
<Feature>
<!-- LookupCount=1 -->
<LookupListIndex index="0" value="0"/>
<LookupListIndex index="0" value="1"/>
</Feature>
</FeatureRecord>
</FeatureList>
<LookupList>
<!-- LookupCount=1 -->
<!-- LookupCount=2 -->
<Lookup index="0">
<LookupType value="2"/>
<LookupFlag value="0"/>
@ -47,6 +47,16 @@
<Substitution in="f_i" out="f,i"/>
</MultipleSubst>
</Lookup>
<Lookup index="1">
<LookupType value="2"/>
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<MultipleSubst index="0">
<Substitution in="c_t" out="c,t"/>
<Substitution in="f_f_i" out="f,f,i"/>
<Substitution in="f_i" out="f,i"/>
</MultipleSubst>
</Lookup>
</LookupList>
</GSUB>

View File

@ -31,12 +31,12 @@
<FeatureTag value="f2 "/>
<Feature>
<!-- LookupCount=1 -->
<LookupListIndex index="0" value="0"/>
<LookupListIndex index="0" value="1"/>
</Feature>
</FeatureRecord>
</FeatureList>
<LookupList>
<!-- LookupCount=1 -->
<!-- LookupCount=2 -->
<Lookup index="0">
<LookupType value="3"/>
<LookupFlag value="0"/>
@ -56,6 +56,25 @@
</AlternateSet>
</AlternateSubst>
</Lookup>
<Lookup index="1">
<LookupType value="3"/>
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<AlternateSubst index="0">
<AlternateSet glyph="A">
<Alternate glyph="A.alt1"/>
<Alternate glyph="A.alt2"/>
</AlternateSet>
<AlternateSet glyph="B">
<Alternate glyph="B.alt1"/>
<Alternate glyph="B.alt2"/>
<Alternate glyph="B.alt3"/>
</AlternateSet>
<AlternateSet glyph="C">
<Alternate glyph="C.alt1"/>
</AlternateSet>
</AlternateSubst>
</Lookup>
</LookupList>
</GSUB>

View File

@ -31,12 +31,12 @@
<FeatureTag value="F2 "/>
<Feature>
<!-- LookupCount=1 -->
<LookupListIndex index="0" value="0"/>
<LookupListIndex index="0" value="1"/>
</Feature>
</FeatureRecord>
</FeatureList>
<LookupList>
<!-- LookupCount=1 -->
<!-- LookupCount=2 -->
<Lookup index="0">
<LookupType value="4"/>
<LookupFlag value="0"/>
@ -56,6 +56,25 @@
</LigatureSet>
</LigatureSubst>
</Lookup>
<Lookup index="1">
<LookupType value="4"/>
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<LigatureSubst index="0">
<LigatureSet glyph="one">
<Ligature components="fraction,two" glyph="onehalf"/>
<Ligature components="fraction,two.oldstyle" glyph="onehalf"/>
<Ligature components="slash,two" glyph="onehalf"/>
<Ligature components="slash,two.oldstyle" glyph="onehalf"/>
</LigatureSet>
<LigatureSet glyph="one.oldstyle">
<Ligature components="fraction,two" glyph="onehalf"/>
<Ligature components="fraction,two.oldstyle" glyph="onehalf"/>
<Ligature components="slash,two" glyph="onehalf"/>
<Ligature components="slash,two.oldstyle" glyph="onehalf"/>
</LigatureSet>
</LigatureSubst>
</Lookup>
</LookupList>
</GSUB>

View File

@ -31,12 +31,12 @@
<FeatureTag value="F2 "/>
<Feature>
<!-- LookupCount=1 -->
<LookupListIndex index="0" value="0"/>
<LookupListIndex index="0" value="1"/>
</Feature>
</FeatureRecord>
</FeatureList>
<LookupList>
<!-- LookupCount=1 -->
<!-- LookupCount=2 -->
<Lookup index="0">
<LookupType value="4"/>
<LookupFlag value="0"/>
@ -52,6 +52,21 @@
</LigatureSet>
</LigatureSubst>
</Lookup>
<Lookup index="1">
<LookupType value="4"/>
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<LigatureSubst index="0">
<LigatureSet glyph="f">
<Ligature components="f,i" glyph="f_f_i"/>
<Ligature components="f" glyph="f_f"/>
<Ligature components="i" glyph="f_i"/>
</LigatureSet>
<LigatureSet glyph="o">
<Ligature components="f,f,i" glyph="o_f_f_i"/>
</LigatureSet>
</LigatureSubst>
</Lookup>
</LookupList>
</GSUB>