getting ttf font/family name; fontTools?

Mike C. Fletcher mcfletch at rogers.com
Fri Sep 12 00:19:52 CEST 2003


TTFQuery does all this stuff (using fontTools).  Particularly the 
"describe" module in the package does the work of pulling apart the 
tables to get something useful:

http://sourceforge.net/projects/ttfquery/
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/ttfquery/ttfquery/describe.py?rev=1.1.1.1&content-type=text/plain

You'll also find scripts similar to your "findfont" in the ttfquery 
package, e.g. family_query.py or metadata_query.py, which are built on 
the ttffiles.Registry object's various methods (particularly matchName).

TTFQuery will build its font-registry either by trying to guess the 
system paths, or by being given a directory in which to search (or both).

HTH,
Mike

John Hunter wrote:

>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')
>  >>> s.find('Courier')
>  4197
>
>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.
>
>Thanks,
>John Hunter
>  
>
_______________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/








More information about the Python-list mailing list