Skip to content

Instantly share code, notes, and snippets.

@typoman
typoman / intersectPen.py
Created February 7, 2024 16:58
Get intersection points of list of lines with a glyph in a font
from fontTools.pens.basePen import BasePen
from fontTools.misc.bezierTools import calcCubicParameters, solveCubic, _alignment_transformation, cubicPointAtT, _line_t_of_pt, linePointAtT
def _curve_line_intersections_t(curve, line):
aligned_curve = _alignment_transformation(line).transformPoints(curve)
a, b, c, d = calcCubicParameters(*aligned_curve)
intersections = solveCubic(a[1], b[1], c[1], d[1])
return sorted(i for i in intersections if 0.0 <= i <= 1)
def curveLineIntersections(curve, line):
@connordavenport
connordavenport / drawbotMarkdown.py
Last active August 9, 2023 14:13
A WIP script to add markdown functionality to DrawBot.
import re
sampleText = '''
A spectre is haunting [Europe](www.robofont.com) — the spectre of **communism**. All the __powers of old Europe have__ entered into a holy alliance to exorcise this spectre: Pope and Tsar, Metternich and Guizot, French Radicals and German police-spies.
Where is the party in opposition that has not been decried as communistic by its opponents in power? Where is the opposition that has not hurled back the branding reproach of **communism**, against the more advanced opposition parties, as well as against its reactionary adversaries?
Two things result from this fact:
I. **Communism** is *already acknowledged* by all _European_ powers to be itself a power.
@hyperupcall
hyperupcall / settings.jsonc
Last active May 13, 2024 22:21
VSCode config to disable popular extensions' annoyances (telemetry, notifications, welcome pages, etc.)
// I'm tired of extensions that automatically:
// - show welcome pages / walkthroughs
// - show release notes
// - send telemetry
// - recommend things
//
// This disables all of that stuff.
// If you have more config, leave a comment so I can add it!!
{

OpenType font name table notes

Provided are the name table record ID and instructions on how to fill it out. Arial is used as an example to show how the names records can be filled. You can see the example records here:

https://learn.microsoft.com/en-us/typography/opentype/spec/namesmp

There are also more exmaples added to the bottom of this file.

Why this document?

@justvanrossum
justvanrossum / convert_ds_to_ds5.py
Created September 15, 2022 11:55
Likely incomplete script that converts 'statmake' axis labels to DesignSpace 5 axis labels
import argparse
import sys
from fontTools.designspaceLib import AxisLabelDescriptor, DesignSpaceDocument
def main():
parser = argparse.ArgumentParser(
description="Converts statmake axis labels to DesignSpace 5.0 axis labels"
)
parser.add_argument("input", help="The source .designspace file")
@arrowtype
arrowtype / draw-glyph-outline.drawbot.glyphsapp.py
Last active March 29, 2024 16:51
For DrawBot in GlyphsApp: Draw a glyph's outlines & nodes, for presentation / social media purposes
"""
Script to create an image of a glyph in the current layer.
Instructions:
- Use within the Drawbot plugin of GlyphsApp.
- Get this plugin via Window > Plugin Manager, then search for "Drawbot" and install it.
- Then, go to File > New Drawbot, and paste in this code and run it.
- You may need to restart glyphs for the Plugin to work.
@chmanie
chmanie / connectall.rb
Created January 26, 2021 18:02
Connect all MIDI inputs to all MIDI outputs (except themselves). Supports multi-port devices
#!/usr/bin/ruby
t = `aconnect -i -l`
$devices = {}
$device = 0
t.lines.each do |l|
match = /client (\d*)\:((?:(?!client).)*)?/.match(l)
# we skip empty lines and the "Through" port
unless match.nil? || match[1] == '0' || /Through/=~l
$device = match[1]
@anthrotype
anthrotype / remove-overlaps.py
Last active May 10, 2023 13:42
script to remove overlaps from TTF with fonttools and skia-pathops
#! /usr/bin/env python3
# Example script to remove overlaps in TTF using skia-pathops
import sys
from fontTools.ttLib import TTFont
from fontTools.pens.recordingPen import DecomposingRecordingPen
from fontTools.pens.ttGlyphPen import TTGlyphPen
@frankrolf
frankrolf / write_glyphs_as_images.py
Last active June 10, 2023 05:26
DrawBot script to write image files for each glyph contained in a given font file
# use absolute or relative path. This can be OTF or TTF.
font_path = 'my_font.otf'
# set the current font to be the one specified above, so we can list its glyph names:
font(font_path)
# loop through the list of glyph names:
for gid, g_name in enumerate(listFontGlyphNames()):
# the new page is 1000 by 1000 points by default
newPage()
fs = FormattedString(
font=font_path,
@alpha-cactus
alpha-cactus / meadowphysics_lib.lua
Last active January 5, 2019 21:53
meadowphysics norns
local mp = {}
mp.__index = mp
mp.MODE_POSITION = 0
mp.MODE_SPEED = 1
mp.MODE_RULES = 2
local mp_set = {}
mp_set.__index = mp_set