Skip to content

Instantly share code, notes, and snippets.

@typemytype
typemytype / swapper.py
Created March 3, 2014 16:20
swap bottom/top part of all glyphs in a font :)
g = CurrentGlyph()
f = CurrentFont()
for g in f:
box = g.box
if box is None:
from fontTools.pens.basePen import BasePen
class MyPen(BasePen):
def _moveTo(self, pt):
print "move to", pt
def _lineTo(self, pt):
print "line to", pt
@typemytype
typemytype / reconvertSplinePointPen.py
Created April 6, 2014 20:50
ReconvertSplinePointPen
from robofab.pens.pointPen import AbstractPointPen, PrintingPointPen
from robofab.pens.adapterPens import SegmentToPointPen
from lib.tools.bezierTools import intersectRayRay
class ReconvertSplinePointPen(AbstractPointPen):
def __init__(self, outPointPen):
self.outPointPen = outPointPen
def beginPath(self):
@typemytype
typemytype / spaceCenterButtonAdder.py
Created May 3, 2014 07:45
Add buttons to a Space Center
from mojo.UI import CurrentSpaceCenter
from vanilla import *
class AddButtonToSpaceCenter:
def __init__(self):
sp = CurrentSpaceCenter()
l, t, w, h = sp.top.glyphLinePreInput.getPosSize()
sp.top.glyphLinePreInput.setPosSize((l + 50, t, w, h))
@typemytype
typemytype / getCreationModDate.py
Created June 25, 2014 12:02
get file creation and mod date
path = u"path/to/file"
from AppKit import *
fm = NSFileManager.defaultManager()
attr, error = fm.attributesOfItemAtPath_error_(path, None)
print attr[NSFileCreationDate]
print attr[NSFileModificationDate]
from fontTools.pens.basePen import BasePen
def pointOnCurve(p1, c1, c2, p2, value):
dx = p1[0]
cx = (c1[0] - dx) * 3.0
bx = (c2[0] - c1[0]) * 3.0 - cx
ax = p2[0] - dx - cx - bx
dy = p1[1]
cy = (c1[1] - dy) * 3.0
@typemytype
typemytype / autoConstraintsProposal.py
Created November 3, 2014 20:21
auto layout contraints proposal
import vanilla
from AppKit import *
"""
for the demo some vanilla objects are subclassed
- the main change would be in the VanillaBaseObject
- a window, sheet, group, popover (all elements that can set vanillaObjects) could have a addConstraints attribute
- map the attribute name and the view automatically whenever the posSize is "auto"
- the constraint cannot be a replacement of the posSize cause it the constraint Visual Format Language is a discription of a complete UI.
@typemytype
typemytype / previewer.py
Created November 6, 2014 08:16
drawBot in RoboFont
from drawBot import *
from drawBot.ui.drawView import DrawView
from vanilla import *
class Previewer(object):
def __init__(self):
# setup the window
self.w = Window((400, 400), "Previewer", minSize=(200, 200))
@typemytype
typemytype / stringToGlyphNames.py
Last active August 29, 2015 14:09
string to glyph names
"""
The MIT License (MIT)
Copyright (c) 2015 Frederik Berlaen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@typemytype
typemytype / searchDescriptiveSSNames.py
Created November 18, 2014 08:16
search for Descriptive Style Set Names
from fontTools.ttLib import TTFont
from robofab.interface.all.dialogs import GetFolder
from lib.tools.misc import walkDirectoryForFile
root = GetFolder("Folder with .otf / .ttf files...")
found = {}