Skip to content

Instantly share code, notes, and snippets.

@mekkablue
Created February 14, 2024 18:34
Show Gist options
  • Save mekkablue/a17e9c3c5b81fa0a4456b28d652923c5 to your computer and use it in GitHub Desktop.
Save mekkablue/a17e9c3c5b81fa0a4456b28d652923c5 to your computer and use it in GitHub Desktop.
Quick script: Align ĦŁł...
MacroTab.title = "Align ĦŁł..."
glyphsToAlign = (
"Hbar",
"Lslash",
"lslash",
# add more glyph names here
)
Glyphs.clearLog()
Glyphs.showMacroWindow()
font = Glyphs.font
print(font.familyName)
for m in font.masters:
for glyphName in glyphsToAlign:
g = font.glyphs[glyphName]
l = g.layers[m.id]
if not l.components:
print(f"⚠️ {m.name}: no components in {glyphName}.")
continue
firstComp = l.components[0]
compWidth = firstComp.componentLayer.width
leftOffset = int(firstComp.x)
rightOffset = int(l.width-firstComp.x-compWidth)
if abs(leftOffset) <= 1:
leftKey = None
else:
leftKey = f"==+{leftOffset}".replace("+-","-")
if abs(rightOffset) <= 1:
rightKey = None
else:
rightKey = f"==+{rightOffset}".replace("+-","-")
l.leftMetricsKey = leftKey
l.rightMetricsKey = rightKey
for c in l.components:
c.makeEnableAlignment()
print(f"👍🏻 {', '.join(glyphsToAlign)} aligned in {m.name}.")
for glyphName in glyphsToAlign:
g = font.glyphs[glyphName]
if g.leftMetricsKey and all([not x in g.leftMetricsKey for x in ("+=", "-=")]):
print(f"🚨 Removing glyph-wide left metrics key ‘{g.leftMetricsKey}’ for {glyphName}.")
g.leftMetricsKey = None
if g.rightMetricsKey and all([not x in g.rightMetricsKey for x in ("+=", "-=")]):
print(f"🚨 Removing glyph-wide right metrics key ‘{g.rightMetricsKey}’ for {glyphName}.")
g.rightMetricsKey = None
font.newTab("/"+"/".join(glyphsToAlign))
print("✅ Done.")
@mekkablue
Copy link
Author

Glyphs 3.x script for the Macro window.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment