Skip to content

Instantly share code, notes, and snippets.

View LettError's full-sized avatar

Erik van Blokland LettError

View GitHub Profile
@LettError
LettError / guide_at_slantangle_tangent.py
Last active April 13, 2024 10:25
For RoboFont. Add a guideline for points (near selected points in the glyph) on the curve where the tangent is at a given angle.
# [email protected]
# April 2024
# version 1
# For robofont
# Dedicated to my github sponsors who encourate explorations like this.
# this can find the t for horizontals in a cubic bezier segment.
@LettError
LettError / sortSpaceCenter.py
Last active January 22, 2024 08:33
Controls for sorting the content of a RoboFont spacecenter.
# coding: utf-8
# menuTitle : Sort Space Center
import ezui
from random import shuffle
from glyphNameFormatter.reader import u2c
from mojo.UI import CurrentSpaceCenter, splitText, OpenSpaceCenter
"""
Take the glyphs from the current spacecenter
@LettError
LettError / previewFont_to_spacecenter.py
Created December 8, 2023 09:21
Generate a preview font with the current designspace and show it in the current spacecenter
from fontTools.designspaceLib import InstanceDescriptor
from mojo.UI import CurrentSpaceCenter
# Scripting with live designspaces
# demo [email protected] 8.12.2023
# have a desigspace open in DSE2
d = CurrentDesignspace()
# have a spacecenter open
@LettError
LettError / responsive_drawbot_animated.py
Created December 4, 2023 11:19
Drawbot output for responsive lettering UFO
#
# script for drawbot extension in robofont
# draws a fitted / interpolating image from a responsive lettering ufo
# [email protected] / 20231204
def ip(a, b, f):
return a + f * (b-a)
page = (659, 500) # image size
margin = 59 # nice to have a margin
@LettError
LettError / LTR_NCND_animation_drawbot_demo.py
Created October 29, 2023 07:30
Drawbot animation with LTR NCND Variable.
# another animation generator
# for NCND fun only
# 2023 letterror.com
# the number of frames for this animation
frames = 25
# margin, in pixels
@LettError
LettError / typo.social.iconGenerator.py
Created May 25, 2023 10:13
icon generator for drawbot
side = 500
steps = 100
clrs = [(1,.6,0),(0,0.3,.2)]
stack = 1000
for r in range(2):
d = 300 * side
for i in range(steps):
newPage(side,side)
@LettError
LettError / scriptingSimilarity.py
Created April 20, 2022 09:02
This shows how to call the similarity extension to find similar glyphs to the current. Needs https://github.com/LettError/similarity to be installed.
import cosineSimilarity
from cosineSimilarity import cosineSimilarity, SimilarGlyphsKey
print('SimilarGlyphsKey', SimilarGlyphsKey)
g = CurrentGlyph()
font = CurrentFont()
@LettError
LettError / rescueImages.py
Created November 23, 2021 21:31
Script for Robofont - copy unreferenced images from the ufo to a new folder, then delete them from the ufo.
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 October 22, 2021 10:13
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.
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 October 12, 2021 10:10
Horizontal scaling while preserving the italic angle. (by "unskewing" the geometry to "upright", then scaling, then "reskewing" back to the italic angle)
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):