Skip to content

Instantly share code, notes, and snippets.

@m4rc1e
m4rc1e / metrics_compatible.py
Created April 14, 2023 10:08
Check whether two fonts are metrics compatible by testing on random strings
import random
import string
import uharfbuzz as hb
import sys
from fontTools.ttLib import TTFont
def generate_random_string(fp):
f = TTFont(fp)
cmap = f.getBestCmap()
length = random.randint(3, 100)
@m4rc1e
m4rc1e / fontbakery_sample.py
Last active August 6, 2021 12:45
gf draft rearchitecture
@condition
...
def gf_family(ttFont):
from gfcore.font import family_name
from gfcore.site import download_family, family_exists
name = family_name(ttFont)
if family_exists(name):
return download_family(name)
return None
@m4rc1e
m4rc1e / gpos.txt
Last active February 11, 2020 11:44 — forked from anthrotype/gist:2539c6c6d56797b50abf19d64a4daee1
OTL json schema
# Lookup type 1: Single Adjustment Positioning
# format 1: Single Positioning Value & format 2: Array of Positioning Values
{
'format': int,
'valueRecord': [
{"a": {"XPlacement": 0, "XAdvance": 10, "YPlacement": 0, "YAdvance": 0},
...
}
@m4rc1e
m4rc1e / fb_fresh.sh
Last active September 11, 2018 13:34
WIP: Shell script to install Fontbakery from stock OSX install
set -e
# Install homebrew
if ! [ -x "$(command -v brew)" ]; then
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
echo "Homebrew already installed! skipping."
fi
# Install python3
"""Compare Comfortaa production against Comfortaa VF in sandbox"""
from diffbrowsers.screenshot import ScreenShot
from diffbrowsers.utils import gen_diff_gif, load_browserstack_credentials
from glob import glob
import os
OFFICIAL_FONTS = 'https://output.jsbin.com/moranexova'
SANDBOX_VF_FONT = 'https://output.jsbin.com/xawawuluvo'
@m4rc1e
m4rc1e / add_avar.py
Created June 29, 2018 17:07
Add an avar table to a variable font
"""
Add an avar table to a VF font. This is often needed for VF fonts generated with glyphsapp
Please note: this script requires the same dependencies as fontmake, https://github.com/googlei18n/fontmake
For testing avar table see script, https://github.com/googlefonts/gftools/blob/master/bin/gftools-check-vf-avar.py
TODO (GF team) File issue on Glyphsapp if glyphsapp does not generate avar table by default.
# -*- coding: utf-8 -*-
import requests
r = requests.get('https://api.github.com/repos/google/fonts/issues?milestone=2&per_page=100')
print('Title,Url,Date')
for issue in r.json():
if not issue['closed_at']:
print('{},{},{}'.format(issue['title'], issue['html_url'], issue['created_at']))
@m4rc1e
m4rc1e / Kern_Modified.txt
Created May 8, 2018 12:35
Diffenator results for MarkaziText Test
ﻻﴅ ﻻﺻﺊ ﻻﴆ ﻻﺻ ﻻصي ﻻبي ﻻﺑﺊ ﻻﰊ ﻻﰉ ﻻﺑ ﻻﻇﻲ ﻻغي ﻻﳷ ﻻﳶ ﻻﳵ ﻻﴇ ﻻﻃ ﻻطي ﻻظي ﻻﻇﺊ ﻻﻏﺊ ﻻﻋﺊ ﻻﴈ ﻻﻇﻰ ﻻضي ﻻﺿﺊ ﻻﳺ ﻻﳹ ﻻﺿ ﻻﻇ ﻻعي ﻻﻃﺊ ﻻﳸ ’ ” 7 ﻻﱓ ﻻﱔ ﻻﳽ ﻻﺷ ʻ ﻻﺳﺊ ﻻﺷﺊ ‘ ﻻﳻ ﻻﳾ ﻻﳼ ﻻﺳ ﻻﻫ ﻻشي “ ﻻهي ﻻسي ﻻﻫﺊ
"""
Flatten a font's GPOS kerning.
"""
from fontTools.ttLib import TTFont
def _kerning_lookup_indexes(ttfont):
"""Return the lookup ids for the kern feature"""
for feat in ttfont['GPOS'].table.FeatureList.FeatureRecord:
if feat.FeatureTag == 'kern':
@m4rc1e
m4rc1e / post_img_imgur.py
Created February 2, 2018 11:25
Anonymously post an image to imgur v3 api
import requests
import json
img_path = 'foo/img_path.jpg'
r = requests.post('https://api.imgur.com/3/image',
data={'image': open(img_path, 'rb').read(), 'type': 'file' },
headers = {'Authorization': 'Client-ID {{Your-CLIENT-ID}}'}
)
print r.json()