Skip to content

Instantly share code, notes, and snippets.

@typoman
Last active December 9, 2021 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save typoman/83cb1f3e618ae986fe792e8ec2a1a2b6 to your computer and use it in GitHub Desktop.
Save typoman/83cb1f3e618ae986fe792e8ec2a1a2b6 to your computer and use it in GitHub Desktop.
RoboFont Metrics Math
from glyphConstruction import *
from mojo.UI import CurrentWindow
"""
RoboFont Script
- Type: Metrics
- Purpose: Fix metrics of selected glyphs according to a formula.
- Specifications:
- Uses RoboFont GlyphConstruction syntax to change metrics of glyphs.
- Publish Date: 18 April 2021
- Author: Bahman Eslami
- License: MIT
For the following example, main reference glyphs for applying the metrics math are:
H, O
Select the glyphs you want to update their metrics and run the script.
"""
metrics_formula = """
>U = ^ H, H
>P = ^ H, O/2
"""
cw = CurrentWindow().doodleWindowName
f = CurrentFont()
selection = []
if cw == 'FontWindow':
f = CurrentFont()
s = f.templateSelectedGlyphNames
for gn in s:
selection.append(gn)
elif cw == 'GlyphWindow':
g = CurrentGlyph()
if g is not None:
selection.append(g.name)
constructions = ParseGlyphConstructionListFromString(metrics_formula)
for c in constructions:
gn = c.split('=')[0].strip()[1:]
if gn in selection:
cg = GlyphConstructionBuilder(c, f)
g = f[cg.name]
g.prepareUndo("Metric Math")
g.leftMargin = cg.leftMargin
g.width = cg.width
g.changed()
g.performUndo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment