def nametable_from_filename(filepath):
  """Generate a new nametable based on a ttf and the GF Spec"""
  font = TTFont(filepath)
  old_table = font['name']
  new_table = newTable('name')
  filename = ntpath.basename(filepath)[:-4]

  family_name, style_name = filename.split('-')
  family_name = _split_camelcase(family_name)

  font_version = font['name'].getName(5, 3, 1, 1033)
  font_version = font_version.toUnicode()
  vendor_id = font['OS/2'].achVendID

  # SET MAC NAME FIELDS
  # -------------------
  # Copyright
  old_cp = old_table.getName(0, 3, 1, 1033).string.decode('utf_16_be')
  new_table.setName(old_cp.encode('mac_roman'), 0, 1, 0, 0)
  # Font Family Name
  new_table.setName(family_name.encode('mac_roman'), 1, 1, 0, 0)
  # Subfamily name
  mac_subfamily_name = _mac_subfamily_name(style_name).encode('mac_roman')
  new_table.setName(mac_subfamily_name, 2, 1, 0, 0)
  # Unique ID
  unique_id = _unique_id(_version(font_version), vendor_id, filename)
  mac_unique_id = unique_id.encode('mac_roman')
  new_table.setName(mac_unique_id, 3, 1, 0, 0)
  # Full name
  fullname = _full_name(family_name, style_name)
  mac_fullname = fullname.encode('mac_roman')
  new_table.setName(mac_fullname, 4, 1, 0, 0)
  # Version string
  old_v = old_table.getName(5, 3, 1, 1033).string.decode('utf_16_be')
  mac_old_v = old_v.encode('mac_roman')
  new_table.setName(mac_old_v, 5, 1, 0, 0)
  # Postscript name
  mac_ps_name = filename.encode('mac_roman')
  new_table.setName(mac_ps_name, 6, 1, 0, 0)

  # SET WIN NAME FIELDS
  # -------------------
  # Copyright
  new_table.setName(old_cp, 0, 3, 1, 1033)
  # Font Family Name
  win_family_name = _win_family_name(family_name, style_name)
  win_family_name = win_family_name.encode('utf_16_be')
  new_table.setName(win_family_name, 1, 3, 1, 1033)
  # Subfamily Name
  win_subfamily_name = _win_subfamily_name(style_name).encode('utf_16_be')
  new_table.setName(win_subfamily_name, 2, 3, 1, 1033)
  # Unique ID
  win_unique_id = unique_id.encode('utf_16_be')
  new_table.setName(win_unique_id, 3, 3, 1, 1033)
  # Full name
  win_fullname = fullname.encode('utf_16_be')
  new_table.setName(win_fullname, 4, 3, 1, 1033)
  # Version string
  win_old_v = old_v.encode('utf_16_be')
  new_table.setName(win_old_v, 5, 3, 1, 1033)
  # Postscript name
  win_ps_name = filename.encode('utf_16_be')
  new_table.setName(win_ps_name, 6, 3, 1, 1033)

  if style_name not in WIN_SAFE_STYLES:
    # Preferred Family Name
    new_table.setName(family_name.encode('utf_16_be'), 16, 3, 1, 1033)
    # Preferred SubfamilyName
    win_pref_subfam_name = _mac_subfamily_name(style_name).encode('utf_16_be')
    new_table.setName(win_pref_subfam_name, 17, 3, 1, 1033)

  # PAD missing fields
  # ------------------
  for field in REQUIRED_FIELDS:
    text = None
    if new_table.getName(*field):
      pass  # Name has already been updated
    elif old_table.getName(*field):
      text = old_table.getName(*field).string
    elif old_table.getName(field[0], 3, 1, 1033):
      text = old_table.getName(field[0], 3, 1, 1033).string.decode('utf_16_be')
    elif old_table.getName(field[0], 1, 0, 0):  # check if field exists for mac
      text = old_table.getName(field[0], 3, 1, 1033).string.decode('mac_roman')

    if text:
      new_table.setName(text, *field)
  return new_table