-
Notifications
You must be signed in to change notification settings - Fork 5
/
Generate-substitutions.py
33 lines (30 loc) · 1.04 KB
/
Generate-substitutions.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
# FontLab script to generate OpenType feature substitution code for selected glyphs
# works with simple ligatures and alternates.
# Does not attempt to decode multiple-feature glyphs such as "f_f_i.alt"
# as there is no single clear right input set for that
#
# by Thomas Phinney, open source under Apache 2.0 license
f = fl.font
if f == None:
exit
# function to call for each glyph...
# it takes two arguments
def printCode(g):
if g == None:
return
# take the part of the glyph name before the period:
dropDot = g.name.split(".")[0]
# separate ligature components:
ligSplit = dropDot.replace("_"," ")
# if neither of these substitutions did anything, exit function and don't print the replacement code
if ligSplit == g.name :
return
# hey, let's print the glyph replacement code now!
print " sub", ligSplit, "by", g.name , ";"
# This is the actual program (using the function above)
font = fl.font
glyphs = font.glyphs
# for every glyph in the font
for index in range(len(glyphs)):
if fl.Selected(index):
printCode(glyphs[index])