Skip to content

Instantly share code, notes, and snippets.

View ryanbugden's full-sized avatar
🏠
Working from home

Ryan Bugden ryanbugden

🏠
Working from home
View GitHub Profile
@ryanbugden
ryanbugden / set_latest_kern_value.py
Last active January 9, 2024 02:05
Save the kern value from the last pair you were on, for quick application to your current pair (with the Page-Down key). Install "store..." as a start-up script, and "set...py" as a normal script in the script folder.
# menuTitle: Set the Latest Kern Value
# shortCut: pagedown
from mojo.UI import getDefault
import metricsMachine as mm
KERN_VALUE_LIB_KEY = 'com.ryanbugden.storeLatestKernValue.kernValue'
def get_kern_group(f, glyph, side):
if side == 'left':
@ryanbugden
ryanbugden / menu-toggle_skip_export.py
Created March 21, 2023 17:05
A font overview contextual menu item that allows you to toggle skip-export for selected glyphs. Install as start-up script.
from mojo.subscriber import Subscriber, registerFontOverviewSubscriber
class ToggleSkipExportMenu(Subscriber):
'''
A contextual menu item:
Go through all selected glyphs, and change whether they are set to export or non-export,
based on the opposite of the state of the first glyph.
@ryanbugden
ryanbugden / scale_while_slanted.py
Last active January 25, 2024 16:48
Honor the italic angle when scaling disproportionately.
# menuTitle: Scale While Slanted
import ezui
from mojo.extensions import getExtensionDefault, setExtensionDefault
from fontTools.misc.transform import Transform
from math import radians
EXTENSION_KEY = "com.ryanbugden.scaleWhileSlanted.settings"
EXTENSION_DEFAULTS = {
@ryanbugden
ryanbugden / addMissingGlyphsFromClipboard.py
Created August 24, 2020 21:43
Copy the text sample you'd like to fulfill to your clipboard. Run this script. Font overview will add more template glyphs for the glyphs you still need to draw.
# menuTitle: Add Missing Characters from Clipboard Text
import collections
from glyphNameFormatter import GlyphName
from AppKit import NSPasteboard, NSPasteboardTypeString
f = CurrentFont()
templ_gs = f.templateGlyphOrder
pasteboard = NSPasteboard.generalPasteboard()
@ryanbugden
ryanbugden / makeTwoLinesParallel.py
Last active August 21, 2020 17:12
Select four points. Make their line segments parallel by running.
# menuTitle : Make Two Selected Lines Parallel
import math
def sortTuple(tup):
# sort line coordinates in ascending y order
tup.sort(key = lambda x: x[1])
return tup
g = CurrentGlyph()
# menuTitle : Generate Instances from Designspaces
from ufoProcessor import build
from mojo.UI import GetFile
paths = GetFile(
message='Select all designspaces, the instances of which you want to generate.',
title='Generate Instances',
allowsMultipleSelection=True
)
@ryanbugden
ryanbugden / markUndrawnGlyphsFromSCRed.py
Last active July 23, 2020 20:27
Add sample text into Space Center. Run this script. Any glyphs that don't exist in the font will be highlighted red. Draw them!
# menuTitle : Mark Undrawn Glyphs from SC Red
from mojo.UI import CurrentSpaceCenter
from glyphNameFormatter.tools import charToUnicode
f, csc = CurrentFont(), CurrentSpaceCenter()
text = csc.getRaw()
color = (1, 0, 0, 1) #red
for letter in text:
@ryanbugden
ryanbugden / makeGNReadable.py
Created July 20, 2020 21:24
Script that goes through each glyph in the current font and—based on its unicode—sets its name according to AGL
# menuTitle : Make All Glyph Names Human Readable
from lib.tools.unicodeTools import GN2UV
def get_key(val, di):
for key, value in di.items():
if val == value:
return key
f = CurrentFont()
@ryanbugden
ryanbugden / openGlyphPreviewWindow.py
Last active July 15, 2020 20:55
Opens a slick glyph preview for when you're working. Thanks Juan for the idea; RoboFont.com for the example code on which this is based
# menuTitle : Open Glyph Preview Window
from vanilla import FloatingWindow
from mojo.glyphPreview import GlyphPreview
from mojo.roboFont import OpenWindow
from mojo.events import addObserver, removeObserver
from lib.tools.misc import rgbaToNSColor
class GlyphPreviewWindow:
@ryanbugden
ryanbugden / spaceCenterTuner.py
Created June 17, 2020 21:20
Fine-tune space center setting
from mojo.UI import CurrentSpaceCenter
from vanilla import FloatingWindow, Slider, TextBox
from AppKit import NSColor
from mojo.events import addObserver, removeObserver
class SpaceCenterTuner():
"""
Fine-tune Space Center sizing and spacing.
Ryan Bugden