Skip to content

Instantly share code, notes, and snippets.

@chrissimpkins
chrissimpkins / glyph-coord-check.py
Last active November 25, 2019 22:30
Check coordinates in font glyphs vs. x and y Min + Max value definitions defined in the glyph header (glyf table)
#!/usr/bin/env python3
# ---------------------------------------------------------------------------
# Copyright 2019 Christopher Simpkins
# Apache License, v2.0
#
# Portions of this source file are derived from the
#
# `com.google.fonts/check/points_out_of_bounds`
#
@chrissimpkins
chrissimpkins / hexcheck.py
Created November 7, 2019 19:01
Unicode hex value checks in cmap tables (fonts)
tt = TTFont(fontpath)
cmap = tt.getBestCmap()
# now the integers are keys in the cmap object and can be used to compare against hexadecimal values for presence in a font
test_list = (hex1, hex2, hex3,...)
# how to split hex ranges to individual hex codes
# e.g., 0x0020-0x0028
for x in range(0x0020,0x0028):
@chrissimpkins
chrissimpkins / Makefile
Created September 20, 2019 18:34
Example Makefile for font projects
# define project name
PROJECT=replaceme-with-project-name
# define path to the font build directory for tests
FONT_DIR="/path/to/font/file/directory"
venv:
python3 -m venv ~/venv/$(PROJECT)
# can't activate and deactivate from Makefile
# because it runs new subshells for each
@chrissimpkins
chrissimpkins / fontelemetry_demo.py
Last active July 16, 2019 18:35
fontelemetry demo source
# Copyright 2019 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@chrissimpkins
chrissimpkins / diff.sh
Created April 2, 2019 17:13
Diff OpenType tables in font files (with color if colordiff is installed)
#!/bin/bash
# Copyright 2018 Source Foundry Authors
# MIT License
# compare fonts with ttx
ttdiff () {
if [ "$#" -lt 2 ]
then
echo "Usage: ttdiff FONT1.ttf FONT2.ttf [tables ...]"
@chrissimpkins
chrissimpkins / mutator-fix.py
Last active February 14, 2019 04:06
mutator-fix.py
# snip: https://github.com/fonttools/fonttools/blob/51a49de3eda4c10df29ceba85a90e7d7378137e8/Lib/fontTools/varLib/mutator.py#L303-L310
if glyf:
for glyph in glyf.glyphs.values():
if hasattr(glyph, "program"):
instructions = glyph.program.getAssembly()
# If GETVARIATION opcode is used in bytecode of any glyph add IDEF
addidef = any(op.startswith("GETVARIATION") for op in instructions)
if addidef:
break
@chrissimpkins
chrissimpkins / subset.sh
Created January 17, 2019 16:29
pyftsubset example
pyftsubset FONTPATH.ttf unicodes=U+XXXX-U+XXXX --name-ids=3,4,6 --no-ignore-missing-unicodes --hinting --verbose --output-file=OUT_FONTPATH.ttf
@chrissimpkins
chrissimpkins / CustomFilter.plist
Created January 11, 2019 22:17
CustomFilter.plist for Google Fonts glyph sets (Glyphs text editor)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>name</key>
<string>Incompatible Master</string>
<key>predicate</key>
<string>mastersCompatible == 0</string>
</dict>
@chrissimpkins
chrissimpkins / bokehjs-licenses.md
Created December 24, 2018 04:07
bokehjs-licenses.md

License List

Generated with the following command in the bokeh repository bokehjs directory after executing npm install:

$ npx license-checker --production --csv
"module name","license","repository"
"@types/es6-promise@3.3.0","MIT","https://github.com/jakearchibald/ES6-Promise"
@chrissimpkins
chrissimpkins / cache-py.sh
Last active September 13, 2018 03:37
cache-py.sh
#!/usr/bin/env bash
#-----------------------------------
## put in an after job
## bash ./cache-py.sh 3.7.0
#-----------------------------------
py_ver=${1:-'3.7.0'}
py_dir="py$py_ver"
py_path="$SEMAPHORE_CACHE_DIR/$py_dir"