Skip to content

Instantly share code, notes, and snippets.

library(readr)
library(dplyr)
library(ggplot2)
library(tidyr)
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)
@simoncozens
simoncozens / interrofont.py
Created April 3, 2020 11:18
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()
parser.add_argument("input",
help="font file to process", metavar="FILE")
parser.add_argument('-n', "--name", action='store_true',
from tensorfont.dataset import prepare_training_data
from tensorfont.generators import RandomPair
prepare_training_data()
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
simoncozens / cmap-survey.py
Created July 10, 2020 10:44
Survey CMAP tables of installed fonts
from fontTools.ttLib import TTFont
import glob
from tabulate import tabulate
import os
import random
paths = [
os.path.expanduser("~/Library/Fonts"),
"/Library/Fonts",
@simoncozens
simoncozens / JSTFBuilder.py
Created January 10, 2020 16:42
JSTF Table builder
#!/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
# Dot a Glyph
from fontTools.ttLib import TTFont
from beziers.path import BezierPath
from beziers.path.representations.fontparts import FontParts
from fontParts.world import *
from beziers.point import Point
from beziers.path.geometricshapes import Circle
import sys
# Dot a Glyph
# Copyright 2019 Simon Cozens
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
@simoncozens
simoncozens / proof-headlines.py
Created March 5, 2021 13:28
A quick and dirty bit of python to dump out headlines containing certain characters
import requests
from urllib.parse import urlencode
languages = ["en"]
doneglyphs = " ABCDEFGHIJKLMNOPRQSTUVXYZabcdefghijklmnopqrstuvwxyz0123456789.,-"
API_TOKEN = "Use your own, not mine."
def get_a_page_of_headlines(page):
params = urlencode(
{"api_token": API_TOKEN, "languages": ",".join(languages), "page": page}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@simoncozens
simoncozens / HTKerner.py
Created February 1, 2019 15:42
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