Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
("public.kern1.aswap", "x"): 20,
("a", "y"): 40,
("a.swap", "y"): 30,
("y", "a"): 60,
("y", "a.swap"): 50,
}
# Test swapped group membership.
assert ufo.groups == {
"public.kern1.a": ["a.swap"],
"public.kern1.aswap": ["a"],
"public.kern2.a": ["a.swap", "a"],
}
# Swap a second time.
fontmake.instantiator.swap_glyph_names(ufo, "aaa", "aaa.swap")
# Test swapped glyphs.
assert sorted(c.baseGlyph for c in ufo["aaa"].components) == ["a", "a", "y"]
assert sorted(c.baseGlyph for c in ufo["aaa.swap"].components) == [
"a.swap",
"a.swap",
"x",
]
# Test for no leftover temporary glyphs.
assert {g.name for g in ufo} == {
"space",
"a",
"a.swap",
"aaa",
"aaa.swap",
def test_swap_glyph_names_spec(data_dir):
"""Test that the rule example in the designspaceLib spec works.
`adieresis` should look the same as before the rule application.
[1]: https://github.com/fonttools/fonttools/tree/master/Doc/source/designspaceLib#ufo-instances
"""
ufo = ufoLib2.Font.open(data_dir / "SwapGlyphNames" / "B.ufo")
fontmake.instantiator.swap_glyph_names(ufo, "a", "a.alt")
assert sorted(c.baseGlyph for c in ufo["adieresis"].components) == [
"a.alt",
"dieresiscomb",
]
assert sorted(c.baseGlyph for c in ufo["adieresis.alt"].components) == [
"a",
"dieresiscomb",
]
def test_swap_glyph_names(data_dir):
ufo = ufoLib2.Font.open(data_dir / "SwapGlyphNames" / "A.ufo")
fontmake.instantiator.swap_glyph_names(ufo, "a", "a.swap")
# Test swapped outlines.
assert ufo["a"].unicode == 0x61
assert len(ufo["a"]) == 1
assert len(ufo["a"].contours[0]) == 8
assert ufo["a"].width == 666
assert ufo["a.swap"].unicode is None
assert len(ufo["a.swap"]) == 1
assert len(ufo["a.swap"].contours[0]) == 4
assert ufo["a.swap"].width == 600
# Test swapped components.
assert sorted(c.baseGlyph for c in ufo["aaa"].components) == [
"a.swap",
"a.swap",
"x",
"x",
]
# Test for no leftover temporary glyphs.
assert {g.name for g in ufo} == {
"space",
"a",
"a.swap",
"aaa",
"aaa.swap",
"x",
"y",
}
with pytest.raises(fontmake.instantiator.InstantiatorError, match="Cannot swap"):
fontmake.instantiator.swap_glyph_names(ufo, "aaa", "aaa.swapa")