Tie the new prefixed group locating function into the converter.
This commit is contained in:
parent
96757fc6a1
commit
2a026d368f
@ -5,9 +5,9 @@ Conversion functions.
|
||||
# adapted from the UFO spec
|
||||
|
||||
def convertUFO1OrUFO2KerningToUFO3Kerning(kerning, groups):
|
||||
# gather known kerning groups based on the prefixes
|
||||
firstReferencedGroups, secondReferencedGroups = findKnownKerningGroups(groups)
|
||||
# Make lists of groups referenced in kerning pairs.
|
||||
firstReferencedGroups = set()
|
||||
secondReferencedGroups = set()
|
||||
for first, seconds in kerning.items():
|
||||
if first in groups:
|
||||
if not first.startswith("public.kern1."):
|
||||
@ -59,6 +59,12 @@ def convertUFO1OrUFO2KerningToUFO3Kerning(kerning, groups):
|
||||
def findKnownKerningGroups(groups):
|
||||
"""
|
||||
This will find kerning groups with known prefixes.
|
||||
In some cases not all kerning groups will be referenced
|
||||
by the kerning pairs. The algorithm for locating groups
|
||||
in convertUFO1OrUFO2KerningToUFO3Kerning will miss these
|
||||
unreferenced groups. By scanning for known prefixes
|
||||
this function will catch all of the prefixed groups.
|
||||
|
||||
These are the prefixes and sides that are handled:
|
||||
@MMK_L_ - side 1
|
||||
@MMK_R_ - side 2
|
||||
@ -114,6 +120,8 @@ def makeUniqueGroupName(name, groupNames, counter=0):
|
||||
|
||||
def test():
|
||||
"""
|
||||
No known prefixes.
|
||||
|
||||
>>> testKerning = {
|
||||
... "A" : {
|
||||
... "A" : 1,
|
||||
@ -174,6 +182,142 @@ def test():
|
||||
... }
|
||||
>>> groups == expected
|
||||
True
|
||||
|
||||
Known prefixes.
|
||||
|
||||
>>> testKerning = {
|
||||
... "A" : {
|
||||
... "A" : 1,
|
||||
... "B" : 2,
|
||||
... "@MMK_R_CGroup" : 3,
|
||||
... "@MMK_R_DGroup" : 4
|
||||
... },
|
||||
... "@MMK_L_BGroup" : {
|
||||
... "A" : 5,
|
||||
... "B" : 6,
|
||||
... "@MMK_R_CGroup" : 7,
|
||||
... "@MMK_R_DGroup" : 8
|
||||
... },
|
||||
... "@MMK_L_CGroup" : {
|
||||
... "A" : 9,
|
||||
... "B" : 10,
|
||||
... "@MMK_R_CGroup" : 11,
|
||||
... "@MMK_R_DGroup" : 12
|
||||
... },
|
||||
... }
|
||||
>>> testGroups = {
|
||||
... "@MMK_L_BGroup" : ["B"],
|
||||
... "@MMK_L_CGroup" : ["C"],
|
||||
... "@MMK_L_XGroup" : ["X"],
|
||||
... "@MMK_R_CGroup" : ["C"],
|
||||
... "@MMK_R_DGroup" : ["D"],
|
||||
... "@MMK_R_XGroup" : ["X"],
|
||||
... }
|
||||
>>> kerning, groups, maps = convertUFO1OrUFO2KerningToUFO3Kerning(
|
||||
... testKerning, testGroups)
|
||||
>>> expected = {
|
||||
... "A" : {
|
||||
... "A": 1,
|
||||
... "B": 2,
|
||||
... "public.kern2.@MMK_R_CGroup": 3,
|
||||
... "public.kern2.@MMK_R_DGroup": 4
|
||||
... },
|
||||
... "public.kern1.@MMK_L_BGroup": {
|
||||
... "A": 5,
|
||||
... "B": 6,
|
||||
... "public.kern2.@MMK_R_CGroup": 7,
|
||||
... "public.kern2.@MMK_R_DGroup": 8
|
||||
... },
|
||||
... "public.kern1.@MMK_L_CGroup": {
|
||||
... "A": 9,
|
||||
... "B": 10,
|
||||
... "public.kern2.@MMK_R_CGroup": 11,
|
||||
... "public.kern2.@MMK_R_DGroup": 12
|
||||
... }
|
||||
... }
|
||||
>>> kerning == expected
|
||||
True
|
||||
>>> expected = {
|
||||
... "@MMK_L_BGroup": ["B"],
|
||||
... "@MMK_L_CGroup": ["C"],
|
||||
... "@MMK_L_XGroup": ["X"],
|
||||
... "@MMK_R_CGroup": ["C"],
|
||||
... "@MMK_R_DGroup": ["D"],
|
||||
... "@MMK_R_XGroup": ["X"],
|
||||
... "public.kern1.@MMK_L_BGroup": ["B"],
|
||||
... "public.kern1.@MMK_L_CGroup": ["C"],
|
||||
... "public.kern1.@MMK_L_XGroup": ["X"],
|
||||
... "public.kern2.@MMK_R_CGroup": ["C"],
|
||||
... "public.kern2.@MMK_R_DGroup": ["D"],
|
||||
... "public.kern2.@MMK_R_XGroup": ["X"],
|
||||
... }
|
||||
>>> groups == expected
|
||||
True
|
||||
|
||||
Mixture of known prefixes and groups without prefixes.
|
||||
|
||||
>>> testKerning = {
|
||||
... "A" : {
|
||||
... "A" : 1,
|
||||
... "B" : 2,
|
||||
... "@MMK_R_CGroup" : 3,
|
||||
... "DGroup" : 4
|
||||
... },
|
||||
... "BGroup" : {
|
||||
... "A" : 5,
|
||||
... "B" : 6,
|
||||
... "@MMK_R_CGroup" : 7,
|
||||
... "DGroup" : 8
|
||||
... },
|
||||
... "@MMK_L_CGroup" : {
|
||||
... "A" : 9,
|
||||
... "B" : 10,
|
||||
... "@MMK_R_CGroup" : 11,
|
||||
... "DGroup" : 12
|
||||
... },
|
||||
... }
|
||||
>>> testGroups = {
|
||||
... "BGroup" : ["B"],
|
||||
... "@MMK_L_CGroup" : ["C"],
|
||||
... "@MMK_R_CGroup" : ["C"],
|
||||
... "DGroup" : ["D"],
|
||||
... }
|
||||
>>> kerning, groups, maps = convertUFO1OrUFO2KerningToUFO3Kerning(
|
||||
... testKerning, testGroups)
|
||||
>>> expected = {
|
||||
... "A" : {
|
||||
... "A": 1,
|
||||
... "B": 2,
|
||||
... "public.kern2.@MMK_R_CGroup": 3,
|
||||
... "public.kern2.DGroup": 4
|
||||
... },
|
||||
... "public.kern1.BGroup": {
|
||||
... "A": 5,
|
||||
... "B": 6,
|
||||
... "public.kern2.@MMK_R_CGroup": 7,
|
||||
... "public.kern2.DGroup": 8
|
||||
... },
|
||||
... "public.kern1.@MMK_L_CGroup": {
|
||||
... "A": 9,
|
||||
... "B": 10,
|
||||
... "public.kern2.@MMK_R_CGroup": 11,
|
||||
... "public.kern2.DGroup": 12
|
||||
... }
|
||||
... }
|
||||
>>> kerning == expected
|
||||
True
|
||||
>>> expected = {
|
||||
... "BGroup": ["B"],
|
||||
... "@MMK_L_CGroup": ["C"],
|
||||
... "@MMK_R_CGroup": ["C"],
|
||||
... "DGroup": ["D"],
|
||||
... "public.kern1.BGroup": ["B"],
|
||||
... "public.kern1.@MMK_L_CGroup": ["C"],
|
||||
... "public.kern2.@MMK_R_CGroup": ["C"],
|
||||
... "public.kern2.DGroup": ["D"],
|
||||
... }
|
||||
>>> groups == expected
|
||||
True
|
||||
"""
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
x
Reference in New Issue
Block a user