Skip to content

Instantly share code, notes, and snippets.

View connordavenport's full-sized avatar

Connor Davenport connordavenport

View GitHub Profile
@connordavenport
connordavenport / LayerSinker.py
Created October 12, 2023 17:09
sync layer metrics when a font opens
from mojo.subscriber import Subscriber, registerRoboFontSubscriber
class LayerSinker(Subscriber):
def fontDocumentDidOpen(self,info):
font = info["font"]
font.lib['com.typemytype.robofont.syncGlyphLayers'] = 'metrics'
registerRoboFontSubscriber(LayerSinker)
@connordavenport
connordavenport / RGlyph_markColorName.py
Last active October 18, 2024 20:19
a fontparts add on to allow one to mark a glyph by the color name
from mojo.roboFont import RGlyph
from mojo.UI import getDefault
'''
g = CurrentGlyph()
g.markColorName = "Red"
'''
def _setColorName(self, color=None):
if not isinstance(color, str):
@connordavenport
connordavenport / AutoCommit.py
Last active October 11, 2023 20:58
Automatic Git Commiter
from AppKit import NSBeep,NSTimer,NSRunLoop,NSRunLoopCommonModes
import git
import os
from mojo.extensions import setExtensionDefault, getExtensionDefault
import re
from mojo.UI import PostBannerNotification
'''
A startup script for RoboFont to automatically commit to Git every 5 minutes.
To use, run the following script with your GitHub email:
@connordavenport
connordavenport / RGlyph_BoundsPositions.py
Last active October 3, 2023 23:40
A startup script that adds a few functions to a glyph to retrieve specific bound location.
'''
fontParts add-on to get specific locations of a glyph's bounds
10
0 3 6
#######
# #
# #
9 1 ## 4 ## 7
@connordavenport
connordavenport / MargielaTabs.py
Last active September 28, 2023 20:15
A startup script for RoboFont that will automatically group/tabulate your fonts by info.familyName
from mojo.subscriber import Subscriber, registerRoboFontSubscriber
import AppKit
class MargielaTabs(Subscriber):
def fontDocumentDidOpen(self,info):
newFont = info["lowLevelEvents"][0]["font"]
windowsMap = {}
allFonts = {f.info.familyName:AllFonts().getFontsByFamilyName(f.info.familyName) for f in AllFonts()}
for familyName,fonts in allFonts.items():
@connordavenport
connordavenport / fitTextToWidth_SpaceCenter.py
Created September 16, 2023 16:18
Fit the current space center text to the view width, it measures the longest line (broken up by newlines) and scales it based on that.
from mojo.UI import CurrentSpaceCenter
def measureLine(pointSize, records):
scale = pointSize / window.font.info.unitsPerEm
sublists = []
currentSublist = []
lineBreakChar = "NewLineGlyph"
for item in records:
if item.glyph.objectName == lineBreakChar:
@connordavenport
connordavenport / AutoNaming.py
Last active September 3, 2023 19:29
Subsriber to automatically set font name entries when info has changed
from mojo.subscriber import Subscriber, registerCurrentFontSubscriber
import unicodedata
class AutoNameSetter(Subscriber):
debug = True
def build(self):
pass
@connordavenport
connordavenport / Add_Support_At_Current_Layer.py
Created August 29, 2023 17:09
interpolates a support glyph at the current layer. Must have a {x,y,z} formatted layer name. Designspace file path is stored in your font's lib.
from fontTools.designspaceLib import DesignSpaceDocument, InstanceDescriptor
from ufoProcessor import DesignSpaceProcessor, ufoOperator
import tempfile
import os
import shutil
from mojo.UI import GetFile
f = CurrentFont()
file = f.lib.get("com.connordavenport.interpolateSupport.designspaceFile")
if file:
@connordavenport
connordavenport / Fill_Support_Layer_Components.py
Created August 29, 2023 14:53
Fill missing components for support layers
from fontTools.designspaceLib import DesignSpaceDocument, InstanceDescriptor
from ufoProcessor import DesignSpaceProcessor, ufoOperator
import tempfile
import os
import shutil
dsPath = 'path/to/file.designspace'
for f in AllFonts():
for l in f.layers:
for g in l:
@connordavenport
connordavenport / makeParts.py
Last active August 21, 2023 21:09
give RF a glyphs like feature to make a component out of contour
from mojo.subscriber import Subscriber, registerRoboFontSubscriber
class makeParts(Subscriber):
debug = True
def glyphEditorWantsContextualMenuItems(self, info):
myMenuItems = [
("Make Component of Contour(s)", self.markPartCallback),