Skip to content

Instantly share code, notes, and snippets.

@okay-type
Last active November 30, 2015 20:38
Show Gist options
  • Save okay-type/39594d9533ecb62beaf2 to your computer and use it in GitHub Desktop.
Save okay-type/39594d9533ecb62beaf2 to your computer and use it in GitHub Desktop.
+version
# jackson
# okaytype.com
# v0.3 28 Nov 15
# uses Version Minor to increment font names i.e.:
# Family Name v1
from vanilla import *
import os
from robofab.interface.all.dialogs import GetFolder
class UpVersion():
def __init__(self):
# create a window
self.w = Window((250, 200), "UpVersion")
L = 20
W = -20
T = 10
H = 30
# create button
self.w.b = Button((L, T, W, H), 'Save New Versions', callback=self.UpVersionCallback)
# create check boxes
self.w.eb = EditText((L, T+40, W, H-5), self.editTextGet(), callback=self.editTextCallback)
self.w.c1 = CheckBox((L, T+70, W, H), "Delete Mark Colors", callback=self.cb1Callback, value=False)
self.w.c2 = CheckBox((L, T+90, W, H), "Delete Layers", callback=self.cb2Callback, value=True)
self.w.c3 = CheckBox((L, T+110, W, H), "Delete Guides", callback=self.cb3Callback, value=False)
# open the window
self.w.open()
def editTextGet(self):
f = CurrentFont()
if f:
return str(f.info.versionMinor+1)
else:
return '0'
def editTextCallback(self, sender):
return
def cb1Callback(self, sender):
return
def cb2Callback(self, sender):
return
def cb3Callback(self, sender):
return
def UpVersionCallback(self, sender):
# get the value from the box
print 'test UpVersionCallback'
if self.w.c1.get() == 1:
self.RemoveMarks()
if self.w.c2.get() == 1:
self.RemoveLayers()
if self.w.c3.get() == 1:
self.RemoveGuides()
self.NewVersion(int(self.w.eb.get()))
print ''
def RemoveMarks(self):
for font in AllFonts():
for glyph in font:
glyph.mark = None
def RemoveLayers(self): # repeate a few times since it was occassionally missing layers and I'm lazy
for font in AllFonts():
for layer in font.layerOrder:
font.removeLayer(layer)
for layer in font.layerOrder:
font.removeLayer(layer)
for layer in font.layerOrder:
font.removeLayer(layer)
def RemoveGuides(self):
for font in AllFonts():
for guide in font.guides:
font.removeGuide(guide)
for g in font:
for guide in g.guides:
g.removeGuide(guide)
def NewVersion(self, revisionnumber):
for font in AllFonts():
# add 'v#' to font family name
familyname = font.info.familyName.replace(" v"+str(font.info.versionMinor), "")
fontname = familyname + " v" + str(revisionnumber)
font.info.versionMinor = int(revisionnumber)
font.info.versionMajor = 0
font.info.familyName = fontname
# update style map name, removing ' Italic' for style linking
font.info.styleMapFamilyName = font.info.familyName + ' ' + font.info.styleName.replace(' Italic', '')
# clean up naming, this should be a check option in the future
font.info.postscriptFontName = None
font.info.postscriptFullName = None
font.info.postscriptWeightName = None
font.info.openTypeNamePreferredFamilyName = None
font.info.openTypeNamePreferredSubfamilyName = None
font.info.openTypeNameCompatibleFullName = None
font.info.macintoshFONDName = None
# truncate file name parts
fileName = os.path.basename(font.path)
pathName = font.path.split(fileName)
shortfamilyname = font.info.familyName.replace(" v"+str(font.info.versionMinor), "")[:12]+"-v"+str(revisionnumber)
if "Italic" in font.info.styleName:
shortstylename = font.info.styleName.replace('Italic', '')
shortstylename = shortstylename[:11]
shortstylename = shortstylename+'Itlc'
else:
shortstylename = font.info.styleName[:11]
# save new file
newfName = shortfamilyname+"-"+shortstylename+"."+fileName.split(".")[1]
newfName = newfName.replace(" ", "")
newPath = os.path.join(pathName[0]+newfName)
font.save(newPath)
UpVersion()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment