Created
July 27, 2019 17:58
-
-
Save mekkablue/99987959971f8cf8562c028997375ac8 to your computer and use it in GitHub Desktop.
Export Spacing/Kerning CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#MenuTitle: Export Kerning Info CSV | |
# -*- coding: utf-8 -*- | |
__doc__=""" | |
Export a CSV containing kerning info. | |
""" | |
import commands | |
from types import * | |
Font = Glyphs.font | |
selectedLayers = Font.selectedLayers | |
filename = Font.familyName + ' kerning' # filename without ending | |
ending = 'csv' # txt|csv | |
myDelim = ";" # use "\t" for tab | |
myExportString = "" | |
def saveFileDialog(message=None, ProposedFileName=None, filetypes=None): | |
if filetypes is None: | |
filetypes = [] | |
Panel = NSSavePanel.savePanel().retain() | |
if message is not None: | |
Panel.setTitle_(message) | |
Panel.setCanChooseFiles_(True) | |
Panel.setCanChooseDirectories_(False) | |
Panel.setAllowedFileTypes_(filetypes) | |
if ProposedFileName is not None: | |
Panel.setNameFieldStringValue_(ProposedFileName) | |
pressedButton = Panel.runModalForTypes_(filetypes) | |
if pressedButton == 1: # 1=OK, 0=Cancel | |
return Panel.filename() | |
return None | |
for m in Font.masters: | |
masterID = m.id | |
masterName = m.name | |
print "Gathering kerning info for Master", masterName | |
for L in Font.kerning[ masterID ]: | |
if L[0] == "@": | |
nameL = "@" + L[7:] | |
else: | |
nameL = Font.glyphForId_(L).name | |
for R in Font.kerning[masterID][L]: | |
if R[0] == "@": | |
nameR = "@" + R[7:] | |
else: | |
nameR = Font.glyphForId_(R).name | |
myKerningPair = [ masterName, nameL, nameR, str(Font.kerning[masterID][L][R]) ] | |
myExportString = myExportString + ( myDelim.join( myKerningPair ) + '\n' ) | |
filepath = saveFileDialog( message="Export Kerning CSV", ProposedFileName=filename, filetypes=["csv","txt"] ) | |
f = open( filepath, 'w' ) | |
print "Exporting to:", f.name | |
f.write( myExportString ) | |
f.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#MenuTitle: Export Glyph Info CSV | |
# -*- coding: utf-8 -*- | |
__doc__=""" | |
Export a CSV containing info about the glyphs. | |
""" | |
import commands | |
from types import * | |
Font = Glyphs.font | |
selectedLayers = Font.selectedLayers | |
filename = Font.familyName + ' metrics' # filename without ending | |
ending = 'csv' # txt|csv | |
myDelim = ";" # use "\t" for tab | |
myExportString = "" | |
def saveFileDialog(message=None, ProposedFileName=None, filetypes=None): | |
if filetypes is None: | |
filetypes = [] | |
Panel = NSSavePanel.savePanel().retain() | |
if message is not None: | |
Panel.setTitle_(message) | |
Panel.setCanChooseFiles_(True) | |
Panel.setCanChooseDirectories_(False) | |
Panel.setAllowedFileTypes_(filetypes) | |
if ProposedFileName is not None: | |
Panel.setNameFieldStringValue_(ProposedFileName) | |
pressedButton = Panel.runModalForTypes_(filetypes) | |
if pressedButton == 1: # 1=OK, 0=Cancel | |
return Panel.filename() | |
return None | |
def process( thisLayer ): | |
try: | |
LKG = str( "@" + thisLayer.parent.leftKerningGroup ) | |
except TypeError: | |
LKG = "" | |
try: | |
RKG = str( "@" + thisLayer.parent.rightKerningGroup ) | |
except TypeError: | |
RKG = "" | |
myExportList = [ | |
str( thisLayer.parent.name ), | |
str( thisLayer.name ), | |
LKG, | |
RKG, | |
str( thisLayer.LSB ), | |
str( thisLayer.RSB ), | |
str( thisLayer.width ) | |
] | |
return myExportList | |
for thisLayer in selectedLayers: | |
print "Processing", thisLayer.parent.name | |
myExportString = myExportString + ( myDelim.join( process( thisLayer ) ) + '\n' ) | |
filepath = saveFileDialog( message="Export Metrics CSV", ProposedFileName=filename, filetypes=["csv","txt"] ) | |
f = open( filepath, 'w' ) | |
print "Exporting to:", f.name | |
f.write( "Glyph;Weight;LKG;RKG;LSB;RSB;Width\n" + myExportString ) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment