How to use the gftools.util.google_fonts function in gftools

To help you get started, we’ve selected a few gftools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googlefonts / gftools / bin / gftools-font-weights-coverage.py View on Github external
def main(argv):
  if len(argv) != 2 or not os.path.isdir(argv[1]):
    sys.exit('Must have one argument, a directory containing font files.')

  dirpath = argv[1]
  cps = set()
  for f in _GetFontFiles(dirpath):
    cps.update(fonts.CodepointsInFont(os.path.join(dirpath, f)))

  for f in _GetFontFiles(dirpath):
    diff = cps - fonts.CodepointsInFont(os.path.join(dirpath, f))
    if bool(diff):
      print('%s failed' % (f))
      for c in diff:
        print('0x%04X' % (c))
    else:
      print('%s passed' % (f))
github googlefonts / gftools / bin / gftools-sanity-check.py View on Github external
path: Path to directory containing font.
    name: The name of the family.
    font: A font record from a METADATA.pb.
    ttf: A fontTools.ttLib.TTFont for the font.
  Returns:
    A list of ResultMessageTuple for tests performed.
  """
  results = []

  style = font.style
  weight = font.weight
  full_font_file = os.path.join(path, font.filename)

  expectations = [('family', fonts.NAME_FAMILY, name),
                  ('postScriptName', fonts.NAME_PSNAME, fonts.FilenameFor(
                      name, style, weight)), ('fullName', fonts.NAME_FULLNAME,
                                              fonts.FullnameFor(
                                                  name, style, weight))]

  for (friendly_name, name_id, expected) in expectations:
    # If you have lots of name records they should ALL have the right value
    actuals = fonts.ExtractNames(ttf, name_id)
    for (idx, actual) in enumerate(actuals):
      results.append(
          ResultMessageTuple(expected == actual,
                             '%s %s/%d \'name\' %s[%d] expected %s, got %s' %
                             (name, style, weight, friendly_name, idx, expected,
                              actual), full_font_file,
                             _FixBadNameRecord(friendly_name, name_id,
                                               expected)))

    # should have at least one actual
github googlefonts / gftools / bin / gftools-sanity-check.py View on Github external
Args:
    path: Path to directory containing font.
    name: The name of the family.
    font: A font record from a METADATA.pb.
    ttf: A fontTools.ttLib.TTFont for the font.
  Returns:
    A list of ResultMessageTuple for tests performed.
  """
  results = []

  style = font.style
  weight = font.weight
  full_font_file = os.path.join(path, font.filename)

  expectations = [('family', fonts.NAME_FAMILY, name),
                  ('postScriptName', fonts.NAME_PSNAME, fonts.FilenameFor(
                      name, style, weight)), ('fullName', fonts.NAME_FULLNAME,
                                              fonts.FullnameFor(
                                                  name, style, weight))]

  for (friendly_name, name_id, expected) in expectations:
    # If you have lots of name records they should ALL have the right value
    actuals = fonts.ExtractNames(ttf, name_id)
    for (idx, actual) in enumerate(actuals):
      results.append(
          ResultMessageTuple(expected == actual,
                             '%s %s/%d \'name\' %s[%d] expected %s, got %s' %
                             (name, style, weight, friendly_name, idx, expected,
                              actual), full_font_file,
                             _FixBadNameRecord(friendly_name, name_id,
                                               expected)))