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 / 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 / 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 / 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
--- 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 / 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"}
import string
import sys
from pprint import pprint
try:
Glyphs
except NameError:
IN_GLYPHS_APP = False
else:
IN_GLYPHS_APP = True
# Common structure for GPOS, GSUB
{
"Version": int,
"Scripts": [
{
"Tag": str,
"DefaultLangSys": {
"ReqFeatureIndex": int, # is it always 0xFFFF?
"FeatureIndices": List[int]
#!/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
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")
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.