-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathremove-list-of-glyphs.py
95 lines (67 loc) · 2.8 KB
/
remove-list-of-glyphs.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
import os
from mojo.UI import AskString
from vanilla.dialogs import *
# copy-paste to fill this list with whatever glyphs fontMake flags as not being interpolatable
# glyphsToDelete = ['LISTOFGLYPHSHERE']
glyphsToRemove = AskString(
'Input glyphnames to remove, then select UFOs').replace("'", "").replace(",", "").split(" ")
# help(CurrentFont().removeGlyph())
instruction = f"select masters to remove {glyphsToRemove} from"
inputFonts = getFile(
instruction, allowsMultipleSelection=True, fileTypes=["ufo"])
# copy space-separated glyph names here
# glyphsToRemove = list(f.selectedGlyphNames)
def removeGlyphs(glyphsToRemove,f):
# LAYERS --------------------------------------------------
for layerName in f.layerOrder:
layer = f.getLayer(layerName)
for glyphToRemove in glyphsToRemove:
if glyphToRemove in layer:
del layer[glyphToRemove]
# else:
# print("%s does not contain a glyph named '%s'" %
# (layerName, glyphToRemove))
# GLYPH ORDER ---------------------------------------------
glyphOrder = f.glyphOrder
for glyphName in glyphsToRemove:
if glyphName in glyphOrder:
glyphOrder.remove(glyphName)
f.glyphOrder = glyphOrder
# KERNING -----------------------------------------------------------
for glyphName in glyphsToRemove:
# iterate over all kerning pairs in the font
for kerningPair in f.kerning.keys():
# if glyph is in the kerning pair, remove it
if glyphName in kerningPair:
print('removing kerning pair (%s, %s)...' % kerningPair)
del f.kerning[kerningPair]
# COMPONENTS -------------------------------------------------------
# iterate over all glyphs in the font
for glyph in f:
# skip glyphs which components
if not glyph.components:
continue
# iterate over all components in glyph
for component in glyph.components:
# if the base glyph is the glyph to be removed
if component.baseGlyph in glyphsToRemove:
# delete the component
glyph.removeComponent(component)
# FONT KEYs -----------------------------------------------
# clean up the rest of the data
for glyphName in glyphsToRemove:
print(glyphName)
# remove from keys
#if glyphName in f:
if glyphName in f.keys():
del f[glyphName]
else:
print("font does not contain a glyph named '%s'" % glyphName)
# clearing this list so it's not saved...
glyphsToRemove = []
for fontPath in inputFonts:
f = OpenFont(fontPath, showInterface=False)
removeGlyphs(glyphsToRemove, f)
print("done!")
f.save()
f.close()