Skip to content

Instantly share code, notes, and snippets.

Avatar

Erik van Blokland LettError

View GitHub Profile
@LettError
LettError / cosineSimilarity.py
Last active Dec 20, 2021
Experiment with cosine similarity and normalised side profiles of shapes..
View cosineSimilarity.py
import statistics
import math
import numpy
from fontPens.marginPen import MarginPen
from defcon import addRepresentationFactory
from mojo.UI import OpenSpaceCenter
import vanilla
@LettError
LettError / rescueImages.py
Created Nov 23, 2021
Script for Robofont - copy unreferenced images from the ufo to a new folder, then delete them from the ufo.
View rescueImages.py
import os
import io
from fontParts.fontshell import RGlyph as partsGlyph
from shutil import copyfile
"""
This will cross reference the image files in <ufoname>/images
with the actual files referenced in the .glif.
Images that are not used will be copied to a new folder <ufoname>_rescued_images
@LettError
LettError / generate_instances.py
Created Oct 22, 2021
Generate instances from a designspace or superpolator document. This will work in RF3 and RF4. Note that if you have complex substitutions as Superpolator allowed, these can not always be converted variable font style rules.
View generate_instances.py
import ufoProcessor
from mojo.UI import PutFile, GetFile
import os
"""
Open a .sp3 or .designspace document and generate the instances.
No reporting, no editing, no debugging.
"""
def convertSuperpolatorToDesignSpace(path):
@LettError
LettError / obliqueScale.py
Created Oct 12, 2021
Horizontal scaling while preserving the italic angle. (by "unskewing" the geometry to "upright", then scaling, then "reskewing" back to the italic angle)
View obliqueScale.py
from fontTools.pens.transformPen import TransformPen
from fontTools.pens.pointPen import AbstractPointPen
from fontTools.misc.transform import Transform
import math
from defcon.objects.glyph import Glyph
class TransformPen2(TransformPen):
# because we don't want to change the transform matrix of the actual components
def addComponent(self, glyphName, transformation):
@LettError
LettError / copyNamesToClipboard.py
Created Mar 29, 2021
RoboFont Script that offers a small UI for copying the selected glyphs in different ways.
View copyNamesToClipboard.py
# coding: utf-8
# menuTitle : Copy Names To Clipboard
# shortCut : command+shift+C
import vanilla
from defconAppKit.windows.baseWindow import BaseWindowController
from mojo.roboFont import CurrentFont, CurrentGlyph, AllFonts, OpenWindow
from AppKit import NSPasteboardTypeString, NSPasteboard
"""
@LettError
LettError / drawbot_generate_teams_background.py
Created May 8, 2020
Generate a background for Teams with drawbot
View drawbot_generate_teams_background.py
import os
from os.path import expanduser
home = expanduser("~")
backgroundFolder = os.path.join(home, "Library/Application Support/Microsoft/Teams/Backgrounds/Uploads")
size(1920, 1080)
s = 10
sw = int(width()/s)
@LettError
LettError / icons.txt
Created Dec 17, 2019
DeRez output of the ICON resources from RoboFog 1.6.3
View icons.txt
data 'ICON' (20265) {
$"0000 0000 0000 0000 0000 0000 0000 0000" /* ................ */
$"0000 0000 0000 0000 0000 0000 0000 0000" /* ................ */
$"0000 0000 0000 0000 0000 0000 00FE 0000" /* .............˛.. */
$"0101 0000 0210 8000 0438 4000 0854 2000" /* ......Ä..8@..T . */
$"1082 1000 2101 0800 4210 8400 8428 4200" /* .Ç..!...B.Ñ.Ñ(B. */
$"0844 2000 1082 1000 0101 0000 0200 8000" /* .D ..Ç........Ä. */
$"0400 4000 0000 0000 0000 0000 0000 0000" /* ..@............. */
$"0000 0000 0000 0000 0000 0000 0000 0000" /* ................ */
};
@LettError
LettError / prrrrrr.py
Created Sep 6, 2019
RoboFont: temporary designspace + designspaceChecker to report on glyph compatibility issues.
View prrrrrr.py
"""
test all open fonts on compatibility
create temp designspace file
align all fonts on a temp axis
order does not matter
run designspaceProblems
present the data somehow
@LettError
LettError / export_drawings.py
Created May 22, 2019
Export Robofont glyph image to iCloud, then reimport it again. After editing it on an ipad for instance.
View export_drawings.py
import drawBot as ctx
import os
from os.path import expanduser
home = expanduser("~")
imagesDir = "Library/Mobile Documents/com~apple~CloudDocs/RoboFont/"
path = os.path.join(home, imagesDir)
if not os.path.exists(path):
os.makedirs(path)
@LettError
LettError / unicodeStyleWriter.py
Created Feb 28, 2019
A small converter from normal latin AZ,az to the Unicode math alphabets.
View unicodeStyleWriter.py
import vanilla
""" Unicode Stylewriter: Use the unicode styles to impress friends and families on the internet. """
class StyleWriter(object):
styles = [
dict(title="𝔸", upper=0x1D538, lower=0x1D552, name='mathdoublestruck'),
dict(title="𝖠", upper=0x1D5A0, lower=0x1D5BA, name='mathsans'),
dict(title="𝗔", upper=0x1D5D4, lower=0x1D5EE, name='mathsansbold'),
dict(title="𝐴", upper=0x1D434, lower=0x1D44E, name='mathitalic'),
dict(title="𝐀", upper=0x1D400, lower=0x1D41A, name='mathbold'),