code: def _parse_header(fh):
      """
      Reads the font metrics header (up to the char metrics) and returns
      a dictionary mapping *key* to *val*.  *val* will be converted to the
      appropriate python type as necessary; eg:
  
          * 'False'->False
          * '0'->0
          * '-168 -218 1000 898'-> [-168, -218, 1000, 898]
  
      Dictionary keys are
  
        StartFontMetrics, FontName, FullName, FamilyName, Weight,
        ItalicAngle, IsFixedPitch, FontBBox, UnderlinePosition,
        UnderlineThickness, Version, Notice, EncodingScheme, CapHeight,
        XHeight, Ascender, Descender, StartCharMetrics
  
      """
      headerConverters = {
          "StartFontMetrics": _to_float,
          "FontName": _to_str,
          "FullName": _to_str,
          "FamilyName": _to_str,
          "Weight": _to_str,
          "ItalicAngle": _to_float,
          "IsFixedPitch": _to_bool,
          "FontBBox": _to_list_of_ints,
          "UnderlinePosition": _to_int,
          "UnderlineThickness": _to_int,
          "Version": _to_str,
          "Notice": _to_str,
          "EncodingScheme": _to_str,
          "CapHeight": _to_float,  # Is the second version a mistake, or
          "Capheight": _to_float,  # do some AFM files contain 'Capheight'? -JKS
          "XHeight": _to_float,
          "Ascender": _to_float,
          "Descender": _to_float,
          "StdHW": _to_float,
          "StdVW": _to_float,
          "StartCharMetrics": _to_int,
          "CharacterSet": _to_str,
          "Characters": _to_int,
      }
  
      d = {}
      while 1:
          line = fh.readline()
          if not line:
              break
          line = line.rstrip()
          if line.startswith("Comment"):
              continue
          lst = line.split(" ", 1)
          # print '%-s\t%-d line :: %-s' % ( fh.name, len(lst), line )
          key = lst[0]
          if len(lst) == 2:
              val = lst[1]
          else:
              val = ""
          # key, val = line.split(' ', 1)
          try:
              d[key] = headerConverters[key](val)
          except ValueError:
              print >> sys.stderr, "Value error parsing header in AFM:", key, val
              continue
          except KeyError:
              print >> sys.stderr, "Found an unknown keyword in AFM header (was %s)" % key
              continue
          if key == "StartCharMetrics":
              return d
      raise RuntimeError("Bad parse")
  
imports: import sys, os, re
  from _mathtext_data import uni2type1
label_desc: Use image node_id 5 for calling a global function with example usage: _parse_header(fh) and returns: d