Merge pull request #1811 from dscorbett/add_multiple_subst-duplicate

[feaLib] Do not fail on duplicate multiple substitutions
This commit is contained in:
Cosimo Lupo 2020-01-29 11:26:41 +00:00 committed by GitHub
commit f609293dc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 4 deletions

View File

@ -892,9 +892,17 @@ class Builder(object):
return
lookup = self.get_lookup_(location, MultipleSubstBuilder)
if glyph in lookup.mapping:
raise FeatureLibError(
'Already defined substitution for glyph "%s"' % glyph,
location)
if replacements == lookup.mapping[glyph]:
log.info(
'Removing duplicate multiple substitution from glyph'
' "%s" to %s%s',
glyph, replacements,
' at {}:{}:{}'.format(*location) if location else '',
)
else:
raise FeatureLibError(
'Already defined substitution for glyph "%s"' % glyph,
location)
lookup.mapping[glyph] = replacements
def add_reverse_chain_single_subst(self, location, old_prefix,

View File

@ -206,9 +206,20 @@ class BuilderTest(unittest.TestCase):
"feature test {"
" sub f_f_i by f f i;"
" sub c_t by c t;"
" sub f_f_i by f f i;"
" sub f_f_i by f_f i;"
"} test;")
def test_multipleSubst_multipleIdenticalSubstitutionsForSameGlyph_info(self):
logger = logging.getLogger("fontTools.feaLib.builder")
with CapturingLogHandler(logger, "INFO") as captor:
self.build(
"feature test {"
" sub f_f_i by f f i;"
" sub c_t by c t;"
" sub f_f_i by f f i;"
"} test;")
captor.assertRegex(r"Removing duplicate multiple substitution from glyph \"f_f_i\" to \('f', 'f', 'i'\)")
def test_pairPos_redefinition_warning(self):
# https://github.com/fonttools/fonttools/issues/1147
logger = logging.getLogger("fontTools.feaLib.builder")