How to use the gftools.util.google_fonts.CodepointsInSubset 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-compare-font.py View on Github external
def DiffCoverage(font_filename1, font_filename2, subset):
  """Prints a comparison of the coverage of a given subset by two fonts.

  Args:
    font_filename1: The first font to compare.
    font_filename2: The second font to compare.
    subset: The lowercase name of the subset to compare coverage of.
  """
  f1cps = fonts.CodepointsInFont(font_filename1)
  f2cps = fonts.CodepointsInFont(font_filename2)

  if subset != 'all':
    subset_cps = fonts.CodepointsInSubset(subset)
    f1cps &= subset_cps
    f2cps &= subset_cps
  else:
    subset_cps = None

  subset_cp_str = ('/%d' % len(subset_cps)) if subset_cps is not None else ''

  print('  %s %+d (%d%s => %d%s)' % (
      subset, len(f2cps) - len(f1cps), len(f1cps), subset_cp_str, len(f2cps),
      subset_cp_str))
github googlefonts / gftools / bin / fonts-subset-support.py View on Github external
def _LeastSimilarCoverage(files, subset):
  """Returns pair of fonts having inconsistent coverage for a subset.

  Args:
    files: List of font files
    subset: Name of subset
  Returns:
    3 tuple of (file1, file2, number of codepoints difference)
  """
  worst = (None, None, 0)
  subsetcps = fonts.CodepointsInSubset(subset, True)
  for pair in itertools.combinations(files, 2):
    inconsistency = _InconsistentSubsetSupport(pair[0], pair[1], subsetcps)
    if inconsistency > worst[2]:
      worst = (pair[0], pair[1], inconsistency)
  return worst