Skip to content

Instantly share code, notes, and snippets.

@simoncozens
simoncozens / debug-merge.py
Created January 31, 2024 09:40
Helper script to debug merge issues in fonttools -o variable
from glyphsLib import load, to_designspace
from ufo2ft.featureCompiler import FeatureCompiler, parseLayoutFeatures
from fontTools.feaLib import ast
import argparse
class Checker:
def __init__(self, sources):
self.masters = []
for source in sources:
@simoncozens
simoncozens / sparsify.py
Last active April 26, 2024 17:48
sparsify.py - turn masters into sparse masters
import uuid
from glyphsLib import load, GSPath, GSNode, GSLayer
from fontTools.varLib.models import VariationModel, normalizeValue
import numpy as np
from tqdm import tqdm
import argparse
def interpolate_paths_without(glyph, intermediate_layer, intermediate_location):
tags = [axis.axisTag for axis in glyph.parent.axes]
#!/opt/homebrew/bin/python3
import sys
sys.path.insert(0, "/Users/simon/others-repos/ufo2ft/Lib")
from glyphsLib.classes import GSFont
from glyphsLib.builder import UFOBuilder
from glyphsLib.builder.font import fill_ufo_metadata
from fontmake.font_project import FontProject
from timeit import default_timer as timer
import requests
from dateutil.relativedelta import relativedelta, FR
from datetime import datetime
import os
lastweek = datetime.utcnow().replace(hour=0,microsecond=0) + relativedelta(weekday=FR(-1))
headers = {"Authorization": "bearer "+os.environ["GITHUB_TOKEN"]}
def run_query(query):
import sys
import os
DEFAULT_NGRAM_SIZE = 5
def all_ngrams(word, size=None):
if size is None:
size = DEFAULT_NGRAM_SIZE
for i in range(max(1, len(word) - size)):
from fontTools.ttLib import TTFont
from fontTools.ttLib.tables.otBase import OTTableWriter
import sys
from fontTools.feaLib.lookupDebugInfo import LOOKUP_DEBUG_INFO_KEY
font = TTFont(sys.argv[1])
def locate(table, ix):
if "Debg" not in font:
return str(ix)

Justification with Variable Fonts

  • In JSTF header
Type Name Description
uint16 majorVersion Major version of the JSTF table, = 1
uint16 minorVersion Minor version of the JSTF table, = 0
uint16 jstfScriptCount Number of JstfScriptRecords in this table
JstfScriptRecord jstfScriptRecords[jstfScriptCount] Array of JstfScriptRecords, in alphabetical order by jstfScriptTag
@simoncozens
simoncozens / threed.py
Created October 6, 2022 10:43
Three-dimensional colour variable fonts
import numpy as np
import matplotlib.pyplot as plt
import math
from babelfont import Font, Layer, Shape, Master, Node, Axis, Glyph
import uuid
from lottie2vf.paintcompiler import compile_paints
from fontTools.ttLib import TTFont
glyph_pts = {
@simoncozens
simoncozens / noto-static.json
Created July 28, 2022 14:41
Operation-level timing of static instance generation
[
{
"format": "designspace",
"glyphs": 3304,
"instances": 2,
"masters": 2,
"name": "arimo",
"succeeded": true,
"timings": [
[
@simoncozens
simoncozens / noto-variable.json
Created July 28, 2022 11:09
Operation-level timings for building variable fonts
[
{
"format": "designspace",
"glyphs": 3304,
"instances": 2,
"masters": 2,
"name": "arimo",
"succeeded": false,
"timings": [
[