Skip to content

Instantly share code, notes, and snippets.

View frankrolf's full-sized avatar
😸
meow

Frank Grießhammer frankrolf

😸
meow
View GitHub Profile
# coding: utf-8
import pprint
from fontTools import agl
characters = u'Loïc Sander Nick Sherman Tânia Raposo Frank Grießhammer'
for char in characters:
# ord(char) is the decimal Unicode value for a given character
# agl.UV2AGL is a dictionary that maps those Unicode values to glyph names
print(agl.UV2AGL.get(ord(char)))
@frankrolf
frankrolf / ipa_characters.txt
Created September 10, 2018 15:43
Test IPA coverage in Robofont 3
# IPA
( 0028
) 0029
. 002E
/ 002F
[ 005B
] 005D
a 0061
b 0062
c 0063
@frankrolf
frankrolf / unicats.py
Last active February 10, 2021 13:47
Select Unicode categories in Robofont 3
from mojo.UI import CurrentFontWindow
import unicodedata
import AppKit
from vanilla import CheckBox, FloatingWindow, List
category_to_codepoints = {}
for code_point in range(0, 0xFFFF + 1):
category = unicodedata.category(chr(code_point))
@frankrolf
frankrolf / write_glyphs_as_images.py
Last active June 10, 2023 05:26
DrawBot script to write image files for each glyph contained in a given font file
# use absolute or relative path. This can be OTF or TTF.
font_path = 'my_font.otf'
# set the current font to be the one specified above, so we can list its glyph names:
font(font_path)
# loop through the list of glyph names:
for gid, g_name in enumerate(listFontGlyphNames()):
# the new page is 1000 by 1000 points by default
newPage()
fs = FormattedString(
font=font_path,
@frankrolf
frankrolf / anchorBaby.py
Last active April 16, 2020 15:16
RoboFont observer for keeping anchors consistent.
'''
## anchorBaby.py
RoboFont script for keeping anchors consistent.
Inspired by an idea from James T. Edmondson, this script will take note of
anchor movement in a given glyph, and replicate that movement in all
dependent glyphs.
For instance, if a font has the glyphs `a` `a.init` and `a.fina`; and all three
@frankrolf
frankrolf / pointselection_alignPoints.py
Created March 11, 2019 18:58
Robofont script for aligning selected points
# Simple align points script for Robofont.
# I have set this to shortcut ctrl-a
def average(coord_list):
coord_sum = sum(coord_list)
return int(round(coord_sum / len(coord_list)))
def distance(coord_list):
@frankrolf
frankrolf / global bounding box.py
Created March 21, 2019 10:18
Robofont script to calculate the global bounding box for all open fonts
import os
a = AllFonts()
class GlyphPoints(object):
def __init__(self, glyph):
point_list = [
point for contour in glyph.contours for point in contour.points]
self.name = glyph.name
self.xPoints = [point.x for point in point_list]
@frankrolf
frankrolf / glyph_recompose_according_to_anchor.py
Created April 16, 2019 10:45
Robofont script to reset a composite glyph according to the anchor found in the base glyph.
import math
def largest_component(g):
if not g.components:
return
else:
boxList = []
for c in g.components:
boxList.append(
@frankrolf
frankrolf / scale_to_caption.py
Created June 20, 2019 07:50
Source Serif scale values
f = CurrentFont()
x_height_scale = 1.05
ascender_scale = 0.98
descender_scale = 0.88
hor_scale_factor_lc = 1.12
hor_scale_factor_uc = 1.1
lime = (0.502, 1.0, 0.0, 1.0)
f.info.xHeight = int(round(x_height_scale * f.info.xHeight))
@frankrolf
frankrolf / ruby_reader.py
Created October 20, 2019 22:51
Parse all languages as specified by TK Speakeasy
# this script is assumed to live in the directory https://github.com/typekit/speakeasy/tree/master/data
import os
import re
def get_code_points(language_file):
with open(language_file, 'r') as f:
raw_data = f.read().splitlines()
split_index = raw_data.index('---') + 5
data = raw_data[split_index:]