Skip to content

Instantly share code, notes, and snippets.

@benkiel
benkiel / draw_glyph.py
Created September 25, 2024 19:34
Draw a glyph in drawbot extension
f = CurrentFont()
glyphName = "a"
size = 1080
newPage (size,size)
black = 0,0,0
red = 1,0,0
green = 0,1,0
blue = 0,0,1
white = 1,1,1
pointshape = oval #oval or rect
@typoman
typoman / segment symbols pen.py
Last active September 18, 2024 10:54
A pen class for converting glyph outlines into symbolic representations. The resulting string can be used for quick visual comparison or analysis of glyph shapes without rendering the full outline.
from typing import Tuple, Optional
from fontTools.pens.basePen import BasePen
from fontTools.misc.arrayTools import calcBounds
import math
def round_angle_to_step(angle: float, degree: int) -> int:
"""
Rounds an angle to the nearest degree increment.
Args:
@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 January 8, 2025 13:29
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 August 20, 2024 23:42
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