How to use the gftools.util.google_fonts.UniqueSort 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
font_filename2: The second font to compare.
  Returns:
    String describing size difference. One line per unique table in either font.
  """
  result = ['    Table    Changes  Delta-Bytes(from=>to)  % Change']
  result.append('    -------------------------------------------------')
  sfnt1 = sfnt.SFNTReader(open(font_filename1, 'rb'))
  sfnt2 = sfnt.SFNTReader(open(font_filename2, 'rb'))

  font_sz1 = os.stat(font_filename1).st_size

  sum_tables1 = 0
  sum_tables2 = 0

  table_l1_l2s = []
  for t in fonts.UniqueSort(sfnt1.tables, sfnt2.tables, _KNOWN_TABLES):
    table1_sz = sfnt1.tables[t].length if t in sfnt1 else 0
    table2_sz = sfnt2.tables[t].length if t in sfnt2 else 0
    sum_tables1 += table1_sz
    sum_tables2 += table2_sz
    table_l1_l2s.append((t, table1_sz, table2_sz))

  for (table, table1_sz, table2_sz) in table_l1_l2s:
    delta_pct = float(table2_sz - table1_sz) / font_sz1 * 100
    result.append('    %s  %+6d      %06d => %06d %+10.1f%%' % (
        table, table2_sz - table1_sz, table1_sz, table2_sz, delta_pct))

  delta_pct = float(sum_tables2 - sum_tables1) / font_sz1 * 100
  result.append('    TOTAL %+6d      %06d => %06d %+10.1f%%' % (
      sum_tables2 - sum_tables1, sum_tables1, sum_tables2, delta_pct))

  return '\n'.join(result)
github googlefonts / gftools / bin / gftools-compare-font.py View on Github external
def CompareDirs(font1, font2):
  """Compares fonts by assuming font1/2 are dirs containing METADATA.pb."""

  m1 = fonts.Metadata(font1)
  m2 = fonts.Metadata(font2)

  subsets_to_compare = fonts.UniqueSort(m1.subsets, m2.subsets)
  subsets_to_compare.remove('menu')
  subsets_to_compare.append('all')

  font_filename1 = os.path.join(font1, fonts.RegularWeight(m1))
  font_filename2 = os.path.join(font2, fonts.RegularWeight(m2))

  if FLAGS.diff_coverage:
    print('Subset Coverage Change (codepoints)')
    for subset in subsets_to_compare:
      DiffCoverage(font_filename1, font_filename2, subset)

  print(CompareSize(font_filename1, font_filename2))