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 / 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 October 3, 2025 15:52
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,
import os
import sys
__requires__ = ["pdfminer.six"]
from pdfminer.psparser import LIT
from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
from fontTools import designspaceLib
import os.path
# define axes names, tags and min/default/max
AXES = [
dict(name="Weight", tag="wght", minimum=400, default=400, maximum=700),
dict(name="Width", tag="wdth", minimum=50, default=100, maximum=100),
]
from fontTools import designspaceLib
import ufo2ft
import ufoLib2
UPEM = 1000
WIDTH = UPEM // 2
FAMILY_NAME = "MyAwesomeVariableFont"
import sys
from ufo2ft.constants import *
from ufoLib2 import Font
UPEM = 1000
WIDTH = UPEM // 2
def _layer(font, name):
try:
from glyphsLib import GSFont
# 'offcurve' GSNode.type is equivalent to 'None' in UFO PointPen API
_UFO_NODE_TYPES = {"line", "curve", "qcurve"}
def drawGSLayerWithPointPen(layer, pointPen):
""" Draw a Glyphs layer with a FontTools PointPen.