-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKerning Group Controller for GL2X.py.orig
262 lines (217 loc) · 10.8 KB
/
Kerning Group Controller for GL2X.py.orig
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#MenuTitle: Kerning Groups Controller 0.1 for GL2.3+
#encoding: utf-8
"""
KerningGroupsController-forGL2.3.py
Created by Alexandr Hudeček on 2017-05-17.
Copyright (c) 2017 odoka.cz. All rights reserved.
"""
import vanilla
import os
thisFont = Glyphs.font
# builing a more accessible kerning dictionary
# it's a dictionary of lists. newKernDic[master.id][left, right, value]
kernDic = thisFont.kerningDict()
newKernDic = {}
for thisMaster in thisFont.masters:
kernList = []
for key1 in kernDic[thisMaster.id]:
for key2 in kernDic[thisMaster.id][key1]:
pairInList = [key1, key2, kernDic[thisMaster.id][key1][key2]]
kernList.append(pairInList)
newKernDic[thisMaster.id] = kernList
# building popup list
# each value contains a list of glyphs involved. groupsL/R[groupName][glyph, glyph, glyph...]
groupsL = {}
groupsR = {}
for thisGlyph in thisFont.glyphs:
if thisGlyph.leftKerningGroup != None:
if not thisGlyph.leftKerningGroup in groupsL:
groupsL[thisGlyph.leftKerningGroup] = []
groupsL[thisGlyph.leftKerningGroup].append(thisGlyph.name)
if thisGlyph.rightKerningGroup != None:
if not thisGlyph.rightKerningGroup in groupsR:
groupsR[thisGlyph.rightKerningGroup] = []
groupsR[thisGlyph.rightKerningGroup].append(thisGlyph.name)
class AppController:
#WINDOW SETTINGS
editX = 180
editY = 22
textY = 17
spaceX = 10
spaceY = 20
windowWidth = spaceX*3+editX*1.5
windowHeight = 405
popupAdjust = 3
#properties
selectedGroupGlyphs = []
selectedGroupName = ""
if groupsL:
selectedGroupName = sorted(groupsL)[0]
def refreshSelectedGroupGlyphs(self, group):
self.selectedGroupGlyphs = []
for glyphName in group[self.selectedGroupName]:
self.selectedGroupGlyphs.append(glyphName)
# print glyphName,' '
#init opens the window
def __init__(self):
if groupsL:
self.refreshSelectedGroupGlyphs(groupsL)
self.w = self.getWindow()
self.w.open()
pass
def getWindow(self):
#open window
w = vanilla.FloatingWindow(
( self.windowWidth, self.windowHeight ), # default window size
"Kerning Groups Controller", # window title
minSize = ( self.windowWidth, self.windowHeight ), # minimum size (for resizing)
maxSize = ( self.windowWidth + 540, self.windowHeight + 140), # maximum size (for resizing)
autosaveName = "com.OdOka.KerningGroupsController.mainwindow" # stores last window position and size
)
#UI
height = self.spaceY
w.text0 = vanilla.TextBox( (self.spaceX, height, 120, self.textY), "Group", sizeStyle='regular' )
w.radio = vanilla.RadioGroup( (self.spaceX+130, height, 120, self.textY), ["Left", "Right"], isVertical = False, sizeStyle='regular', callback=self.switchList)
w.radio.set(0)
height += self.spaceY+self.textY
w.text1 = vanilla.TextBox( (self.spaceX, height, 120, self.textY), "Choose Group", sizeStyle='regular' )
w.popupGroup = vanilla.PopUpButton( (self.spaceX+130, height-self.popupAdjust, -15, self.editY), [str(x) for x in sorted(groupsL)], sizeStyle='regular', callback=self.adjustGlyphsList)
height += self.spaceY+self.textY
w.text2 = vanilla.TextBox( (self.spaceX, height, 120, self.textY), "Choose glyph", sizeStyle='regular' )
w.workWithGlyphs = vanilla.EditText( (self.spaceX + 130, height, -15, self.editY), "", sizeStyle = 'regular' )
#w.popupGlyph = vanilla.PopUpButton( (self.spaceX+130, height-self.popupAdjust, -10, self.editY), [str(x) for x in sorted(self.selectedGroupGlyphs)], sizeStyle='regular' )
height += self.spaceY+self.textY
w.textGM = vanilla.TextBox( (self.spaceX, height, 120, self.textY), "Glyphs in group", sizeStyle='small' )
glyphsInGroupHelper = "No groups. No glyphs."
if self.selectedGroupName <> "":
glyphsInGroupHelper = ','.join(sorted(self.selectedGroupGlyphs))
<<<<<<< HEAD
w.textG = vanilla.TextBox( (self.spaceX+130, height, -15, -15),glyphsInGroupHelper , sizeStyle='small' )
=======
w.textG = vanilla.TextBox( (self.spaceX+130, height, -15, -15), glyphsInGroupHelper, sizeStyle='small' )
>>>>>>> dev
height += self.spaceY+self.textY*2 + self.spaceY
w.text3 = vanilla.TextBox( (self.spaceX, height, 120, self.textY), "What to do", sizeStyle='regular' )
w.radioOptions = vanilla.RadioGroup( (self.spaceX+130, height, 150, self.textY*5), ["copy kerning values","relative change in %","absolute change","do not kern"], isVertical = True, sizeStyle='regular')
w.radioOptions.set(0)
height += self.textY*5 + self.editY/2
w.text4 = vanilla.TextBox( (self.spaceX+130, height, 40, self.textY), "Value", sizeStyle='regular' )
w.value = vanilla.EditText( (self.spaceX+165+self.spaceX, height, 40, self.editY), "", sizeStyle = 'regular' )
height += self.spaceY+self.editY
w.text5 = vanilla.TextBox( (self.spaceX, height, 120, self.textY), "Assign new group", sizeStyle='regular' )
w.assignNewGroup = vanilla.EditText( (self.spaceX + 130, height, -15, self.editY), "", sizeStyle = 'regular' )
#w.popupAssign = vanilla.PopUpButton( (self.spaceX+130, height-self.popupAdjust, -10, self.editY), [str(x) for x in sorted(groupsL)], sizeStyle='regular' )
height += self.spaceY+self.textY
#w.textEG = vanilla.TextBox( (self.spaceX, height, 120, self.textY), "Existing groups", sizeStyle='small' )
#w.textEGL = vanilla.TextBox( (self.spaceX+130, height, -15, -15), ','.join(sorted(groupsL)), sizeStyle='small' )
#height += self.spaceY+self.textY*2 + self.spaceY
w.text6 = vanilla.TextBox((self.spaceX, height, 80, 20), "Apply to:", sizeStyle = 'regular')
w.radioApplyTo = vanilla.RadioGroup((self.spaceX+130, height, -15, 40), [ "To current font only", "To all open fonts" ], sizeStyle = 'regular' )
w.radioApplyTo.set(0)
# w.checkBoxRenameIndividualGlyphs = vanilla.CheckBox((80, height, -15, 19), "Rename individual glyphs", value=False, sizeStyle = 'regular')
# w.textOptions = vanilla.TextBox((15, height, 80, 20), "Remove:", sizeStyle = 'regular')
w.buttonProcess = vanilla.Button((-15 - 80, -15 - 20, -15, -15), "Go", sizeStyle = 'regular', callback=self.process)
w.setDefaultButton(w.buttonProcess)
w.spinner = vanilla.ProgressSpinner((15, -15 - 16, 16, 16), sizeStyle = 'regular')
return w
#def updateWindow(self, sender):
# self.w.textEditGlyphsNames._nsObject.setEditable_(self.w.checkBoxDeleteGlyphs.get())
def getSettings(self):
out = {
#"input": self.w.radioInput.get(),
"options": {
# "UpdateGlyphInfo": self.w.checkBoxUpdateGlyphInfo.get(),
# "RemoveGlyphOrder": self.w.checkBoxRemoveGlyphOrder.get(),
# "RemoveAllCustomParameters": self.w.checkBoxRemoveAllCustomParameters.get(),
# "RemoveAllMastersCustomParameters": self.w.checkBoxRemoveAllMastersCustomParameters.get(),
# "AddSuffixesToLigatures": self.w.checkBoxAddSuffixesToLigatures.get(),
# "RenameSuffixes": self.w.checkBoxRenameSuffixes.get(),
# "RenameIndividualGlyphs": self.w.checkBoxRenameIndividualGlyphs.get(),
# "RemoveAllFeatures": self.w.checkBoxRemoveAllFeatures.get(),
# "RemovePUA": self.w.checkBoxRemovePUA.get(),
# "DeleteUnnecessaryGlyphs": self.w.checkBoxDeleteUnnecessaryGlyphs.get()
}
}
return out
def switchList(self, sender):
index = 0
try:
if self.w.radio.get() == 0:
if groupsL:
self.w.popupGroup.setItems(sorted(groupsL))
self.selectedGroupName = sorted(groupsL)[index]
self.refreshSelectedGroupGlyphs(groupsL)
self.w.textG.set(','.join(sorted(self.selectedGroupGlyphs)))
else:
self.w.popupGroup.setItems([])
self.selectedGroupName = ""
self.w.textG.set("No group, No glyphs.")
elif self.w.radio.get() == 1:
if groupsR:
self.w.popupGroup.setItems(sorted(groupsR))
self.selectedGroupName = sorted(groupsR)[index]
self.refreshSelectedGroupGlyphs(groupsR)
self.w.textG.set(','.join(sorted(self.selectedGroupGlyphs)))
else:
self.w.popupGroup.setItems([])
self.selectedGroupName = ""
self.w.textG.set("No group, No glyphs.")
except Exception, e:
print "Kerning Group Controller Error (switchList): %s" % e
def adjustGlyphsList(self, sender):
index = self.w.popupGroup.get()
try:
if self.w.radio.get() == 0:
self.selectedGroupName = sorted(groupsL)[index]
self.refreshSelectedGroupGlyphs(groupsL)
self.w.textG.set(','.join(sorted(self.selectedGroupGlyphs)))
elif self.w.radio.get() == 1:
self.selectedGroupName = sorted(groupsR)[index]
self.refreshSelectedGroupGlyphs(groupsR)
self.w.textG.set(','.join(sorted(self.selectedGroupGlyphs)))
except Exception, e:
print "Kerning Group Controller Error (switchList): %s" % e
def process(self, sender):
self.w.spinner.start()
worker = AppWorker()
worker.start(self.getSettings())
self.w.spinner.stop()
self.displayLog(worker.getLog())
def displayLog(self, s):
log = vanilla.FloatingWindow((360, 480), 'Log')
log.textEditor = vanilla.TextEditor((0, 0, -1, -1))
log.textEditor.set(s)
log.open()
class AppWorker:
def __init__(self):
pass
def printLog(self, message, addLine):
self.outputLog += message + '\n'
if addLine == True:
self.outputLog += '\n'
print message + '\n'
else:
print message
def get_all_font_names(self):
self.allGlyphsNames = []
for glyph in self.font.glyphs:
self.allGlyphsNames.append(glyph.name)
return True
def processFont(self, font, onlySelected, options):
message = '# Proccesing font: ' + self.font.familyName + ' (contains %s glyphs)' % self.glyphs_total
messlength = len(message)
self.printLog(message, False)
message = '-' * messlength
self.printLog(message, True)
Glyphs.redraw()
return True
def start(self, settings):
self.outputLog = ''
self.printLog('==== Starting ====',False)
self.printLog('===== Done. =====',False)
def log(self, s):
self.outputLog += s + '\n'
def getLog(self):
return self.outputLog
# Script start
app = AppController()