Created
October 29, 2019 22:48
-
-
Save extesy/806b95cdef25b97003ff46de7fa9c416 to your computer and use it in GitHub Desktop.
Schmelvetica - Absurd fonts for an absurd world
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fontTools.ttLib import TTFont | |
import random | |
import string | |
ORIGINAL_FONT_PATH = "path/to/Helvetica.ttc" | |
GLORIOUS_FONT_PATH = "path/to/Schmelvetica.ttc" | |
NEW_FONTNAME = b"Schmelvetica" | |
# Load the font | |
font = TTFont(ORIGINAL_FONT_PATH, fontNumber=0, lazy=False) | |
# Rename it | |
for i, n in enumerate(font["name"].names): | |
if b"Helvetica" in n.string: | |
n.string = NEW_FONTNAME | |
# this should be unique | |
font["name"].names[3].string = NEW_FONTNAME + b"; 0.001; 2019-10-23" | |
# Have fun with kerning | |
for kt in font["kern"].kernTables: | |
for k in itertools.product(string.ascii_letters, string.ascii_letters): | |
kt.kernTable[k] = random.randint(-100, 100) | |
print(k, kt.kernTable[k]) | |
# get wobbly with it | |
for s in string.ascii_letters: | |
# Move all points relative to the new base | |
new_base = (random.randint(-100, 100), random.randint(-100, 100)) | |
print(s, new_base) | |
for i, c in enumerate(font["glyf"][s].coordinates): | |
font["glyf"][s].coordinates[i] = (c[0] + new_base[0], c[1] + new_base[1]) | |
# Enjoy your new glorious font! | |
font.save(GLORIOUS_FONT_PATH) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment