Skip to content

Instantly share code, notes, and snippets.

simoncozens /
Created Jul 10, 2020
Survey CMAP tables of installed fonts
from fontTools.ttLib import TTFont
import glob
from tabulate import tabulate
import os
import random
paths = [
from tensorfont.dataset import prepare_training_data
from tensorfont.generators import RandomPair
def kern_generator():
rpg = RandomPair(196, 196, 76, "training")
gen = rpg.generator()
while True:
font, left, right = next(gen)
img1, perturbation = rpg.get_image(font, left, right, perturbation_range= [-100,100])
simoncozens /
Created Apr 3, 2020
Interrofont: Show various data about a font from the command line
#!env python3
import sys
from fontTools.ttLib import TTFont
from argparse import ArgumentParser
import itertools
parser = ArgumentParser()
help="font file to process", metavar="FILE")
parser.add_argument('-n', "--name", action='store_true',
View ncov2019.r
logTicks <- function(n = 5, base = 10){
# Divisors of the logarithm base. E.g. for base 10: 1, 2, 5, 10.
divisors <- which((base / seq_len(base)) %% 1 == 0)
mkTcks <- function(min, max, base, divisor){
f <- seq(divisor, base, by = divisor)
#!/usr/bin/env python
# Builds a JSTF table from specially named features
# To use:
# First, set up the features in your font.
# You may add as many or as few features as you like, but they must conform
# to the following naming convention:
# exs1: First priority extension substitution.
# i.e. the first rules we try to substitute glyphs to make the line longer
# exp1: First priority extension positioning.
# i.e. the first rules we try to reposition glyphs to make the line longer
View IUP Optimizer Test
from __future__ import print_function, division, absolute_import
from fontTools.misc.py23 import *
from fontTools.ttLib import TTFont
from Lib.fontTools.varLib.iup import iup_delta_optimize, _iup_contour_bound_forced_set
font = TTFont("NotoSerifHebrew-GX.ttf")
gvar = font["gvar"]
glyf = font["glyf"]
total = 0
simoncozens /
Created Feb 1, 2019
HT LetterKerner, first draft
#MenuTitle: HT LetterKerner
# Put this in your HTLetterSpacer script directory so it can find
# the library.
# Todo:
# Does not handle whole-font yet.
# Does not know or care about kerning groups.
# The reference glyph should be adjusted based on the letter pair
# - "n" works well for lowercase-lowercase
simoncozens /
Created May 31, 2018
Keras callback for signal handing
# In your model:
# from SignalHandler import SignalHandler
# callbacks=[..., SignalHandler()])
# kill -USR1 $KERAS_PROCESS # Drop learning rate x0.1
# kill -USR2 $KERAS_PROCESS # Save model immediately
# kill $KERAS_PROCESS # Terminate at end of epoch
from keras import backend as K
from keras.callbacks import Callback
simoncozens /
Created Sep 27, 2016
OpenType Variation Instance Generator
from fontTools.misc.py23 import *
from fontTools.ttLib import TTFont
import sys
import argparse
parser = argparse.ArgumentParser(description="OpenType Variation Instance Generator")
parser.add_argument('font', help="font file")
parser.add_argument('-a', '--all', action="store_true", help="Generate all instances")
parser.add_argument('-o', '--output', help="Output directory", default = ".")
simoncozens /
Last active Oct 7, 2020
Harmonizing two Bezier curves

To harmonize (with G2 curvature) two cubic Bézier curves a0,a1,a2,a3 and b0,b1,b2,b3 where a2, a3 = b0, and b1 are colinear:

  • First find d = intersection point of line a1--a2 and line b1--b2.
  • Now find ratios p0 = |a1, a2| / |a2, d| and p1 = |d1, b1| / |b1, b2|.
  • Determine ratio p = sqrt(p0 * p1)
  • Now set position of a3 = b0 such that |a2, a3| / |a3, b1| == p.
  • To do this, set t = p / (p+1).
  • Adjust the position of a3=b0 so that it sits t of the way between a2 and b1.

Of course, you may prefer to keep the position of a3 because it's the on-curve point. Fine. Instead, compute where a3 should go according to this algorithm, work out the delta between the new position and the current position, and apply that delta to the handles a2 and b1 instead.

You can’t perform that action at this time.