-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathomCreateAxisLocations.py
executable file
·118 lines (100 loc) · 2.12 KB
/
omCreateAxisLocations.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#MenuTitle: Create Axis Locations
# -*- coding: utf-8 -*-
# Code by Olli Meier, February 2022
__doc__="""
Add Axis Locations to Masters and Instances.
"""
from GlyphsApp import *
from GlyphsApp import objcObject
axis_location_dict = {
'wght': {
130: 300,
176: 400,
230: 500,
270: 600,
310: 700,
},
'ital': {
0: 0,
1: 14,
},
'XTDR': {
0: 0,
30: 30,
},
'INKT': {
0: 0,
1: 1,
},
'APRT': {
0: 0,
100: 100,
},
'SPAC': {
0: 0,
40: 40,
60: 60,
},
'SS01': {
0: 0,
1: 1,
},
'SS02': {
0: 0,
1: 1,
},
'SS03': {
0: 0,
1: 1,
},
}
def create_CP(obj, param, value, overwrite=False):
'''
create custom parameter:
param: 'Axis Location'
value: Content
obj: font, master or instance
'''
if obj.customParameters[param]:
if overwrite:
obj.customParameters[param] = value
print(f"{obj.name}: overwrote CustomParameter '{param}'.")
else:
print(f"{obj.name}: CustomParameter '{param}'' exists already, won't do anything.")
else:
obj.customParameters[param] = value
print(f"New CustomParameter '{param}'' created.")
def create_axis_location(obj):
'''
obj: master or instance.
'''
values = []
for ax_i, ax in enumerate(obj.axes):
v = obj.axes[ax_i]
if v in axis_location_dict[ax.axisTag]:
location_value = axis_location_dict[ax.axisTag][v]
values.append({"Axis": ax.name, "Location": location_value})
else:
print(f'Error: Could not find {v} in in given axis_location_dict. Please check: {obj.name}')
values = None
break
print('values: ', values)
if values is not None:
create_CP(obj, objcObject('Axis Location'), objcObject(values), overwrite=True)
def create_axis_locations(font_obj, axis_location_dict=axis_location_dict):
for obj in font_obj.masters:
m = font_obj.masters[obj.id]
create_axis_location(m)
for obj in font_obj.instances:
create_axis_location(obj)
def get_axis_location_dict():
'''
TODO: automation.
'''
return axis_location_dict
def main():
axis_location_dict = get_axis_location_dict()
for font_obj in Glyphs.fonts:
create_axis_locations(font_obj, axis_location_dict=axis_location_dict)
if __name__ == '__main__':
main()