Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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}
# 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,
# 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
@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",
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 / 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',
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 / 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
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