Skip to content

Instantly share code, notes, and snippets.

@nirbheek
Last active August 29, 2015 14:27
Show Gist options
  • Save nirbheek/357ef4e6da9f89fd85d5 to your computer and use it in GitHub Desktop.
Save nirbheek/357ef4e6da9f89fd85d5 to your computer and use it in GitHub Desktop.
Takes a given font and changes the font family/wws family names to "Cantarell"
#!/usr/bin/env fontforge
# vim: set sts=4 sw=4 et :
#
# Takes a given font and changes the font family/wws family names to "Cantarell"
# Created for testing GNOME's move away from Cantarell as the UI font
fontname_prefix = "Cantarell"
if ($version < "20080330")
Error("Your version of FontForge is too old - 20080330 or newer is required");
endif
SetPref("FoundryName", fontname_prefix)
SetPref("TTFFoundry", fontname_prefix)
i = 1
while (i < $argc)
Open($argv[i], 1)
# Get "Regular" or "Bold" out of a font name like SourceSansPro-Regular
font_style = StrSplit($fontname, "-")
# Array-indexing doesn't seem to work unless done to a named variable, so we
# need this extra step.
old_fontname = font_style[0]
font_style = font_style[1]
# Note: StrJoin doesn't actually work the way you would expect.
# StrJoin(["a", "b"], "-") will give "a-b-" instead of "a-b"
# Set the new font name, ex: "Cantarell-Regular"
output_filename = StrJoin([old_fontname, "--", fontname_prefix, "-", font_style], "")
new_fontname = StrJoin([fontname_prefix, "-", font_style], "")
# Set the new family name, ex: "Cantarell Regular"
new_fullname = StrJoin([fontname_prefix, " ", font_style], "")
# This will set name table name ID 1, 16, 17, 18
SetFontNames(new_fontname, fontname_prefix, new_fullname)
# Set the WWS font family name
SetTTFName(0x409, 21, fontname_prefix)
# Set newer version
SetTTFName(0x409, 5, "0.1.0")
SavePrefs()
Generate(output_filename + ".otf")
Close()
i++
endloop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment