Sort feature records by feature tag

Resolves https://github.com/behdad/fonttools/issues/568
This commit is contained in:
Sascha Brawer 2016-04-12 13:53:25 +02:00
parent af5bd42479
commit 967cf8bb15
5 changed files with 106 additions and 15 deletions

View File

@ -465,7 +465,10 @@ class Builder(object):
feature_indices = {}
required_feature_indices = {} # ('latn', 'DEU') --> 23
scripts = {} # 'latn' --> {'DEU': [23, 24]} for feature #23,24
for key, lookups in sorted(self.features_.items()):
# Sort the feature table by feature tag:
# https://github.com/behdad/fonttools/issues/568
sortFeatureTag = lambda f: (f[0][2], f[0][1], f[0][0], f[1])
for key, lookups in sorted(self.features_.items(), key=sortFeatureTag):
script, lang, feature_tag = key
# l.lookup_index will be None when a lookup is not needed
# for the table under construction. For example, substitution

View File

@ -58,7 +58,7 @@ class BuilderTest(unittest.TestCase):
spec5h1 spec6b_ii spec6d2 spec6e spec6f
spec6h_ii spec6h_iii_1 spec6h_iii_3d spec8a spec8b spec8c
spec9a spec9b spec9c1 spec9c2 spec9c3 spec9d spec9e spec9f
bug453 bug463 bug501 bug502 bug505 bug506 bug509 bug512
bug453 bug463 bug501 bug502 bug505 bug506 bug509 bug512 bug568
name size size2
""".split()

View File

@ -0,0 +1,11 @@
# https://github.com/behdad/fonttools/issues/568
feature tst1 {
script latn;
pos T -20;
} tst1;
feature tst2 {
script cyrl;
pos T -80;
} tst2;

View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<ttFont>
<GPOS>
<Version value="1.0"/>
<ScriptList>
<!-- ScriptCount=2 -->
<ScriptRecord index="0">
<ScriptTag value="cyrl"/>
<Script>
<DefaultLangSys>
<ReqFeatureIndex value="65535"/>
<!-- FeatureCount=1 -->
<FeatureIndex index="0" value="1"/>
</DefaultLangSys>
<!-- LangSysCount=0 -->
</Script>
</ScriptRecord>
<ScriptRecord index="1">
<ScriptTag value="latn"/>
<Script>
<DefaultLangSys>
<ReqFeatureIndex value="65535"/>
<!-- FeatureCount=1 -->
<FeatureIndex index="0" value="0"/>
</DefaultLangSys>
<!-- LangSysCount=0 -->
</Script>
</ScriptRecord>
</ScriptList>
<FeatureList>
<!-- FeatureCount=2 -->
<FeatureRecord index="0">
<FeatureTag value="tst1"/>
<Feature>
<!-- LookupCount=1 -->
<LookupListIndex index="0" value="0"/>
</Feature>
</FeatureRecord>
<FeatureRecord index="1">
<FeatureTag value="tst2"/>
<Feature>
<!-- LookupCount=1 -->
<LookupListIndex index="0" value="1"/>
</Feature>
</FeatureRecord>
</FeatureList>
<LookupList>
<!-- LookupCount=2 -->
<Lookup index="0">
<!-- LookupType=1 -->
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<SinglePos index="0" Format="1">
<Coverage>
<Glyph value="T"/>
</Coverage>
<ValueFormat value="4"/>
<Value XAdvance="-20"/>
</SinglePos>
</Lookup>
<Lookup index="1">
<!-- LookupType=1 -->
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<SinglePos index="0" Format="1">
<Coverage>
<Glyph value="T"/>
</Coverage>
<ValueFormat value="4"/>
<Value XAdvance="-80"/>
</SinglePos>
</Lookup>
</LookupList>
</GPOS>
</ttFont>

View File

@ -14,7 +14,7 @@
<LangSys>
<ReqFeatureIndex value="0"/>
<!-- FeatureCount=1 -->
<FeatureIndex index="0" value="1"/>
<FeatureIndex index="0" value="3"/>
</LangSys>
</LangSysRecord>
<LangSysRecord index="1">
@ -22,16 +22,16 @@
<LangSys>
<ReqFeatureIndex value="65535"/>
<!-- FeatureCount=2 -->
<FeatureIndex index="0" value="2"/>
<FeatureIndex index="1" value="1"/>
<FeatureIndex index="0" value="1"/>
<FeatureIndex index="1" value="3"/>
</LangSys>
</LangSysRecord>
<LangSysRecord index="2">
<LangSysTag value="ITA "/>
<LangSys>
<ReqFeatureIndex value="3"/>
<ReqFeatureIndex value="2"/>
<!-- FeatureCount=1 -->
<FeatureIndex index="0" value="1"/>
<FeatureIndex index="0" value="3"/>
</LangSys>
</LangSysRecord>
</Script>
@ -47,26 +47,26 @@
</Feature>
</FeatureRecord>
<FeatureRecord index="1">
<FeatureTag value="scmp"/>
<Feature>
<!-- LookupCount=1 -->
<LookupListIndex index="0" value="3"/>
</Feature>
</FeatureRecord>
<FeatureRecord index="2">
<FeatureTag value="hlig"/>
<Feature>
<!-- LookupCount=1 -->
<LookupListIndex index="0" value="1"/>
</Feature>
</FeatureRecord>
<FeatureRecord index="3">
<FeatureRecord index="2">
<FeatureTag value="liga"/>
<Feature>
<!-- LookupCount=1 -->
<LookupListIndex index="0" value="2"/>
</Feature>
</FeatureRecord>
<FeatureRecord index="3">
<FeatureTag value="scmp"/>
<Feature>
<!-- LookupCount=1 -->
<LookupListIndex index="0" value="3"/>
</Feature>
</FeatureRecord>
</FeatureList>
<LookupList>
<!-- LookupCount=4 -->