Skip to content

Commit

Permalink
Merge pull request #1883 from khaledhosny/script-reset
Browse files Browse the repository at this point in the history
[feaLib] Ignore superfluous script statements
  • Loading branch information
khaledhosny committed Apr 21, 2020
2 parents 660531b + 259e586 commit d9a754b
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 3 deletions.
11 changes: 11 additions & 0 deletions Lib/fontTools/feaLib/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,10 @@ def set_language(self, location, language, include_default, required):
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_)
Expand Down Expand Up @@ -772,6 +776,13 @@ def set_script(self, location, script):
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
Expand Down
12 changes: 12 additions & 0 deletions Tests/feaLib/builder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,12 @@ def test_script_in_size_feature(self):
"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 ')
Expand Down Expand Up @@ -364,6 +370,12 @@ def test_language_in_size_feature(self):
"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,
Expand Down
13 changes: 13 additions & 0 deletions Tests/feaLib/data/lookupflag.fea
Original file line number Diff line number Diff line change
Expand Up @@ -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;
49 changes: 46 additions & 3 deletions Tests/feaLib/data/lookupflag.ttx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<GPOS>
<Version value="0x00010000"/>
<ScriptList>
<!-- ScriptCount=1 -->
<!-- ScriptCount=2 -->
<ScriptRecord index="0">
<ScriptTag value="DFLT"/>
<Script>
Expand All @@ -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>
Expand Down Expand Up @@ -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 -->
Expand Down Expand Up @@ -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>

Expand Down

0 comments on commit d9a754b

Please sign in to comment.