Skip to content

Instantly share code, notes, and snippets.

@adaptivegarage
adaptivegarage / theme-detect.css
Last active December 1, 2024 00:39
Pure CSS ePub theme detection (White / Sepia / Night) in iBooks (Mac OS and iOS included)
/*
Pure CSS ePub theme detection (White / Sepia / Night) in iBooks (Mac OS and iOS included)
Version 1.1
Note that iBooks actually uses internal JavaScript to set the "__ibooks_internal_theme" attribute on :root (html) element
every time the theme is changed, but this happens independently of whether your epub html markup is scripted or not.
Discovered and tested in iBooks on Mac, iPhone and iPad by
https://twitter.com/adaptivegarage
*/
@typemytype
typemytype / addMeasurement.py
Created December 10, 2014 20:48
add a measurement line in RoboFont
from AppKit import NSPoint
from mojo.events import MeasurementTool
measurement = MeasurementTool.measurementClass()
measurement.startPoint = NSPoint(100, 100)
measurement.endPoint = NSPoint(200, 200)
g = CurrentGlyph()
g.naked().measurements.append(measurement)
g.update()
@benkiel
benkiel / simplify_components.py
Created June 11, 2015 22:04
Walks all open fonts and looks for a component that is a reference of another component. Is dumb and assumes that there is only one component the reference. Good for quickly cleaning up UFOs before importing into FontLab, where this sort of thing isn't allowed.
fonts = AllFonts()
for font in fonts:
for g in font:
if len(g.components) != 0:
for c in g.components:
b = font[c.baseGlyph]
if len(b.components) != 0:
e = b.components[0]
eb = e.baseGlyph
@LettError
LettError / blinkenDraw.py
Last active March 14, 2018 16:38
Toy script for RF3: draw animated pixels in a tiny window, save to gif.
# coding: utf-8
import os
import vanilla
import mojo.canvas
from mojo.UI import PutFile
from random import random
from mojo.drawingTools import *
import drawBot
from AppKit import NSTimer
@frankrolf
frankrolf / unicats.py
Last active February 10, 2021 13:47
Select Unicode categories in Robofont 3
from mojo.UI import CurrentFontWindow
import unicodedata
import AppKit
from vanilla import CheckBox, FloatingWindow, List
category_to_codepoints = {}
for code_point in range(0, 0xFFFF + 1):
category = unicodedata.category(chr(code_point))
{
"cmd": ["robofont", "-p", "$file"],
"file_regex": "^[ ]File \"(...?)\", line ([0-9]*)",
"selector": "source.python",
}
@LettError
LettError / angleRatioTool.py
Created February 28, 2019 09:57
EditTool script for RoboFont 3. Show the ratio between the length of incoming and outgoing sections of bcps and tangents.
import AppKit
from mojo.events import installTool, EditingTool, BaseEventTool, setActiveEventTool
from mojo.drawingTools import *
from mojo.UI import UpdateCurrentGlyphView
from defconAppKit.windows.baseWindow import BaseWindowController
import math
#
#
# A visualisation for RoboFont
@frankrolf
frankrolf / anchorBaby.py
Last active April 16, 2020 15:16
RoboFont observer for keeping anchors consistent.
'''
## anchorBaby.py
RoboFont script for keeping anchors consistent.
Inspired by an idea from James T. Edmondson, this script will take note of
anchor movement in a given glyph, and replicate that movement in all
dependent glyphs.
For instance, if a font has the glyphs `a` `a.init` and `a.fina`; and all three
@typoman
typoman / roboFontPerformanceTests.py
Last active September 8, 2020 10:09
This can be used to find faster ways to perform tasks in RoboFont using python
import time
def timeit(method):
def timed(*args, **kw):
ts = time.time()
result = method(*args, **kw)
te = time.time()
if 'log_time' in kw:
name = kw.get('log_name', method.__name__.upper())
kw['log_time'][name] = int((te - ts) * 1000)
else:
@typoman
typoman / roboFontCompDoubleClick.py
Last active May 21, 2022 09:56
RoboFont startup script to enable jump to base glyph of componets by double clicking on the component in glyph view.
from defconAppKit.windows.baseWindow import BaseWindowController
from vanilla import FloatingWindow
from mojo.events import addObserver, removeObserver
from mojo.UI import SetCurrentGlyphByName
"""
RoboFont Helper
Type: Start up
Purpose: After it's run, if you double click on a component it will jump to its base glyph.
"""