diff options
author | Maxim Yurchuk <[email protected]> | 2025-05-30 21:14:52 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2025-05-30 21:14:52 +0000 |
commit | c75cf6fa89ba44e2fa74a15232593b2e8423ed3f (patch) | |
tree | a7f428153ad7b3109180af04a9c84af2b0ab2a16 /contrib/python/fonttools/fontTools/voltLib/parser.py | |
parent | b21606bc4b50665ea3fdca703e13a4b4d7a44284 (diff) | |
parent | 8728b9da66674488bde07a092040097e46de9366 (diff) |
Library import 250529-1108 (#19003)
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: |