-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSuperaligner.py
More file actions
32 lines (29 loc) · 1.23 KB
/
Superaligner.py
File metadata and controls
32 lines (29 loc) · 1.23 KB
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
# MenuTitle: SuperAligner
# -*- coding: utf-8 -*-
def align_path(reference, target_path):
# Try to align the paths by type
test = [n.type for n in target_path.nodes]
if reference == test:
return True
shifts = 0
while shifts < len(test) and reference != test:
test = test[-1:] + test[:-1]
shifts += 1
if reference == test:
target_path.nodes = target_path.nodes[-shifts:] + target_path.nodes[:-shifts]
return True
return False
layers = [ l for l in Glyphs.font.selectedLayers[0].parent.layers if l.associatedMasterId == l.layerId ]
for path_index in range(len(layers[0].paths)):
reference = [n.type for n in layers[0].paths[path_index].nodes]
for target_layer in layers[1:]:
target_path = target_layer.paths[path_index]
if len(target_path.nodes) != len(reference):
print('Different number of nodes in path %d' % path_index)
continue
if not align_path(reference, target_path):
print('Could not align path %d, reversing' % path_index)
target_path.reverse()
if not align_path(reference, target_path):
print('Could not align path %d' % path_index)
continue