Created
May 2, 2016 18:35
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.