Created
February 14, 2024 18:37
-
-
Save mekkablue/b7686d595a556b930c20ad1e56f75001 to your computer and use it in GitHub Desktop.
Quick script: Check small figures
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
MacroTab.title = "Check small figures" | |
Glyphs.clearLog() | |
Glyphs.showMacroWindow() | |
# please adapt as needed (Glyphs defaults as comments): | |
defaultExtension = ".denominator" # ".dnom" | |
extensions = ( | |
".numerator", # ".numr" | |
"superscript", # "superior" | |
"subscript", # "inferior" | |
) | |
figNames = ( | |
"zero", | |
"one", | |
"two", | |
"three", | |
"four", | |
"five", | |
"six", | |
"seven", | |
"eight", | |
"nine", | |
) | |
font = Glyphs.font | |
print(font.familyName) | |
collectedLayers = [] | |
for m in font.masters: | |
mid = m.id | |
for i, extension in enumerate(extensions): | |
figureGlyphs = [font.glyphs[fig+extension] for fig in figNames] | |
figureLayers = [g.layers[mid] for g in figureGlyphs] | |
defaults = [fig+defaultExtension for fig in figNames] | |
compPositions = [] | |
for j, fig in enumerate(figureLayers): | |
if fig is None: | |
continue | |
default = defaults[j] | |
comp = fig.components[0] | |
if default != comp.componentName: | |
print(f"⚠️ {m.name} {fig.parent.name}: expected {default}, but found {comp.componentName} as component.") | |
compPositions.append(comp.y) | |
allPositions = set(compPositions) | |
somethingWrong = False | |
if len(allPositions) != 1: | |
# consistency: | |
posDict = {} | |
for fig in figureLayers: | |
pos = fig.components[0].y | |
if pos in posDict.keys(): | |
posDict[pos].append(fig.parent.name) | |
else: | |
posDict[pos] = [fig.parent.name] | |
print(f"\n⚠️ {m.name} *{extension}:") | |
for pos in posDict.keys(): | |
glyphNames = posDict[pos] | |
print(f"{pos:12.1f}: {', '.join(glyphNames)}".replace(".0","").replace(extension,"")) | |
somethingWrong = True | |
else: | |
# sanity check on pos: | |
pos = list(allPositions)[0] | |
if i == 2: #subscript | |
if not pos < 0.0: | |
print(f"\n⚠️ {m.name} *{extension}: expected below baseline, but at position {pos}.") | |
somehingWrong = True | |
else: | |
if not pos > 100.0: | |
print(f"\n⚠️ {m.name} *{extension}: expected above 100, but at position {pos}.") | |
somehingWrong = True | |
if somethingWrong: | |
collectedLayers.extend(figureLayers) | |
collectedLayers.append(GSControlLayer.newline()) | |
font.newTab(collectedLayers) | |
print("\n✅ Done.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Glyphs 3.x script for the Macro window.