Last active
March 15, 2020 21:39
-
-
Save agyeiarcher/f327cea156bcc4625e04b0e086274c4f to your computer and use it in GitHub Desktop.
A robofont script that filters through a folder of font masters for minimum and maximum grade(labelled "MinGrade" and "MaxGrade" but that can get variable-assigned), and does the math and matching to equate the glyph widths (this assumes equal advance weights and only addresses potential spacing problems)
This file contains 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
def makePairs(path, stylename, maxVal, minVal): | |
separatemasters(path, maxVal, minVal) | |
listName = [] | |
for f in maxFonts: | |
if stylename in f: | |
listName.append(f) | |
for m in minFonts: | |
if stylename in m: | |
listName.append(m) | |
return(list(dict.fromkeys(listName))) #list(dict.fromkeys(x)) is a good way to get a list with stripped duplicates | |
def matchWidths(folderPath): | |
for style in baseStyles: | |
thisPair = (makePairs(folderPath, style, "MaxGrade", "MinGrade")) | |
maxMaster = OpenFont(thisPair[0], showInterface = False) | |
minMaster = OpenFont(thisPair[1], showInterface = False) | |
for glyphName in maxMaster.keys(): | |
if maxMaster[glyphName]: | |
maxMaster[glyphName].leftMargin=int(maxMaster[glyphName].leftMargin) | |
maxMaster[glyphName].rightMargin=int(maxMaster[glyphName].rightMargin) | |
widthDiff=maxMaster[glyphName].width-minMaster[glyphName].width | |
minMaster[glyphName].leftMargin+=int(widthDiff/2) | |
minMaster[glyphName].rightMargin+=int(widthDiff/2) | |
if minMaster[glyphName].width > maxMaster[glyphName].width: | |
minMaster[glyphName].rightMargin += -1 | |
if maxMaster[glyphName].width > minMaster[glyphName].width: | |
maxMaster[glyphName].rightMargin += -1 | |
maxMaster.save(folderPath + maxMaster.info.familyName + " " + maxMaster.info.styleName + ".ufo") | |
minMaster.save(folderPath + minMaster.info.familyName + " " + minMaster.info.styleName + ".ufo") | |
# print(f"Min Master ---> left margin: {minMaster[glyph].leftMargin} | right margin: {minMaster[glyph].rightMargin} | width: {minMaster[glyph].width}") | |
# print(f"Max Master ---> left margin: {maxMaster[glyph].leftMargin} | right margin: {maxMaster[glyph].rightMargin} | width: {maxMaster[glyph].width}") | |
matchWidths("folder path/") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment