Skip to content

Instantly share code, notes, and snippets.

View connordavenport's full-sized avatar

Connor Davenport connordavenport

View GitHub Profile
@connordavenport
connordavenport / Versioner.py
Last active September 27, 2022 10:05
Command line tool for changing version of a sfnt
#!/usr/bin/env python
'''
A command-line script to update a version number inside a SFNT.
python Versioner.py -v 1.420 -i *.otf
'''
import os
from re import findall as extract
from fontTools.ttLib import TTFont
@connordavenport
connordavenport / waveform.py
Created April 9, 2020 13:19
plot a .wav in drawbot
from scipy.io import wavfile
fs, data = wavfile.read("Untitled2.wav")
# for this case I only needed the left waveform
left = [a[0] for a in data.tolist()]
seconds = data.shape[0]/fs
fps = fs
duration = 1 / fps
totalFrames = round(seconds * fps)
# I was too lazy to scale anything so I made a massive image file:)
@connordavenport
connordavenport / frontAndCenter.py
Created April 29, 2020 17:49
Bring RF extension windows to the front when app becomes active
from AppKit import *
from mojo.events import addObserver
class frontAndCenter():
def __init__(self):
addObserver(self,"bringFront", "applicationDidBecomeActive")
def bringFront(self,sender):
windows = [w for w in NSApp().orderedWindows() if w.isVisible()]
from fontTools.ttLib.tables._f_v_a_r import table__f_v_a_r, Axis, NamedInstance
from fontTools.ttLib.tables._n_a_m_e import table__n_a_m_e, NameRecord
from fontTools.ttLib import TTFont
def AddName(font, name):
nameTable = font.get("name")
if nameTable is None:
nameTable = font["name"] = table__n_a_m_e()
nameTable.names = []
namerec = NameRecord()
from ufoProcessor import DesignSpaceProcessor
from mojo.UI import GetFile
# change this to True if you want to
# use VarLib instead of MutatorMath ↓
D = DesignSpaceProcessor(ufoVersion=3, useVarlib=False)
designspacePaths = GetFile("select a designspace file:", allowsMultipleSelection=True, fileTypes=['designspace'])
if designspacePaths:
for designspacePath in designspacePaths:
D.read(designspacePath)
D.generateUFO()
@connordavenport
connordavenport / mm_toggle.py
Last active September 24, 2020 17:12 — forked from frankrolf/mm_toggle.py
Toggle Metrics Machine pair list
'''
Toggle the pair list of an open MetricsMachine (extension) window
from all kerning pairs (sorted by glyph order) to exceptions and back.
'''
import metricsMachine
from mm4.interface.documentWindow import MMDocumentWindowController
from mm4.mmScripting import _getMainWindowControllerForFont, MetricsMachineScriptingError
import mm4
@connordavenport
connordavenport / frontAndCenter-RFont.py
Last active May 10, 2022 20:33
Bring a font to the front
# menuTitle : front & center
# shortCut : command+alt+0
from mojo.UI import SelectFont, AllFontWindows
from fontParts.world import RFont
class frontAndCenter:
def __init__(self):
self.fontWindows = [(w.document.font,w) for w in AllFontWindows() if hasattr(w, "document")]
@connordavenport
connordavenport / SyncMMWindows.py
Last active June 6, 2023 16:18
A small script to keep certain MM windows in sync
import metricsMachine
from mm4.mmScripting import MetricsMachineScriptingError
from vanilla import FloatingWindow, List, CheckBox, PopUpButton
from mojo.events import addObserver, removeObserver
from AppKit import *
from mojo.UI import Message
class SyncMM:
def __init__(self):
@connordavenport
connordavenport / syncAnchors.py
Last active September 27, 2023 16:09
Sync Anchors
from mojo.subscriber import Subscriber, registerGlyphEditorSubscriber, disableSubscriberEvents
'''
A startup script to help keep anchors in-sync across glyphs
The script will not append anchors, only move existing anchors
To set a linked glyph, add 'LinkedGlyphs:' in your main glyph's .note
On that same line add a comma separated list of glyph names (no spaces)
Adding a ! after a glyph name with a semicolon separated list will add
an exception and only those anchors will be moved
e.g.
@connordavenport
connordavenport / find-type1-fonts.py
Last active February 22, 2021 17:40
find type1 fonts in a directory
#!/usr/bin/python
import os
import sys
import fontTools.t1Lib
'''
usage:
cd into directory you want to look through