getting ttf font/family name; fontTools?

Discussion in 'Python' started by John Hunter, Sep 11, 2003.

  1. John Hunter

    John Hunter Guest

    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
    John Hunter, Sep 11, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AJ
    Replies:
    1
    Views:
    6,705
    Ralph Aichinger
    Apr 29, 2004
  2. Sameer
    Replies:
    4
    Views:
    395
    Sameer
    Mar 12, 2005
  3. Mike C. Fletcher

    Re: getting ttf font/family name; fontTools?

    Mike C. Fletcher, Sep 11, 2003, in forum: Python
    Replies:
    0
    Views:
    430
    Mike C. Fletcher
    Sep 11, 2003
  4. John Hunter
    Replies:
    0
    Views:
    360
    John Hunter
    Sep 12, 2003
  5. Laszlo Nagy
    Replies:
    1
    Views:
    628
    David Boddie
    Sep 19, 2009
Loading...

Share This Page