Skip to content

Instantly share code, notes, and snippets.

@HinTak
Created May 4, 2016 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HinTak/96a686572a824d78f8e1967b464821aa to your computer and use it in GitHub Desktop.
Save HinTak/96a686572a824d78f8e1967b464821aa to your computer and use it in GitHub Desktop.
FontVal-based IronPython script to merge truetype fonts into a truetype collection.
# Usage:
# mono ipy.exe ttc-merger.py outfile infile1 infile2 ... infileN
# Copyright (c) Hin-Tak Leung
# Tips:
# "mono ipy.exe -h" to get options.
# -X:ColorfulConsole - useful on terminal with a light background
# (somehow forground color is hard-coded to white)
# -X:PassExceptions - to see C# exceptions
import clr
import sys
# IronPython does not have the os module, but it can use CPython's!
# NOTE: edit for your CPython's location
sys.path.append("/usr/lib64/python2.7/")
import os
# NOTE: edit "os.getcwd()" to FontVal's top location
# relative path does not seem to work.
sys.path.append(os.getcwd() + "/bin")
clr.AddReference("OTFontFile.dll")
from OTFontFile import *
from System import Array, Console
if __name__ == '__main__':
if not sys.argv[1:]:
print("Usage: %s outfile infile1 infile2 ... infileN" % sys.argv[0])
newfont = Array.CreateInstance(OTFont, len(sys.argv)-2)
for i in range(2, len(sys.argv)):
f = OTFile()
f.open(sys.argv[i])
newfont[i-2] = f.GetFont(0)
OTFile.WriteFile(sys.argv[1], newfont)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment