Skip to content

Instantly share code, notes, and snippets.

View mathieureguer's full-sized avatar

Mathieu Réguer mathieureguer

View GitHub Profile
@mathieureguer
mathieureguer / toggleSubscriber.py
Created February 15, 2022 15:21
A little helper function to toggle Subscriber on and off
from mojo.subscriber import *
def toggleSubscriberClass(SubscriberClass, register_function):
"""
Will register a SubscriberClass with the suplied register_function if that SubscriberClass is not already registered.
Will unregister a SubscriberClass with the corresponding unregister_function if that SubscriberClass is already registered.
Usage:
considering the Neighbours.py example in the Robofont documentation
# this is largely stolen from Antonio Cavedoni's much cooler CAShapeLayer animation demo.
import vanilla
from mojo.events import addObserver, removeObserver
from mojo.UI import splitText
from fontTools.pens.basePen import BasePen
from AppKit import NSView, NSMakeRect, NSColor, CAShapeLayer, NSRect, CAScrollLayer
from Quartz.QuartzCore import kCALayerWidthSizable, kCALayerHeightSizable, CABasicAnimation
IGNORE_ANCHORS = []
# ----------------------------------------
def match_anchor(anchor_source, anchor_targets):
if anchor_source.name.startswith("_"):
target_name = anchor_source.name[1:]
else:
target_name = "_" + anchor_source.name
for a in anchor_targets:
"""
Run in Robofont.
Tries to add anchors to selected glyphs, based on the position of components in relevant glyphs.
This script is not smart enough to distinguish top and bottom anchors (sorry), it must be run again for each target_anchor_name.
Here is a typical process:
- add "_top" to the circumflex glyph (we need at least an anchor as a starting point)
- set target_anchor_name to "top"
- select the base glyphs you want anchored (both base letters and diacritic glyphs)
- run
#menuTitle: flag USWin table cropped glyphs
for font in AllFonts():
y_min_flags = []
y_max_flags = []
for g in font:
if g.bounds:
_, _, y_min, y_max = g.bounds
"""
This is very barebones, but it allows changing one or several locations
within a designspace while preerving an identical output.
(hey, it's hard to plan a designspace exactly right from the start :)
ie. changing a source location from weight:1200 to weight:1000 will recalculate all the other locations
so that the resulting instances remain the same as before.
Set your relocation_map below.
"""