-
Notifications
You must be signed in to change notification settings - Fork 7
/
Why You Not Compatible.py
87 lines (79 loc) · 3.08 KB
/
Why You Not Compatible.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#MenuTitle: Why You Not Compatible?
# -*- coding: utf-8 -*-
__doc__="""
Finds compatibility issues in the selected glyphs
"""
Font = Glyphs.font
def checkALayer(aLayer):
differences = []
pathCounts = []
anchors = []
paths = []
components = []
for idx, thisLayer in enumerate(aLayer.parent.layers):
pcount = len(thisLayer.paths)
if idx > 0:
if pcount != pathCounts[-1]:
differences.append({"type": "path counts",
"prevLayer": Font.selectedLayers[0].parent.layers[idx-1].name,
"thisLayer": thisLayer.name,
"prevItem": pathCounts[-1],
"thisItem": pcount
})
pathCounts.append(pcount)
if len(differences) == 0: # If path counts differ all bets are off
for pathIdx, path in enumerate(thisLayer.paths):
if idx >0:
if len(path.nodes) != len(paths[idx-1][pathIdx].nodes):
differences.append({"type": "path "+str(1+pathIdx)+", node count",
"prevLayer": Font.selectedLayers[0].parent.layers[idx-1].name,
"thisLayer": thisLayer.name,
"prevItem": len(paths[idx-1][pathIdx].nodes),
"thisItem": len(path.nodes)
})
else:
for nodeIdx, node in enumerate(path.nodes):
prevNode = paths[idx-1][pathIdx].nodes[nodeIdx]
if node.type != prevNode.type:
differences.append({"type": "path "+str(1+pathIdx)+", node "+str(1+nodeIdx)+ " node types",
"prevLayer": Font.selectedLayers[0].parent.layers[idx-1].name,
"thisLayer": thisLayer.name,
"prevItem": prevNode.type,
"thisItem": node.type
})
paths.append(thisLayer.paths)
thisAnchors = set(thisLayer.anchors.keys())
if len(anchors) > 0:
diff = thisAnchors.symmetric_difference(anchors[-1])
if len(diff) > 0:
differences.append({"type": "anchors",
"prevLayer": Font.selectedLayers[0].parent.layers[idx-1].name,
"thisLayer": thisLayer.name,
"thisItem": ", ".join(thisAnchors),
"prevItem": ", ".join(anchors[-1])
})
anchors.append(thisAnchors)
thisComponents = set()
for item in thisLayer.components:
thisComponents.add(item.name)
if len(components) > 0:
diffComp = thisComponents.symmetric_difference(components[-1])
if len(diffComp) > 0:
differences.append({"type": "components",
"prevLayer": Font.selectedLayers[0].parent.layers[idx-1].name,
"thisLayer": thisLayer.name,
"thisItem": ", ".join(thisComponents),
"prevItem": ", ".join(components[-1])
})
components.append(thisComponents)
if len(differences) == 0:
print(thisLayer.parent.name + " is compatible")
else:
print(thisLayer.parent.name + " is not compatible")
for diff in differences:
print(diff["type"]+" differ:")
print(" "+diff["prevLayer"] + " has "+str(diff["prevItem"]))
print(" "+diff["thisLayer"] + " has "+str(diff["thisItem"]))
for aLayer in Font.selectedLayers:
checkALayer(aLayer)
print("\n")