Skip to content

Instantly share code, notes, and snippets.

View connordavenport's full-sized avatar

Connor Davenport connordavenport

View GitHub Profile
@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),
@connordavenport
connordavenport / commitedRelationship.py
Created August 8, 2023 16:33
Notifies you once you've saved 5 times, it might be a good point to commit to git. You can change the limit to whatever you want though.
from mojo.extensions import getExtensionDefault, setExtensionDefault
from mojo.subscriber import Subscriber, registerRoboFontSubscriber
from mojo.UI import PostBannerNotification, Message
DEFAULTSKEY = "com.connorDavenport.commitedRelationship"
SAVELIMIT = 5
class commitedRelationship(Subscriber):
def fontDocumentWillSave(self,info):
@connordavenport
connordavenport / CopyMachine.py
Created July 27, 2023 15:07
Copies and slant anchors from roman
g = CurrentGlyph()
f = g.font
of = AllFonts().getFontsByStyleName(f.info.styleName.replace(" Italic", ""))[0]
og = of[g.name]
try:
fr = g.width/og.width
except ZeroDivisionError:
fr = 1
with g.undo():
g.clearAnchors()
@connordavenport
connordavenport / drawbotMarkdown.py
Last active August 9, 2023 14:13
A WIP script to add markdown functionality to DrawBot.
import re
sampleText = '''
A spectre is haunting [Europe](www.robofont.com) — the spectre of **communism**. All the __powers of old Europe have__ entered into a holy alliance to exorcise this spectre: Pope and Tsar, Metternich and Guizot, French Radicals and German police-spies.
Where is the party in opposition that has not been decried as communistic by its opponents in power? Where is the opposition that has not hurled back the branding reproach of **communism**, against the more advanced opposition parties, as well as against its reactionary adversaries?
Two things result from this fact:
I. **Communism** is *already acknowledged* by all _European_ powers to be itself a power.
@connordavenport
connordavenport / gitMachineMini.py
Last active August 8, 2023 16:27
A simple git UI for robofont. Commit faster and spend more time drawing your nice fonts:)
# menuTitle : GitMachineMini
# shortCut : command+shift+c
from AppKit import NSBeep
import git
import os
import ezui
from mojo.extensions import setExtensionDefault, getExtensionDefault
import webbrowser
import re
@connordavenport
connordavenport / RGlyph_GetCommits.py
Last active March 13, 2023 19:39
a custom fontparts function to get the git commits of a specific glyph. adapted from Mathieu Reguer's robofont-git tool
from git import Repo
import os
from fontTools.ufoLib.glifLib import readGlyphFromString, GlyphSet
import time
def getCommits(self,):
glif_path = get_glif_path_from_glyph(self)
commits = get_all_commit_for_file(glif_path)
history = {GlyphCommit(b):GlyphCommit(b).hash for b in commits}
return history