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
import sys
from fontTools import ttLib
from fontTools.ttLib.tables import sbixStrike
from fontTools.ttLib.tables import sbixGlyph
ttfont = ttLib.TTFont()
# https://docs.microsoft.com/en-us/typography/opentype/spec/sbix
sbix = newTable("sbix")
#!/usr/bin/env python3
"""Create a COLR/CPAL font from a set of SVGs.
Sample usage:
make_colr_font.py -o font.ttf $(find ~/oss/noto-emoji/svg -name '*.svg' | head -10)
"""
import argparse
from collections import namedtuple
import itertools
import logging
# Common structure for GPOS, GSUB
{
"Version": int,
"Scripts": [
{
"Tag": str,
"DefaultLangSys": {
"ReqFeatureIndex": int, # is it always 0xFFFF?
"FeatureIndices": List[int]
import string
import sys
from pprint import pprint
try:
Glyphs
except NameError:
IN_GLYPHS_APP = False
else:
IN_GLYPHS_APP = True
@anthrotype
anthrotype / google-ocr.py
Last active October 1, 2019 15:45
Script to run Google Drive's OCR on a batch of image files
import argparse
from datetime import datetime
import os
import subprocess
import logging
FILE_EXTENSIONS = {".jpg", ".png", ".pdf"}
--- XXX_VF_Latn_WghtWdth-VF.ttx 2019-06-06 18:30:12.002485552 +0100
+++ XXX_VF_Latn_WghtWdth-VF_2.ttx 2019-06-07 16:15:35.576124762 +0100
@@ -667,12 +667,12 @@
<!-- Most of this table will be recalculated by the compiler -->
<tableVersion value="1.0"/>
<fontRevision value="1.0"/>
- <checkSumAdjustment value="0x99bcc445"/>
+ <checkSumAdjustment value="0xb41a5347"/>
<magicNumber value="0x5f0f3cf5"/>
<flags value="00000000 00001011"/>
@anthrotype
anthrotype / list_vf_regions.py
Created February 28, 2019 06:04
List/count tuple variation regions in gvar table
import sys
import pprint
from collections import OrderedDict, Counter
import fontTools
from fontTools import ttLib
log = fontTools.log
@anthrotype
anthrotype / merge_cff.py
Created July 27, 2018 14:06
Merge CFF table processed by afdko's tx tool back into OTF
"""Script to read a CFF table in binary format as produced by afdko's tx tool
and merge it into an existing OpenType/CFF font, replacing the current CFF
table with the other.
E.g. you can generate a OTF with fontmake with the --keep-overalaps or
--no-subroutinize options, then use tx to remove overlaps or subroutinize the
CFF table, and finally merge the result back into the original font:
$ fontmake -u MyFont.ufo \
--no-subroutinize \
@anthrotype
anthrotype / optimize_glyph_order.py
Created July 26, 2018 11:23
Sort glyphs in UFO by increasing Unicode codepoint
"""Sort glyphs in UFO by increasing Unicode codepoint to try shrinking the
size of the cmap table.
"""
import sys
from defcon import Font
try:
font = Font(sys.argv[1])
except IndexError:
sys.exit("usage: optimize_glyph_order.py FONT.ufo")
@anthrotype
anthrotype / ttfautohint.rb
Last active July 21, 2018 14:23
Modified ttfautohint homebrew formula to build with latest macOS High Sierra and Qt 5.11
# $ brew install --build-from-source --HEAD --with-qt /path/to/local/modified/formula/ttfautohint.rb
class Ttfautohint < Formula
desc "Auto-hinter for TrueType fonts"
homepage "https://www.freetype.org/ttfautohint"
url "https://downloads.sourceforge.net/project/freetype/ttfautohint/1.8.1/ttfautohint-1.8.1.tar.gz"
sha256 "12df5120be194d2731e2a3c596892aa218681614c4f924e24279baf69bb7d4f9"
bottle do
cellar :any