[feaLib] Allow script and language statements in named lookup blocks

Although the specification writes the exact opposite, makeotf does
accept script and language statements inside named lookup blocks.
Since Glyphs.app (and possibly other tools, too) produce feature files
that make use of this syntax, enforcing the spec would break existing
files.

Resolves https://github.com/behdad/fonttools/issues/501.
This commit is contained in:
Sascha Brawer 2016-02-04 09:52:20 +01:00
parent a3f70370fe
commit f9a236f54e
4 changed files with 67 additions and 23 deletions

View File

@ -385,10 +385,6 @@ class Builder(object):
def set_language(self, location, language, include_default, required):
assert(len(language) == 4)
if self.cur_lookup_name_:
raise FeatureLibError(
"Within a named lookup block, it is not allowed "
"to change the language", location)
if self.cur_feature_name_ in ('aalt', 'size'):
raise FeatureLibError(
"Language statements are not allowed "
@ -450,10 +446,6 @@ class Builder(object):
self.lookupflag_ = value
def set_script(self, location, script):
if self.cur_lookup_name_:
raise FeatureLibError(
"Within a named lookup block, it is not allowed "
"to change the script", location)
if self.cur_feature_name_ in ('aalt', 'size'):
raise FeatureLibError(
"Script statements are not allowed "

View File

@ -51,7 +51,7 @@ class BuilderTest(unittest.TestCase):
spec4h1 spec5d1 spec5d2 spec5fi1 spec5fi2 spec5fi3 spec5fi4
spec5h1 spec6b_ii spec6d2 spec6e spec6f spec6h_ii spec6h_iii_1 spec8a
spec9b spec9c1 spec9c2 spec9c3
bug463 bug502
bug463 bug501 bug502
""".split()
def __init__(self, methodName):
@ -237,13 +237,6 @@ class BuilderTest(unittest.TestCase):
"Script statements are not allowed within \"feature aalt\"",
self.build, "feature aalt { script latn; } aalt;")
def test_script_in_lookup_block(self):
self.assertRaisesRegex(
FeatureLibError,
"Within a named lookup block, it is not allowed "
"to change the script",
self.build, "lookup Foo { script latn; } Foo;")
def test_script_in_size_feature(self):
self.assertRaisesRegex(
FeatureLibError,
@ -269,13 +262,6 @@ class BuilderTest(unittest.TestCase):
"Language statements are not allowed within \"feature aalt\"",
self.build, "feature aalt { language FRA; } aalt;")
def test_language_in_lookup_block(self):
self.assertRaisesRegex(
FeatureLibError,
"Within a named lookup block, it is not allowed "
"to change the language",
self.build, "lookup Foo { language RUS; } Foo;")
def test_language_in_size_feature(self):
self.assertRaisesRegex(
FeatureLibError,

View File

@ -0,0 +1,8 @@
# https://github.com/behdad/fonttools/issues/501
languagesystem DFLT dflt;
feature test {
lookup L {
script grek;
pos T 100;
} L;
} test;

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<ttFont sfntVersion="true" ttLibVersion="3.0">
<GPOS>
<Version value="1.0"/>
<ScriptList>
<!-- ScriptCount=2 -->
<ScriptRecord index="0">
<ScriptTag value="DFLT"/>
<Script>
<DefaultLangSys>
<ReqFeatureIndex value="65535"/>
<!-- FeatureCount=1 -->
<FeatureIndex index="0" value="0"/>
</DefaultLangSys>
<!-- LangSysCount=0 -->
</Script>
</ScriptRecord>
<ScriptRecord index="1">
<ScriptTag value="grek"/>
<Script>
<DefaultLangSys>
<ReqFeatureIndex value="65535"/>
<!-- FeatureCount=1 -->
<FeatureIndex index="0" value="0"/>
</DefaultLangSys>
<!-- LangSysCount=0 -->
</Script>
</ScriptRecord>
</ScriptList>
<FeatureList>
<!-- FeatureCount=1 -->
<FeatureRecord index="0">
<FeatureTag value="test"/>
<Feature>
<!-- LookupCount=1 -->
<LookupListIndex index="0" value="0"/>
</Feature>
</FeatureRecord>
</FeatureList>
<LookupList>
<!-- LookupCount=1 -->
<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="100"/>
</SinglePos>
</Lookup>
</LookupList>
</GPOS>
</ttFont>