def createFontList(fontfiles, fontext=u'ttf'):
 fontlist = []
 seen = {}
 for fpath in fontfiles:
  verbose.report((u'createFontDict: %s' % fpath), u'debug')
  fname = os.path.split(fpath)[1]
  if (fname in seen):
   continue
  else:
   seen[fname] = 1
  if (fontext == u'afm'):
   try:
    fh = open(fpath, u'rb')
   except EnvironmentError:
    verbose.report((u'Could not open font file %s' % fpath))
    continue
   try:
    font = afm.AFM(fh)
   except RuntimeError:
    verbose.report((u'Could not parse font file %s' % fpath))
    continue
   finally:
    fh.close()
   try:
    prop = afmFontProperty(fpath, font)
   except KeyError:
    continue
  else:
   try:
    font = ft2font.FT2Font(fpath)
   except RuntimeError:
    verbose.report((u'Could not open font file %s' % fpath))
    continue
   except UnicodeError:
    verbose.report(u'Cannot handle unicode filenames')
    continue
   except IOError:
    verbose.report((u'IO error - cannot open font file %s' % fpath))
    continue
   try:
    prop = ttfFontProperty(font)
   except (KeyError, RuntimeError, ValueError):
    continue
  fontlist.append(prop)
 return fontlist

def createFontList ( fontfiles , fontext = u'ttf' ) : fontlist = [ ] seen = { } for fpath in fontfiles : verbose . report ( ( u'createFontDict: %s' % fpath ) , u'debug' ) fname = os . path . split ( fpath ) [ 1 ] if ( fname in seen ) : continue else : seen [ fname ] = 1 if ( fontext == u'afm' ) : try : fh = open ( fpath , u'rb' ) except EnvironmentError : verbose . report ( ( u'Could not open font file %s' % fpath ) ) continue try : font = afm . AFM ( fh ) except RuntimeError : verbose . report ( ( u'Could not parse font file %s' % fpath ) ) continue finally : fh . close ( ) try : prop = afmFontProperty ( fpath , font ) except KeyError : continue else : try : font = ft2font . FT2Font ( fpath ) except RuntimeError : verbose . report ( ( u'Could not open font file %s' % fpath ) ) continue except UnicodeError : verbose . report ( u'Cannot handle unicode filenames' ) continue except IOError : verbose . report ( ( u'IO error - cannot open font file %s' % fpath ) ) continue try : prop = ttfFontProperty ( font ) except ( KeyError , RuntimeError , ValueError ) : continue fontlist . append ( prop ) return fontlist
a function to create a font lookup list .