Skip to content

Instantly share code, notes, and snippets.

@arrowtype
Last active July 31, 2023 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arrowtype/6610a554ab126b455498305827629dcc to your computer and use it in GitHub Desktop.
Save arrowtype/6610a554ab126b455498305827629dcc to your computer and use it in GitHub Desktop.
A Python script to set ufo2ft filters in UFOs, in order to run them on FontMake builds
"""
A script to set ufo2ft filters for all fonts in a directory.
DIRECTIONS: Set up the dict below with filters you would like to use in your UFO builds. Then, run it in the command
line like this, replacing the <content surrounded by angle brackets> with relavent paths:
python3 "<path_to_this_script>/add-ufo2ft-filters-to-ufos_in_dir.py" "<path_to_a_folder_containing_UFO_fonts>"
See https://github.com/googlefonts/fontmake/blob/a4c83a0693ae7c629db9385a9e68d8641d85718e/USAGE.md#outline-filtering
for more information.
LICENSE: MIT license
"""
import sys
import os
from fontParts.world import *
import ufonormalizer
sourceFolderPath = sys.argv[1]
for fileName in os.listdir(sourceFolderPath):
if fileName.endswith(".ufo"):
ufoPath = os.path.join(sourceFolderPath, fileName)
print(ufoPath)
f = OpenFont(ufoPath, showInterface=False)
f.lib["com.github.googlei18n.ufo2ft.filters"] = [
{
'name': 'decomposeTransformedComponents',
'pre': 1
},
{
'name': 'flattenComponents',
'pre': 1
},
{
'name': 'propagateAnchors',
'pre': 1
},
]
f.save()
ufonormalizer.normalizeUFO(ufoPath, writeModTimes=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment