How to use the gftools.util.google_fonts.ExtractNames 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-sanity-check.py View on Github external
"""
  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
    if not actuals:
      results.append(
          _SadResult('%s %s/%d \'name\' %s has NO values' %
                     (name, style, weight, friendly_name), full_font_file,
                     _FixMissingNameRecord(friendly_name, name_id, expected)))