Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. # Usage:
  2. # mono ipy.exe ttx-l-example.py <fontfile1> <fontfile2> ...
  3.  
  4. # This script does the same thing as "ttx -l", except
  5. # it will recurse through member fonts in a ttc and also take
  6. # multiple font file arguments.
  7.  
  8. # Copyright (c) Hin-Tak Leung
  9.  
  10. # Tips:
  11. # "mono ipy.exe -h" to get options.
  12. # -X:ColorfulConsole - useful on terminal with a light background
  13. # (somehow forground color is hard-coded to white)
  14.  
  15. import clr
  16. import sys
  17.  
  18. # For "clr.Convert(, String)" below, to call the custom implicit cast operator.
  19. # de.tag.ToString()/String(de.tag) does de.tag.GetType() instead.
  20. from System import String
  21.  
  22. # IronPython does not have the os module, but it can use CPython's!
  23. # NOTE: edit for your CPython's location
  24. sys.path.append("/usr/lib64/python2.7/")
  25. import os
  26.  
  27. # NOTE: edit "os.getcwd()" to FontVal's top location
  28. # relative path does not seem to work.
  29. sys.path.append(os.getcwd() + "/bin")
  30. clr.AddReference("OTFontFile.dll")
  31.  
  32. from OTFontFile import *
  33.  
  34. class ttxl:
  35. def __init__(self, filename):
  36. self.filename = filename
  37. self.f = OTFile()
  38. self.f.open(filename)
  39. for i in range(0, self.f.GetNumFonts()):
  40. fn = self.f.GetFont(i)
  41. tname = fn.GetTable("name")
  42. print tname.GetNameString()
  43. print "Name\tCheckSum\tLength\tOffset"
  44. print "========================================="
  45. for j in range(0, fn.GetNumTables()):
  46. de = fn.GetDirectoryEntry(j)
  47. print "%s\t0x%s\t%d\t%d" % (clr.Convert(de.tag, String),
  48. de.checkSum.ToString("X8"), de.length, de.offset)
  49. print
  50.  
  51. if __name__ == '__main__':
  52. if not sys.argv[1:]:
  53. print("Usage: %s fontfiles" % sys.argv[0])
  54.  
  55. files = sys.argv[1:]
  56.  
  57. for file in files:
  58. ttxlobj = ttxl(file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement