Merge pull request #2303 from fonttools/glyphclass-by-null

[feaLib] Allow substituting a glyph class with NULL
This commit is contained in:
Cosimo Lupo 2021-05-13 10:41:54 +01:00 committed by GitHub
commit c51d3aa061
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 9 deletions

View File

@ -1258,9 +1258,15 @@ class MultipleSubstStatement(Statement):
"""Calls the builder object's ``add_multiple_subst`` callback."""
prefix = [p.glyphSet() for p in self.prefix]
suffix = [s.glyphSet() for s in self.suffix]
builder.add_multiple_subst(
self.location, prefix, self.glyph, suffix, self.replacement, self.forceChain
)
if not self.replacement and hasattr(self.glyph, "glyphSet"):
for glyph in self.glyph.glyphSet():
builder.add_multiple_subst(
self.location, prefix, glyph, suffix, self.replacement, self.forceChain
)
else:
builder.add_multiple_subst(
self.location, prefix, self.glyph, suffix, self.replacement, self.forceChain
)
def asFea(self, indent=""):
res = "sub "

View File

@ -892,16 +892,26 @@ class Parser(object):
old, new, old_prefix, old_suffix, forceChain=hasMarks, location=location
)
# Glyph deletion, built as GSUB lookup type 2: Multiple substitution
# with empty replacement.
if is_deletion and len(old) == 1 and num_lookups == 0:
return self.ast.MultipleSubstStatement(
old_prefix,
old[0],
old_suffix,
(),
forceChain=hasMarks,
location=location,
)
# GSUB lookup type 2: Multiple substitution.
# Format: "substitute f_f_i by f f i;"
if (
not reverse
and len(old) == 1
and len(old[0].glyphSet()) == 1
and (
(len(new) > 1 and max([len(n.glyphSet()) for n in new]) == 1)
or len(new) == 0
)
and len(new) > 1
and max([len(n.glyphSet()) for n in new]) == 1
and num_lookups == 0
):
return self.ast.MultipleSubstStatement(

View File

@ -1,3 +1,7 @@
feature test {
sub a by NULL;
} test;
feature test {
sub [a b c] by NULL;
} test;

View File

@ -22,13 +22,14 @@
<FeatureRecord index="0">
<FeatureTag value="test"/>
<Feature>
<!-- LookupCount=1 -->
<!-- LookupCount=2 -->
<LookupListIndex index="0" value="0"/>
<LookupListIndex index="1" value="1"/>
</Feature>
</FeatureRecord>
</FeatureList>
<LookupList>
<!-- LookupCount=1 -->
<!-- LookupCount=2 -->
<Lookup index="0">
<LookupType value="2"/>
<LookupFlag value="0"/>
@ -37,6 +38,16 @@
<Substitution in="a" out=""/>
</MultipleSubst>
</Lookup>
<Lookup index="1">
<LookupType value="2"/>
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<MultipleSubst index="0">
<Substitution in="a" out=""/>
<Substitution in="b" out=""/>
<Substitution in="c" out=""/>
</MultipleSubst>
</Lookup>
</LookupList>
</GSUB>