Merge pull request #1300 from anthrotype/explicit-subtable-break

support explicit "subtable" breaks in kerning lookups
This commit is contained in:
Cosimo Lupo 2018-07-25 11:58:26 +01:00 committed by GitHub
commit 8991f2c097
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 3 deletions

View File

@ -1077,6 +1077,9 @@ class SubtableStatement(Statement):
def __init__(self, location=None):
Statement.__init__(self, location)
def build(self, builder):
builder.add_subtable_break(self.location)
def asFea(self, indent=""):
return indent + "subtable;"

View File

@ -999,6 +999,16 @@ class Builder(object):
lookup = self.get_lookup_(location, PairPosBuilder)
lookup.addClassPair(location, glyphclass1, value1, glyphclass2, value2)
def add_subtable_break(self, location):
if type(self.cur_lookup_) is not PairPosBuilder:
raise FeatureLibError(
'explicit "subtable" statement is intended for use with only '
"Pair Adjustment Positioning Format 2 (i.e. pair class kerning)",
location
)
lookup = self.get_lookup_(location, PairPosBuilder)
lookup.add_subtable_break(location)
def add_specific_pair_pos(self, location, glyph1, value1, glyph2, value2):
lookup = self.get_lookup_(location, PairPosBuilder)
lookup.addGlyphPair(location, glyph1, value1, glyph2, value2)

View File

@ -512,6 +512,18 @@ class BuilderTest(unittest.TestCase):
addOpenTypeFeatures(font, tree)
assert "GSUB" in font
def test_unsupported_subtable_break(self):
self.assertRaisesRegex(
FeatureLibError,
'explicit "subtable" statement is intended for .* class kerning',
self.build,
"feature liga {"
" sub f f by f_f;"
" subtable;"
" sub f i by f_i;"
"} liga;"
)
def generate_feature_file_test(name):
return lambda self: self.check_feature_file(name)

View File

@ -1,12 +1,16 @@
languagesystem DFLT dflt;
languagesystem latn dflt;
@group1 = [b o];
@group2 = [c d];
@group3 = [v w];
lookup kernlookup {
pos A V -34;
subtable;
@group1 = [b o];
@group2 = [c d];
pos @group1 @group2 -12;
subtable;
pos @group3 @group2 -20;
} kernlookup;
feature kern {

View File

@ -43,7 +43,7 @@
<Lookup index="0">
<LookupType value="2"/>
<LookupFlag value="0"/>
<!-- SubTableCount=2 -->
<!-- SubTableCount=3 -->
<PairPos index="0" Format="1">
<Coverage>
<Glyph value="A"/>
@ -82,6 +82,29 @@
</Class2Record>
</Class1Record>
</PairPos>
<PairPos index="2" Format="2">
<Coverage>
<Glyph value="v"/>
<Glyph value="w"/>
</Coverage>
<ValueFormat1 value="4"/>
<ValueFormat2 value="0"/>
<ClassDef1>
</ClassDef1>
<ClassDef2>
<ClassDef glyph="c" class="1"/>
<ClassDef glyph="d" class="1"/>
</ClassDef2>
<!-- Class1Count=1 -->
<!-- Class2Count=2 -->
<Class1Record index="0">
<Class2Record index="0">
</Class2Record>
<Class2Record index="1">
<Value1 XAdvance="-20"/>
</Class2Record>
</Class1Record>
</PairPos>
</Lookup>
</LookupList>
</GPOS>