Created
February 14, 2024 18:40
-
-
Save mekkablue/6d311e4bb23cdb809f3c47af8358b44a to your computer and use it in GitHub Desktop.
Quick script: Check ()[]{}
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 ()[]{}" | |
Glyphs.clearLog() | |
Glyphs.showMacroWindow() | |
# adapt as needed: | |
threshold = 1.0 | |
font = Glyphs.font | |
print(font.familyName) | |
collectedLayers = [] | |
for m in font.masters: | |
mid = m.id | |
for bracket in ("paren", "bracket", "brace"): | |
leftGlyph = font.glyphs[bracket+"left"] | |
rightGlyph = font.glyphs[bracket+"right"] | |
if leftGlyph is None or rightGlyph is None: | |
print(f"❌ master ‘{m.name}’: {bracket}left and {bracket}right do not exist.") | |
continue | |
leftLayer = leftGlyph.layers[mid] | |
rightLayer = rightGlyph.layers[mid] | |
leftOrigin = leftLayer.bounds.origin.y | |
rightOrigin = rightLayer.bounds.origin.y | |
leftTop = leftOrigin + leftLayer.bounds.size.height | |
rightTop = rightOrigin + rightLayer.bounds.size.height | |
originDiff = abs(leftOrigin-rightOrigin) | |
topDiff = abs(leftTop-rightTop) | |
if originDiff>=threshold or topDiff>=threshold: | |
print(f"⚠️ master ‘{m.name}’: {bracket}left and {bracket}right not on same level: bottom {originDiff:.1f} off, top {topDiff:.1f} off.") | |
collectedLayers.extend([leftLayer, rightLayer]) | |
if not collectedLayers: | |
Message( | |
"All pairs of ()[]{} are on the same height.", | |
title='🥳 Congrats', | |
OKButton="Yippie", | |
) | |
else: | |
font.newTab(collectedLayers) | |
print(f"✅ Found {int(len(collectedLayers)/2)} pairs. Opened in a new tab.") |
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.