Skip to content

Instantly share code, notes, and snippets.

View anthrotype's full-sized avatar
🤔
debating umlauts

Cosimo Lupo anthrotype

🤔
debating umlauts
  • London
View GitHub Profile
@anthrotype
anthrotype / sample_mark_mkmk_features.py
Created September 14, 2023 10:30
sample_mark_mkmk_features.py
from ufo2ft.featureWriters.markFeatureWriter import MarkFeatureWriter
from fontTools.feaLib.ast import FeatureFile
from ufoLib2 import Font
fea = FeatureFile()
font = Font()
a = font.newGlyph("a")
a.appendAnchor({"name": "top", "x": 500, "y": 600})
@anthrotype
anthrotype / add_fvar_axis.py
Last active June 6, 2023 10:22
Script to append a new axis to fvar and related variation tables
import sys
import argparse
import logging
from fontTools.ttLib import TTFont
from fontTools.ttLib.tables._f_v_a_r import Axis
from fontTools.varLib.builder import buildVarRegionAxis
log = logging.getLogger("add_fvar_axis.py")
"""
The contours from https://gist.github.com/rsheeter/cef6cf71fa9e519c94f9f0d23906e5de are in fact not compatible
and this even before we attempt to reverse them.
See https://github.com/fonttools/fonttools/issues/3093
"""
from ufoLib2 import Font
from ufo2ft import compileInterpolatableTTFs
@anthrotype
anthrotype / get_gvar_masters.py
Created April 13, 2022 15:11
Print all the glyph 'master' locations from a variable TTF (user-scale coordinates).
"""Print all the glyph 'master' locations from a variable TTF (user-scale coordinates).
A 'master' along a given axis is where a delta-set region peaks.
"""
from fontTools.varLib.models import piecewiseLinearMap
def map_axis_values(axis_mappings, location):
return {
import logging
import shutil
import os
from fontTools.misc.loggingTools import Timer
import orjson
from ufoLib2.converters import json_converter as c
from ufoLib2.objects import Font
@anthrotype
anthrotype / freeze_requirements.py
Created June 25, 2021 18:41
Similar to pip freeze, but only listing the installed dependencies for the selected package.
"""
Similar to pip freeze, but only listing the installed dependencies for the selected package.
E.g.:
$ python freeze_requirements.py fonttools[ufo]
# Installed requirements for 'fonttools[ufo]' (5 in total):
appdirs==1.4.4
fonttools==4.24.4
fs==2.4.13
@anthrotype
anthrotype / glyf2svg.py
Created November 12, 2020 19:14
Convert TrueType glyph outline to SVG
#!/usr/bin/env python3
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@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
@anthrotype
anthrotype / remove_unused_symbols.py
Created June 10, 2020 17:26
strip unused <symbol> elements in noto-emoji svgs
import sys
import glob
from lxml import etree
svg_directory = sys.argv[1]
noid_files = set()
id_files = set()
for filename in glob.glob(f"{svg_directory}/*.svg"):
tree = etree.parse(filename)
@anthrotype
anthrotype / scale_ufo.py
Last active June 4, 2020 14:39
Script that uses ufo2ft (>= 2.14) TransformationsFilter to scale the UPEM of a UFO
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,