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 / consolidate_selected_point_pairs.py
Last active January 9, 2024 02:02
Looks at selected points, attempts to pair them up, and consolidates each pair into one point (attempts to preserve curve)
# menuTitle: Consolidate Selected Point Pairs
# shortCut : shift + control + f
from fontTools.misc.fixedTools import otRound
MAKE_INTO_ONE_POINT = True
def average(lst):
@ryanbugden
ryanbugden / accept_figma_svg.py
Last active August 3, 2023 02:43
RF start-up scripts for moving SVGs to and from Figma (or other apps) via pasteboard.
# menuTitle: Accept SVGs from Figma (Start-up script)
'''
An RF start-up script that allows inbound SVG data from Figma via pasteboard.
Should work on simple shapes, might not work for others.
Ryan Bugden
'''
import AppKit
@ryanbugden
ryanbugden / rotate_180-all_layers.py
Created August 3, 2023 02:29
See docstring in the script for description.
# menuTitle: Rotate 180 - All Layers
# shortCut: shift + command + r
'''
A script that rotates your glyph and all of its layers.
It does its best to rotate it in a helpful way, not
necessarily just around the body of the contours themselves.
Use your preferred shortcut in line 2.
Ryan Bugden
@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