Skip to content

Instantly share code, notes, and snippets.

@HinTak
Created May 2, 2016 18:35
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/8c08a4f3ac9d787c382139506c259ffd to your computer and use it in GitHub Desktop.
Save HinTak/8c08a4f3ac9d787c382139506c259ffd to your computer and use it in GitHub Desktop.
IronPython example to use Microsoft Font Validator's internals to get at font creation and modification times.
# Usage:
# mono ipy.exe this_script.py <fontfile1> <fontfile2> ...
# 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
# 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
sys.path.append(os.getcwd() + "/bin")
clr.AddReference("OTFontFile.dll")
from OTFontFile import *
class headtime:
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()
thead = fn.GetTable("head")
print "\t%s" % thead.GetCreatedDateTime()
print "\t%s" % thead.GetModifiedDateTime()
if __name__ == '__main__':
if not sys.argv[1:]:
print("Usage: %s fontfiles" % sys.argv[0])
files = sys.argv[1:]
for file in files:
headtimeobj = headtime(file)
@HinTak
Copy link
Author

HinTak commented May 2, 2016

You need MS Font Validator, mono, ironpython (it comes with the windows version of mono definitely, and possibly also the mac OS version); CPython is optional, and only needed for the os module to set the current path if you are sitting at the top of FontVal's directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment