Skip to content

Instantly share code, notes, and snippets.

View arrowtype's full-sized avatar

Stephen Nixon arrowtype

View GitHub Profile
@arrowtype
arrowtype / make-blank-glyphs-in-ttf.py
Last active February 28, 2022 23:05
A script to make all glyphs in a TTF blank, while leaving metrics, features, etc in place.
"""
A script to make all glyphs in a TTF blank, while leaving metrics, features, etc in place.
"""
from fontTools import ttLib
from fontTools.ttLib.tables._g_l_y_f import Glyph
from argparse import ArgumentParser
def eraseGlyphs(fontPath, inplace=False):
@arrowtype
arrowtype / split-kerning-group-allfonts.py
Last active February 11, 2022 21:57
RoboFont script to split glyphs from a kern group, but keep kerning (so you can fix it without disrupting it too much)
"""
Split glyphs from a given kerning group, but keep kerning
so you don’t lose a bunch of almost-correct kerns.
(Slightly
E.g. If you need to split "e" glyphs out of the "o" group.
USAGE:
- set originalGroupName (group to split from)
@arrowtype
arrowtype / 1--orient-glyph-contours-UFOs_in_dir.py
Last active January 25, 2022 18:48
Go through UFOs in directory and orient contour paths in a counter-clockwise direction. See https://github.com/googlefonts/fontmake/issues/846
"""
⚠️⚠️⚠️
OOPS. Don’t use this. FontParts already has BaseGlyph.correctDirection()
⚠️⚠️⚠️
Go through UFOs in directory and orient contour paths in a counter-clockwise direction,
as they should be for cubic/postscript/CFF/"OTF" curves.
DEPENDENCIES:
@arrowtype
arrowtype / italic-shift.py
Created December 1, 2021 22:46
A snippet to determine how much horizontal shift a point should get in an italic glyph, in a UFO font.
"""
Here’s a snippet to determine how much horizontal shift a point should get in an italic glyph.
In practical terms, I have just used this to shift anchors in a UFO font source, in order to prepare an oblique font.
Basically, how can we determine "x" below, given a height ("y") and an angle (italicAngle)?
x
• - - •
| /
@arrowtype
arrowtype / remove-selected-glyphs-from-currentfont.py
Last active December 15, 2021 15:45
A script to nuke selected glyphs from the Current Font in RoboFont
"""
Removes currently selected glyphs from current font.
Also removes these glyphs from groups, kerning, and components.
Includes template glyphs in selection and removal.
"""
f = CurrentFont()
@arrowtype
arrowtype / find-n-fix-unintended-kerning-exceptions.py
Last active August 26, 2021 15:37
RoboFont script to find unexpected kerning exceptions in a UFO, then remove those kerns and replace them with kerns using groups.
"""
Find kerning exceptions in a UFO, then remove those kerns and replace them with kerns using groups.
Why?
Sometimes, if you add kerning to a font early, you can wind up with unexpected kerning exceptions
when you add new characters to the font. E.g. ('G', 'asterisk') makes sense until you add 'Gbreve'.
USAGE:
Configure side1_ignore & side2_ignore lists below, then run this script in RoboFont.
- It won’t autosave your UFOs, because you should probably review the results before saving.
@arrowtype
arrowtype / check-glyphset.py
Created August 3, 2021 22:31
A simple way to compare the unicodes currently covered by a font binary to GF Glyph Sets.
"""
A simple way to compare the unicodes currently covered by a font binary to GF Glyph Sets.
Doesn’t account for glyphs that don’t have unicodes, such as most ligatures, case-specific puncutation, etc.
Glyph Sets copied and adjusted from:
https://github.com/googlefonts/gftools/tree/3aefd92ba3f9ab5355de472a4cb1e4b19c1a3b2e/Lib/gftools/encodings/GF%20Glyph%20Sets#google-fonts-2016-glyph-sets
Usage:
@arrowtype
arrowtype / add-STAT.py
Created June 25, 2021 19:17
Example STAT-adding script for a typeface with split Roman/Italic variable fonts
"""
python3 src/build-scripts/helpers/add-STAT-display_only.py <build_directory>
...where <build_directory> is a folder containing two variable fonts, e.g. Family-Variable.ttf and FamilyItalic-Variable.ttf
This file is adapted from an example originally in https://github.com/Omnibus-Type/Texturina
"""
from fontTools.otlLib.builder import buildStatTable, _addName
from fontTools.ttLib import TTFont
@arrowtype
arrowtype / print-character-set.robofont.py
Created April 11, 2021 21:41
A RoboFont script to print all characters in a font that have a unicode value.
"""
A RoboFont script to print all characters in a font that have a unicode value.
"""
f = CurrentFont()
unicodes = []
for name in f.keys():
if f[name].unicodes != () and f[name].width != 0:
@arrowtype
arrowtype / README.md
Last active April 7, 2021 17:34
An example script that adds a starter set of anchors to one or more UFOs. This must be run in RoboFont, but could be easily adapted to run via the command line only.

Add (starter) anchors to UFO(s)

An example script that adds a starter set of anchors to one or more UFOs.

This is intended to save time clicking around and typing to add anchors to glyphs across one or multiple sources of a font project. You will still need to go through the glyphs to refine the positioning of anchors after running this script, as positions are only rough guesses.

You can remix/extend the script to add anchors to more glyphs, add special anchors to certain glyphs at certain positions, and more.

This script is intended to be run in RoboFont, but it could be easily adapted to run via the command line only, using the FontParts API.