Skip to content

Instantly share code, notes, and snippets.

@HinTak
Created May 3, 2016 10:37
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/3cbc107a4394b0546f4647ecbe49d92c to your computer and use it in GitHub Desktop.
Save HinTak/3cbc107a4394b0546f4647ecbe49d92c to your computer and use it in GitHub Desktop.
# Usage:
# mono ipy.exe ttx-l-example.py <fontfile1> <fontfile2> ...
# This script does the same thing as "ttx -l", except
# it will recurse through member fonts in a ttc and also take
# multiple font file arguments.
# 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)
import clr
import sys
# For "clr.Convert(, String)" below, to call the custom implicit cast operator.
# de.tag.ToString()/String(de.tag) does de.tag.GetType() instead.
from System import String
# 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 *
class ttxl:
def __init__(self, filename):
self.filename = filename
self.f = OTFile()
self.f.open(filename)
for i in range(0, self.f.GetNumFonts()):
fn = self.f.GetFont(i)
tname = fn.GetTable("name")
print tname.GetNameString()
print "Name\tCheckSum\tLength\tOffset"
print "========================================="
for j in range(0, fn.GetNumTables()):
de = fn.GetDirectoryEntry(j)
print "%s\t0x%s\t%d\t%d" % (clr.Convert(de.tag, String),
de.checkSum.ToString("X8"), de.length, de.offset)
print
if __name__ == '__main__':
if not sys.argv[1:]:
print("Usage: %s fontfiles" % sys.argv[0])
files = sys.argv[1:]
for file in files:
ttxlobj = ttxl(file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment