diff options
author | Alexander Smirnov <alex@ydb.tech> | 2025-05-29 11:09:23 +0000 |
---|---|---|
committer | Alexander Smirnov <alex@ydb.tech> | 2025-05-29 11:09:23 +0000 |
commit | a34a6816abefdcfe2c00295edb510cc5c99ad52c (patch) | |
tree | a264baadccf7add09a1b285786307ddd774472a5 /contrib/python/fonttools/fontTools/voltLib/parser.py | |
parent | 84ec9093e10073ab151bfe5f81037a0d017c2362 (diff) | |
parent | fdbc38349df2ee0ddc678fa2bffe84786f9639a3 (diff) | |
download | ydb-a34a6816abefdcfe2c00295edb510cc5c99ad52c.tar.gz |
Merge branch 'rightlib' into merge-libs-250529-1108
Diffstat (limited to 'contrib/python/fonttools/fontTools/voltLib/parser.py')
-rw-r--r-- | contrib/python/fonttools/fontTools/voltLib/parser.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/contrib/python/fonttools/fontTools/voltLib/parser.py b/contrib/python/fonttools/fontTools/voltLib/parser.py index 1fa6b11d027..31a76e69bff 100644 --- a/contrib/python/fonttools/fontTools/voltLib/parser.py +++ b/contrib/python/fonttools/fontTools/voltLib/parser.py @@ -313,19 +313,27 @@ class Parser(object): self.expect_keyword_("END_SUBSTITUTION") max_src = max([len(cov) for cov in src]) max_dest = max([len(cov) for cov in dest]) + # many to many or mixed is invalid - if (max_src > 1 and max_dest > 1) or ( - reversal and (max_src > 1 or max_dest > 1) - ): + if max_src > 1 and max_dest > 1: raise VoltLibError("Invalid substitution type", location) + mapping = dict(zip(tuple(src), tuple(dest))) if max_src == 1 and max_dest == 1: - if reversal: - sub = ast.SubstitutionReverseChainingSingleDefinition( - mapping, location=location - ) + # Alternate substitutions are represented by adding multiple + # substitutions for the same glyph, so we detect that here + glyphs = [x.glyphSet() for cov in src for x in cov] # flatten src + if len(set(glyphs)) != len(glyphs): # src has duplicates + sub = ast.SubstitutionAlternateDefinition(mapping, location=location) else: - sub = ast.SubstitutionSingleDefinition(mapping, location=location) + if reversal: + # Reversal is valid only for single glyph substitutions + # and VOLT ignores it otherwise. + sub = ast.SubstitutionReverseChainingSingleDefinition( + mapping, location=location + ) + else: + sub = ast.SubstitutionSingleDefinition(mapping, location=location) elif max_src == 1 and max_dest > 1: sub = ast.SubstitutionMultipleDefinition(mapping, location=location) elif max_src > 1 and max_dest == 1: |