Merge pull request #356 from anthrotype/feaLib-fix

[feaLib] make LookupList.Lookup into a list of Lookup objects, not subtables
This commit is contained in:
Sascha Brawer 2015-09-09 20:32:09 +02:00
commit d927ccf2a6
7 changed files with 212 additions and 139 deletions

View File

@ -299,9 +299,15 @@ class AlternateSubstBuilder(LookupBuilder):
self.alternates == other.alternates) self.alternates == other.alternates)
def build(self): def build(self):
lookup = otTables.AlternateSubst() lookup = otTables.Lookup()
lookup.Format = 1 lookup.SubTable = []
lookup.alternates = self.alternates st = otTables.AlternateSubst()
st.Format = 1
st.alternates = self.alternates
lookup.SubTable.append(st)
lookup.LookupFlag = self.lookup_flag
lookup.LookupType = self.lookup_type
lookup.SubTableCount = len(lookup.SubTable)
return lookup return lookup
@ -329,14 +335,20 @@ class LigatureSubstBuilder(LookupBuilder):
return (-len(components), components) return (-len(components), components)
def build(self): def build(self):
lookup = otTables.LigatureSubst() lookup = otTables.Lookup()
lookup.Format = 1 lookup.SubTable = []
lookup.ligatures = {} st = otTables.LigatureSubst()
st.Format = 1
st.ligatures = {}
for components in sorted(self.ligatures.keys(), key=self.make_key): for components in sorted(self.ligatures.keys(), key=self.make_key):
lig = otTables.Ligature() lig = otTables.Ligature()
lig.Component = components lig.Component = components
lig.LigGlyph = self.ligatures[components] lig.LigGlyph = self.ligatures[components]
lookup.ligatures.setdefault(components[0], []).append(lig) st.ligatures.setdefault(components[0], []).append(lig)
lookup.SubTable.append(st)
lookup.LookupFlag = self.lookup_flag
lookup.LookupType = self.lookup_type
lookup.SubTableCount = len(lookup.SubTable)
return lookup return lookup
@ -350,6 +362,12 @@ class SingleSubstBuilder(LookupBuilder):
self.mapping == other.mapping) self.mapping == other.mapping)
def build(self): def build(self):
lookup = otTables.SingleSubst() lookup = otTables.Lookup()
lookup.mapping = self.mapping lookup.SubTable = []
st = otTables.SingleSubst()
st.mapping = self.mapping
lookup.SubTable.append(st)
lookup.LookupFlag = self.lookup_flag
lookup.LookupType = self.lookup_type
lookup.SubTableCount = len(lookup.SubTable)
return lookup return lookup

View File

@ -37,6 +37,10 @@
</FeatureList> </FeatureList>
<LookupList> <LookupList>
<!-- LookupCount=1 --> <!-- LookupCount=1 -->
<Lookup index="0">
<!-- LookupType=3 -->
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<AlternateSubst index="0" Format="1"> <AlternateSubst index="0" Format="1">
<AlternateSet glyph="A"> <AlternateSet glyph="A">
<Alternate glyph="A.alt1"/> <Alternate glyph="A.alt1"/>
@ -51,6 +55,7 @@
<Alternate glyph="C.alt1"/> <Alternate glyph="C.alt1"/>
</AlternateSet> </AlternateSet>
</AlternateSubst> </AlternateSubst>
</Lookup>
</LookupList> </LookupList>
</GSUB> </GSUB>

View File

@ -70,22 +70,41 @@
</FeatureList> </FeatureList>
<LookupList> <LookupList>
<!-- LookupCount=4 --> <!-- LookupCount=4 -->
<Lookup index="0">
<!-- LookupType=4 -->
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<LigatureSubst index="0" Format="1"> <LigatureSubst index="0" Format="1">
<LigatureSet glyph="D"> <LigatureSet glyph="D">
<Ligature components="D,E,U" glyph="D_E_U"/> <Ligature components="D,E,U" glyph="D_E_U"/>
</LigatureSet> </LigatureSet>
</LigatureSubst> </LigatureSubst>
<LigatureSubst index="1" Format="1"> </Lookup>
<Lookup index="1">
<!-- LookupType=4 -->
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<LigatureSubst index="0" Format="1">
<LigatureSet glyph="F"> <LigatureSet glyph="F">
<Ligature components="F,R,A" glyph="D_E_U"/> <Ligature components="F,R,A" glyph="D_E_U"/>
</LigatureSet> </LigatureSet>
</LigatureSubst> </LigatureSubst>
<LigatureSubst index="2" Format="1"> </Lookup>
<Lookup index="2">
<!-- LookupType=4 -->
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<LigatureSubst index="0" Format="1">
<LigatureSet glyph="I"> <LigatureSet glyph="I">
<Ligature components="I,T,A" glyph="I_T_A"/> <Ligature components="I,T,A" glyph="I_T_A"/>
</LigatureSet> </LigatureSet>
</LigatureSubst> </LigatureSubst>
<SingleSubst index="3"> </Lookup>
<Lookup index="3">
<!-- LookupType=1 -->
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<SingleSubst index="0">
<Substitution in="a" out="A.sc"/> <Substitution in="a" out="A.sc"/>
<Substitution in="b" out="B.sc"/> <Substitution in="b" out="B.sc"/>
<Substitution in="c" out="C.sc"/> <Substitution in="c" out="C.sc"/>
@ -113,6 +132,7 @@
<Substitution in="y" out="Y.sc"/> <Substitution in="y" out="Y.sc"/>
<Substitution in="z" out="Z.sc"/> <Substitution in="z" out="Z.sc"/>
</SingleSubst> </SingleSubst>
</Lookup>
</LookupList> </LookupList>
</GSUB> </GSUB>

View File

@ -81,6 +81,10 @@
</FeatureList> </FeatureList>
<LookupList> <LookupList>
<!-- LookupCount=4 --> <!-- LookupCount=4 -->
<Lookup index="0">
<!-- LookupType=1 -->
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<SingleSubst index="0"> <SingleSubst index="0">
<Substitution in="a" out="A.sc"/> <Substitution in="a" out="A.sc"/>
<Substitution in="b" out="B.sc"/> <Substitution in="b" out="B.sc"/>
@ -109,25 +113,41 @@
<Substitution in="y" out="Y.sc"/> <Substitution in="y" out="Y.sc"/>
<Substitution in="z" out="Z.sc"/> <Substitution in="z" out="Z.sc"/>
</SingleSubst> </SingleSubst>
<LigatureSubst index="1" Format="1"> </Lookup>
<Lookup index="1">
<!-- LookupType=4 -->
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<LigatureSubst index="0" Format="1">
<LigatureSet glyph="f"> <LigatureSet glyph="f">
<Ligature components="f,f" glyph="f_f"/> <Ligature components="f,f" glyph="f_f"/>
<Ligature components="f,i" glyph="f_i"/> <Ligature components="f,i" glyph="f_i"/>
<Ligature components="f,l" glyph="f_l"/> <Ligature components="f,l" glyph="f_l"/>
</LigatureSet> </LigatureSet>
</LigatureSubst> </LigatureSubst>
<LigatureSubst index="2" Format="1"> </Lookup>
<Lookup index="2">
<!-- LookupType=4 -->
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<LigatureSubst index="0" Format="1">
<LigatureSet glyph="c"> <LigatureSet glyph="c">
<Ligature components="c,s" glyph="c_s"/> <Ligature components="c,s" glyph="c_s"/>
<Ligature components="c,t" glyph="c_t"/> <Ligature components="c,t" glyph="c_t"/>
</LigatureSet> </LigatureSet>
</LigatureSubst> </LigatureSubst>
<LigatureSubst index="3" Format="1"> </Lookup>
<Lookup index="3">
<!-- LookupType=4 -->
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<LigatureSubst index="0" Format="1">
<LigatureSet glyph="c"> <LigatureSet glyph="c">
<Ligature components="c,h" glyph="c_h"/> <Ligature components="c,h" glyph="c_h"/>
<Ligature components="c,k" glyph="c_k"/> <Ligature components="c,k" glyph="c_k"/>
</LigatureSet> </LigatureSet>
</LigatureSubst> </LigatureSubst>
</Lookup>
</LookupList> </LookupList>
</GSUB> </GSUB>

View File

@ -37,6 +37,10 @@
</FeatureList> </FeatureList>
<LookupList> <LookupList>
<!-- LookupCount=1 --> <!-- LookupCount=1 -->
<Lookup index="0">
<!-- LookupType=4 -->
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<LigatureSubst index="0" Format="1"> <LigatureSubst index="0" Format="1">
<LigatureSet glyph="one"> <LigatureSet glyph="one">
<Ligature components="one,fraction,two" glyph="onehalf"/> <Ligature components="one,fraction,two" glyph="onehalf"/>
@ -51,6 +55,7 @@
<Ligature components="one.oldstyle,slash,two.oldstyle" glyph="onehalf"/> <Ligature components="one.oldstyle,slash,two.oldstyle" glyph="onehalf"/>
</LigatureSet> </LigatureSet>
</LigatureSubst> </LigatureSubst>
</Lookup>
</LookupList> </LookupList>
</GSUB> </GSUB>

View File

@ -37,6 +37,10 @@
</FeatureList> </FeatureList>
<LookupList> <LookupList>
<!-- LookupCount=1 --> <!-- LookupCount=1 -->
<Lookup index="0">
<!-- LookupType=4 -->
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<LigatureSubst index="0" Format="1"> <LigatureSubst index="0" Format="1">
<LigatureSet glyph="f"> <LigatureSet glyph="f">
<Ligature components="f,f,i" glyph="f_f_i"/> <Ligature components="f,f,i" glyph="f_f_i"/>
@ -47,6 +51,7 @@
<Ligature components="o,f,f,i" glyph="o_f_f_i"/> <Ligature components="o,f,f,i" glyph="o_f_f_i"/>
</LigatureSet> </LigatureSet>
</LigatureSubst> </LigatureSubst>
</Lookup>
</LookupList> </LookupList>
</GSUB> </GSUB>

View File

@ -120,8 +120,8 @@ class BaseConverter(object):
raise NotImplementedError(self) raise NotImplementedError(self)
def writeArray(self, writer, font, tableDict, values): def writeArray(self, writer, font, tableDict, values):
for i in range(len(values)): for i, value in enumerate(values):
self.write(writer, font, tableDict, values[i], i) self.write(writer, font, tableDict, value, i)
def write(self, writer, font, tableDict, value, repeatIndex=None): def write(self, writer, font, tableDict, value, repeatIndex=None):
"""Write a value to the writer.""" """Write a value to the writer."""