getting ttf font/family name; fontTools?
jdhunter at ace.bsd.uchicago.edu
Thu Sep 11 22:32:09 CEST 2003
I would like to extract the font and family name from a TTF file. I
have been looking at fontTools ttLib, which parses the ttf file and
provides lots of helpful information, but cannot find the name.
>>> from fontTools import ttLib
>>> tt = ttLib.TTFont("cour.ttf")
tt['head'] seems like a good place to find it, but I can't.
The data appear to be in the 'name' field
>>> s = tt.getTableData('name')
But I still don't know how to extract this information if I don't know
the family/font name in advace. Any ideas on how to best extract this
info using fontTools or otherwise?
What I am trying to do is find the best ttf font file for a given
fontname, fontangle, and fontweight. I plan to write my own font
finder given a font name and font family from the ttf file, but if
there is a better way to find ttf fonts let me know. Eg, what I want
to do is
ttfile = findfont('Courier', 'Italic', 'Bold')
and have findfont search some PATH containing TTF files and return the
closest match, or a default if no good match is found.
More information about the Python-list