Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement