Skip to content

Instantly share code, notes, and snippets.

@LettError
Created February 28, 2025 21:41
Show Gist options
  • Select an option

  • Save LettError/be076a82bded34216f07818bd77e38af to your computer and use it in GitHub Desktop.

Select an option

Save LettError/be076a82bded34216f07818bd77e38af to your computer and use it in GitHub Desktop.
RobFont: sync appearance states for all open sources.
# coding: utf-8
# menuTitle : 📌 Sync Layer Appearance
"""
RoboFont layer's drawing states
are sometimes a bit fiddly to edit.
Different colors, different fills.
When your designspace has many sources
switching between different states can
be visually jarring.
This here script takes the current font
as a model, and then applies its layer
states and layer colors to the other
open sources,
I suppose it could be a small UI.
I suppose it could text prefs.
But not today.
erik@letterror.com
20250228
"""
# Undocumented but easy to find in the layer's lib
# I think the author wanted us to understand these keys.
layerKeys = [
'com.typemytype.robofont.layerShow',
'com.typemytype.robofont.layerShowCoordinates',
'com.typemytype.robofont.layerShowFill',
'com.typemytype.robofont.layerShowPoints',
'com.typemytype.robofont.layerShowStroke'
]
# take the currentfont as model for the appearance of the others.
model = CurrentFont()
for f in AllFonts():
if model.path == f.path:
continue
for l in f.layers:
# model has this layer?
if not l.name in [m.name for m in model.layers]:
continue
modelLayer = model.getLayer(l.name)
l.color = modelLayer.color
print(f"{f.info.styleName}\n.\t.\t{l.name}")
for k in layerKeys:
if k in l.lib and k in modelLayer.lib:
l.lib[k] = modelLayer.lib[k]
print(f".\t.\t.\t{k.split(".")[-1]}: {l.lib[k]}")
#print(f"\t\t{l.color}")
l.changed()
f.changed()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment