Merge pull request #1883 from khaledhosny/script-reset

[feaLib] Ignore superfluous script statements
This commit is contained in:
Khaled Hosny 2020-04-21 16:45:43 +02:00 committed by GitHub
commit d9a754b48f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 82 additions and 3 deletions

View File

@ -706,6 +706,10 @@ class Builder(object):
raise FeatureLibError(
"Language statements are not allowed "
"within \"feature %s\"" % self.cur_feature_name_, location)
if self.cur_feature_name_ is None:
raise FeatureLibError(
"Language statements are not allowed "
"within standalone lookup blocks", location)
self.cur_lookup_ = None
key = (self.script_, language, self.cur_feature_name_)
@ -772,6 +776,13 @@ class Builder(object):
raise FeatureLibError(
"Script statements are not allowed "
"within \"feature %s\"" % self.cur_feature_name_, location)
if self.cur_feature_name_ is None:
raise FeatureLibError(
"Script statements are not allowed "
"within standalone lookup blocks", location)
if self.language_systems == {(script, 'dflt')}:
# Nothing to do.
return
self.cur_lookup_ = None
self.script_ = script
self.lookupflag_ = 0

View File

@ -337,6 +337,12 @@ class BuilderTest(unittest.TestCase):
"Script statements are not allowed within \"feature size\"",
self.build, "feature size { script latn; } size;")
def test_script_in_standalone_lookup(self):
self.assertRaisesRegex(
FeatureLibError,
"Script statements are not allowed within standalone lookup blocks",
self.build, "lookup test { script latn; } test;")
def test_language(self):
builder = Builder(makeTTFont(), (None, None))
builder.add_language_system(None, 'latn', 'FRA ')
@ -364,6 +370,12 @@ class BuilderTest(unittest.TestCase):
"Language statements are not allowed within \"feature size\"",
self.build, "feature size { language FRA; } size;")
def test_language_in_standalone_lookup(self):
self.assertRaisesRegex(
FeatureLibError,
"Language statements are not allowed within standalone lookup blocks",
self.build, "lookup test { language FRA; } test;")
def test_language_required_duplicate(self):
self.assertRaisesRegex(
FeatureLibError,

View File

@ -134,3 +134,16 @@ feature test {
pos one 1;
} V;
} test;
feature test {
lookup W {
lookupflag IgnoreMarks;
script latn;
pos one 1;
} W;
lookup X {
lookupflag IgnoreMarks;
script latn;
pos two 2;
} X;
} test;

View File

@ -43,7 +43,7 @@
<GPOS>
<Version value="0x00010000"/>
<ScriptList>
<!-- ScriptCount=1 -->
<!-- ScriptCount=2 -->
<ScriptRecord index="0">
<ScriptTag value="DFLT"/>
<Script>
@ -55,9 +55,20 @@
<!-- LangSysCount=0 -->
</Script>
</ScriptRecord>
<ScriptRecord index="1">
<ScriptTag value="latn"/>
<Script>
<DefaultLangSys>
<ReqFeatureIndex value="65535"/>
<!-- FeatureCount=1 -->
<FeatureIndex index="0" value="1"/>
</DefaultLangSys>
<!-- LangSysCount=0 -->
</Script>
</ScriptRecord>
</ScriptList>
<FeatureList>
<!-- FeatureCount=1 -->
<!-- FeatureCount=2 -->
<FeatureRecord index="0">
<FeatureTag value="test"/>
<Feature>
@ -86,9 +97,17 @@
<LookupListIndex index="21" value="21"/>
</Feature>
</FeatureRecord>
<FeatureRecord index="1">
<FeatureTag value="test"/>
<Feature>
<!-- LookupCount=2 -->
<LookupListIndex index="0" value="22"/>
<LookupListIndex index="1" value="23"/>
</Feature>
</FeatureRecord>
</FeatureList>
<LookupList>
<!-- LookupCount=22 -->
<!-- LookupCount=24 -->
<Lookup index="0">
<LookupType value="1"/>
<LookupFlag value="1"/><!-- rightToLeft -->
@ -357,6 +376,30 @@
<Value XAdvance="1"/>
</SinglePos>
</Lookup>
<Lookup index="22">
<LookupType value="1"/>
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<SinglePos index="0" Format="1">
<Coverage>
<Glyph value="one"/>
</Coverage>
<ValueFormat value="4"/>
<Value XAdvance="1"/>
</SinglePos>
</Lookup>
<Lookup index="23">
<LookupType value="1"/>
<LookupFlag value="8"/><!-- ignoreMarks -->
<!-- SubTableCount=1 -->
<SinglePos index="0" Format="1">
<Coverage>
<Glyph value="two"/>
</Coverage>
<ValueFormat value="4"/>
<Value XAdvance="2"/>
</SinglePos>
</Lookup>
</LookupList>
</GPOS>