[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."""
|
"""Calls the builder object's ``add_multiple_subst`` callback."""
|
||||||
prefix = [p.glyphSet() for p in self.prefix]
|
prefix = [p.glyphSet() for p in self.prefix]
|
||||||
suffix = [s.glyphSet() for s in self.suffix]
|
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(
|
builder.add_multiple_subst(
|
||||||
self.location, prefix, self.glyph, suffix, self.replacement, self.forceChain
|
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
|
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.
|
# GSUB lookup type 2: Multiple substitution.
|
||||||
# Format: "substitute f_f_i by f f i;"
|
# Format: "substitute f_f_i by f f i;"
|
||||||
if (
|
if (
|
||||||
not reverse
|
not reverse
|
||||||
and len(old) == 1
|
and len(old) == 1
|
||||||
and len(old[0].glyphSet()) == 1
|
and len(old[0].glyphSet()) == 1
|
||||||
and (
|
and len(new) > 1
|
||||||
(len(new) > 1 and max([len(n.glyphSet()) for n in new]) == 1)
|
and max([len(n.glyphSet()) for n in new]) == 1
|
||||||
or len(new) == 0
|
|
||||||
)
|
|
||||||
and num_lookups == 0
|
and num_lookups == 0
|
||||||
):
|
):
|
||||||
return self.ast.MultipleSubstStatement(
|
return self.ast.MultipleSubstStatement(
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
feature test {
|
feature test {
|
||||||
sub a by NULL;
|
sub a by NULL;
|
||||||
} test;
|
} test;
|
||||||
|
|
||||||
|
feature test {
|
||||||
|
sub [a b c] by NULL;
|
||||||
|
} test;
|
||||||
|
@ -22,13 +22,14 @@
|
|||||||
<FeatureRecord index="0">
|
<FeatureRecord index="0">
|
||||||
<FeatureTag value="test"/>
|
<FeatureTag value="test"/>
|
||||||
<Feature>
|
<Feature>
|
||||||
<!-- LookupCount=1 -->
|
<!-- LookupCount=2 -->
|
||||||
<LookupListIndex index="0" value="0"/>
|
<LookupListIndex index="0" value="0"/>
|
||||||
|
<LookupListIndex index="1" value="1"/>
|
||||||
</Feature>
|
</Feature>
|
||||||
</FeatureRecord>
|
</FeatureRecord>
|
||||||
</FeatureList>
|
</FeatureList>
|
||||||
<LookupList>
|
<LookupList>
|
||||||
<!-- LookupCount=1 -->
|
<!-- LookupCount=2 -->
|
||||||
<Lookup index="0">
|
<Lookup index="0">
|
||||||
<LookupType value="2"/>
|
<LookupType value="2"/>
|
||||||
<LookupFlag value="0"/>
|
<LookupFlag value="0"/>
|
||||||
@ -37,6 +38,16 @@
|
|||||||
<Substitution in="a" out=""/>
|
<Substitution in="a" out=""/>
|
||||||
</MultipleSubst>
|
</MultipleSubst>
|
||||||
</Lookup>
|
</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>
|
</LookupList>
|
||||||
</GSUB>
|
</GSUB>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user