Skip to content

Instantly share code, notes, and snippets.

View mekkablue's full-sized avatar

Rainer Erich Scheichelbauer mekkablue

View GitHub Profile
def intersect( x1, y1, x2, y2, x3, y3, x4, y4 ):
"""Calculates the intersection of line P1-P2 with P3-P4."""
slope12 = ( float(y2) - float(y1) ) / ( float(x2) - float(x1) )
slope34 = ( float(y4) - float(y3) ) / ( float(x4) - float(x3) )
x = ( slope12 * x1 - y1 - slope34 * x3 + y3 ) / ( slope12 - slope34 )
y = slope12 * ( x - x1 ) + y1
return x, y
@mekkablue
mekkablue / Grid Switcher.py
Last active August 29, 2015 14:00
Grid Switcher for Glyphs.app
#MenuTitle: Grid Switcher
# -*- coding: utf-8 -*-
"""Turns Grid on and off."""
import vanilla
import GlyphsApp
class GridOnOff( object ):
def __init__( self ):
currentGridStep = Glyphs.font.gridMain()
@mekkablue
mekkablue / Isopsephy.py
Last active August 11, 2022 09:55
Creating an Isopsephy OT feature
alphabet = list( "abcdefghijklmnopqrstuvwxyz" )
alphabetLength = len(alphabet)
wordlength = 5
figures = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
def wordForNumber( thisNumber ):
figurelist = [ figures[int( x )] for x in str( thisNumber ) ]
return "_".join( figurelist )
def lookupWithContent( lookupName, content ):
@mekkablue
mekkablue / Add Hints.py
Created May 2, 2014 07:06
Adds hints for the current node selection in Glyphs.app
#MenuTitle: Add Hints
# -*- coding: utf-8 -*-
"""Add Hints for the Selected Nodes. Tries to guess whether it should be H or V. If exactly one node inside a zone is selected, it will add a Ghost Hint."""
import GlyphsApp
Font = Glyphs.font
FontMaster = Font.selectedFontMaster
thisLayer = Font.selectedLayers[0]
thisSelection = [ n for n in thisLayer.selection() if n.className() == "GSNode" ]
@mekkablue
mekkablue / Invert Selection in Font View.py
Last active August 29, 2015 14:05
Inverts the glyph selection in Font View.
#MenuTitle: Invert Selection in Font View
# -*- coding: utf-8 -*-
__doc__="""
Inverts the glyph selection in Font View.
"""
import GlyphsApp
thisFont = Glyphs.font # frontmost font
from subprocess import Popen, PIPE
def runAppleScript(scpt, args=[]):
p = Popen(['osascript', '-'] + args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate(scpt)
return stdout
nameOfFont = """
tell application "InDesign"
tell front document
@mekkablue
mekkablue / Copy Unicode-Sorted Glyph List.py
Created May 13, 2015 07:33
Glyphs script which creates a glyph list of all encoded glyphs, in Unicode order, and puts it in your clipboard for pasting.
#MenuTitle: Copy Unicode-Sorted Glyph List
# -*- coding: utf-8 -*-
__doc__="""
Creates a glyph list of all encoded glyphs, in Unicode order, and puts it in your clipboard for pasting.
"""
import GlyphsApp
from AppKit import *
thisFont = Glyphs.font # frontmost font
@mekkablue
mekkablue / Copy Glyph Names to Clipboard.py
Created May 29, 2015 22:40
Copy Glyph Names to Clipboard
#MenuTitle: Copy Glyph Names to Clipboard
# -*- coding: utf-8 -*-
__doc__="""
Copies a newline-separated list of glyph names to the clipboard.
"""
import GlyphsApp
from AppKit import *
separator = "\n"
@mekkablue
mekkablue / Open Corner in all Layers.py
Last active March 7, 2016 13:47
Tries to open the corner for a single selected node, in all layers if compatible.
#MenuTitle: Open Corner in all Layers
# -*- coding: utf-8 -*-
__doc__="""
Tries to open the corner for a single selected node, in all layers if compatible.
"""
thisFont = Glyphs.font # frontmost font
thisFontMaster = thisFont.selectedFontMaster # active master
thisLayer = thisFont.selectedLayers[0] # active layers of selected glyphs
selection = thisLayer.selection # node selection in edit mode
@mekkablue
mekkablue / Use Excel columns in clipboard for renaming glyphs
Created June 26, 2019 01:41
Put in Macro Window and run after copying Excel columns (oldname, newname) in clipboard
from AppKit import NSPateboard, NSStringPboardType
myClipboard = NSPasteboard.generalPasteboard()
renameString = myClipboard.stringForType_(NSStringPboardType)
renameCount = 0
print "Processing: %s" % Font.familyName
print
for renameLine in renameString.strip().splitlines():