[feaLib] Allow substituting a glyph class with NULL
sub [a b c] by NULL; was producing errors, now it builds as multiple statements.
This commit is contained in:
parent
31ab3aae0b
commit
f6d2ff8d2a
@ -1258,6 +1258,12 @@ 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]
|
||||
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
|
||||
)
|
||||
|
@ -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(
|
||||
|
@ -1,3 +1,7 @@
|
||||
feature test {
|
||||
sub a by NULL;
|
||||
} test;
|
||||
|
||||
feature test {
|
||||
sub [a b c] by NULL;
|
||||
} test;
|
||||
|
@ -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>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user