Skip to content

Instantly share code, notes, and snippets.

View mathieureguer's full-sized avatar

Mathieu Réguer mathieureguer

View GitHub Profile
"""
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.
"""
#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
"""
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
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:
# 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
@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
from mojo.UI import SetCurrentLayerByName
from mojo.subscriber import Subscriber, registerGlyphEditorSubscriber
from fontTools.ufoLib.pointPen import AbstractPointPen
import math
"""
This is *largely* based on the great work of Jackson Cavanaugh on AddOverlapp
and the awesome drag offset update by Ryan Bugden
It is *extremly* likely not the best way to use merz and subscriber :)
# menuTitle : auto align points
# shortCut : command+shift+E
"""
Move 2 points to align them.
Will guess between x and y alignment based on shortest move required.
Should align according to italic angle as well.
"""
do_italic_angle = True
#menuTitle: ReMutate Support Layer
import ufoProcessor
import mojo.UI
import pathlib
# ----------------------------------------
def get_sources_paths(designspace):
"""
selectively copy and paste glyph attributes
"""
from vanilla import *
class attributeMover():
def __init__(self):